Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752758Ab0H0UPV (ORCPT ); Fri, 27 Aug 2010 16:15:21 -0400 Received: from exprod5og113.obsmtp.com ([64.18.0.26]:44104 "EHLO exprod5og113.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751141Ab0H0UPT convert rfc822-to-8bit (ORCPT ); Fri, 27 Aug 2010 16:15:19 -0400 MIME-Version: 1.0 In-Reply-To: References: <4C779111.8000803@kernel.org> Date: Fri, 27 Aug 2010 15:15:15 -0500 Message-ID: Subject: Re: [PATCH] scatterlist: prevent invalid free when alloc fails From: Jeffrey Carlyle To: Tejun Heo Cc: torvalds@osdl.org, linux-kernel@vger.kernel.org, jaxboe@fusionio.com, OLUSANYA SOYANNWO , Hu Tao Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1329 Lines: 32 On Fri, Aug 27, 2010 at 2:45 PM, Jeffrey Carlyle wrote: > On Fri, Aug 27, 2010 at 5:18 AM, Tejun Heo wrote: >> On 08/26/2010 06:04 PM, Jeffrey Carlyle wrote: >>> diff --git a/lib/scatterlist.c b/lib/scatterlist.c >>> index a5ec428..acf2c6e 100644 >>> --- a/lib/scatterlist.c >>> +++ b/lib/scatterlist.c >>> @@ -163,7 +163,7 @@ void __sg_free_table(struct sg_table *table, >>> unsigned int max_ents, >>> ? ? ? ? ? ? ? return; >>> >>> ? ? ? sgl = table->sgl; >>> - ? ? while (table->orig_nents) { >>> + ? ? while (table->orig_nents && sgl) { >>> ? ? ? ? ? ? ? unsigned int alloc_size = table->orig_nents; >>> ? ? ? ? ? ? ? unsigned int sg_size; >> >> Why is this change necessary? > > Well the problem we were seeing manifested itself when we called > free_fn on a NULL value. This was a naive attempt at avoiding that. If > the logic in __sg_alloc_table is corrected, I agree that we shouldn't > need this. Actually, please disregard the comment about trying to free NULL. I don't think we need to add the "&& sgl" under any circumstances. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/