Re: [PATCH] scatterlist: prevent invalid free when alloc fails

From: Tejun Heo
Date: Fri Aug 27 2010 - 19:31:31 EST


Hello,

On 08/27/2010 09:45 PM, Jeffrey Carlyle wrote:
>>> sg = alloc_fn(alloc_size, gfp_mask);
>>> - if (unlikely(!sg))
>>> + if (unlikely(!sg)) {
>>> + table->orig_nents = total_alloc;
>>> + /* mark the end of previous entry */
>>> + sg_mark_end(&prv[alloc_size - 1]);
>>
>> prv[alloc_size - 1] is already marked as end by sg_init_table() during
>> the previous iteration. Also, prv can be NULL at this point. AFAICS,
>> the only thing necessary would be "if (prv) table->nents++", no?
>
> You are right about prv possibly being NULL here. Sorry for not
> catching that earlier; however, I don't think prv will be marked as an
> end in the previous iteration.

But we have sg_mark_end(&sgl[nents-1]) in sg_init_table(). I think
explicit end marking in __sg_alloc_table() is redundant.

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/