Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756861Ab0GMO5z (ORCPT ); Tue, 13 Jul 2010 10:57:55 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:61755 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752510Ab0GMO5x (ORCPT ); Tue, 13 Jul 2010 10:57:53 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; b=EQ8JHm8TlopigPiH+VgqSvwcoxI1hXmlCPVsvGUvvekjnvvWaxK8K9Nbx8x6fWIoFI D4Sbo0xyDYE7Z7ellfP+aTdxWz96835gPdElFidKwKB5yL/RYMm2TV82xUCsVH7wktJX pz3dOIor/5s/XOjYcdHyIcf3tZJ647meh5YmI= Date: Tue, 13 Jul 2010 16:56:08 +0200 From: Dan Carpenter To: crosslonelyover Cc: linux-ext4 , linux-kernel , kernel-janitors Subject: Re: [PATCH] check name_len before down_read xattr_sem and sb_read in ext2_xattr_get Message-ID: <20100713145608.GM5658@bicker> Mail-Followup-To: Dan Carpenter , crosslonelyover , linux-ext4 , linux-kernel , kernel-janitors References: <201007122229025316610@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201007122229025316610@gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1437 Lines: 42 On Mon, Jul 12, 2010 at 10:29:09PM +0800, crosslonelyover wrote: > Hi, > I walked through ext2_xattr_get, and felt that we can > do some optimization on it. For name_len check, it's done > after down xattr_sem and sb_read, both of which are time > consuming operation compared with strlen: > down_read(&EXT2_I(inode)->xattr_sem); > ... > bh = sb_bread(inode->i_sb, EXT2_I(inode)->i_file_acl); > ... > /* find named attribute */ > name_len = strlen(name); > > error = -ERANGE; > if (name_len > 255) > goto cleanup; > > Most of the case, you'll get one valid block, but if the > name len > 255, then the xattr_sem down and sb_bread operation > can be seen as a waste of time. So I think we'd better do > name len check as early as possible. > Following is my patch, and it's against 2.6.35-rc4. > Please check it. > > Signed-off-by: Wang Sheng-Hui > --- > fs/ext2/xattr.c | 12 +++++++----- > 1 files changed, 7 insertions(+), 5 deletions(-) For what it's worth, this change looks OK to me. Reviewed-by: Dan Carpenter regards, dan carpenter -- 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/