Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761404AbXIRRlt (ORCPT ); Tue, 18 Sep 2007 13:41:49 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1760298AbXIRRla (ORCPT ); Tue, 18 Sep 2007 13:41:30 -0400 Received: from mx1.redhat.com ([66.187.233.31]:50182 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760211AbXIRRl2 (ORCPT ); Tue, 18 Sep 2007 13:41:28 -0400 Subject: Re: [PATCH] ext34: ensure do_split leaves enough free space in both blocks From: "Stephen C. Tweedie" To: Eric Sandeen Cc: ext4 development , linux-kernel , hooanon05@yahoo.co.jp, Andrew Morton , Stephen Tweedie In-Reply-To: <46EEA5F4.3030806@redhat.com> References: <46EEA5F4.3030806@redhat.com> Content-Type: text/plain Date: Tue, 18 Sep 2007 18:41:11 +0100 Message-Id: <1190137272.27889.19.camel@sisko.scot.redhat.com> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-35.0.4.el4) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1579 Lines: 50 Hi, On Mon, 2007-09-17 at 11:06 -0500, Eric Sandeen wrote: > The do_split() function for htree dir blocks is intended to split a > leaf block to make room for a new entry. It sorts the entries in the > original block by hash value, then moves the last half of the entries to > the new block - without accounting for how much space this actually moves. Nasty. > Also add a few comments to the functions involved. A big improvement. :) > + /* Split the existing block in the middle, size-wise */ > + size = 0; > + move = 0; > + for (i = count-1; i >= 0; i--) { > + /* is more than half of this entry in 2nd half of the block? */ > + if (size + map[i].size/2 > blocksize/2) > + break; > + size += map[i].size; > + move++; > + } > + /* map index at which we will split */ > + split = count - move; This is the guts of it, and I spent a while looking just to convince myself it was getting things right in the corner case and was splitting at _exactly_ the right point. If we have large dirents and 1k blocksize, even getting the split point off-by-one will still leave us vulnerable to the bug. But it all looks fine. My only other comment would be that "move" is redundant, you could lose it completely and just do split = i+1; but I think the logic's easier to understand the way it is. Nice catch. --Stephen - 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/