From patchwork Fri Jul 22 14:06:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Sheng-Hui X-Patchwork-Id: 106298 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E1290B6EE8 for ; Sat, 23 Jul 2011 00:06:38 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754493Ab1GVOGg (ORCPT ); Fri, 22 Jul 2011 10:06:36 -0400 Received: from mail-pz0-f42.google.com ([209.85.210.42]:57379 "EHLO mail-pz0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754455Ab1GVOGf (ORCPT ); Fri, 22 Jul 2011 10:06:35 -0400 Received: by pzk37 with SMTP id 37so3650490pzk.1 for ; Fri, 22 Jul 2011 07:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=/tGNsabAGN1XT4UQvCZ+COLYtrCXxuQLSEOvI/xE6wM=; b=f2+sv8dHe/bBsSKNCJWDPfECcwaHzUi4JCE/OFGFs2ELx1eatWZVw8i10zabio0je6 oFEXyNOvU50LYpDLkViu2GiBsNw3mupQHHdtJ82jmkKqt3m53AZYAd7QHUP/se7r21ns VMpnGuSO25HZIZ0ytLD+jD5PBAlAM2kGXnAKs= Received: by 10.68.40.6 with SMTP id t6mr1282339pbk.464.1311343594970; Fri, 22 Jul 2011 07:06:34 -0700 (PDT) Received: from [192.168.1.100] ([121.18.126.183]) by mx.google.com with ESMTPS id i9sm1792122pbk.36.2011.07.22.07.06.32 (version=SSLv3 cipher=OTHER); Fri, 22 Jul 2011 07:06:34 -0700 (PDT) Message-ID: <4E2983E0.3060208@gmail.com> Date: Fri, 22 Jul 2011 22:06:24 +0800 From: Wang Sheng-Hui User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, Jan Kara , "Theodore Ts'o" Subject: [PATCH] ext2: check xattr name_len before acquiring sem lock in ext2_xattr_get Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From 667173a18b671896f933c5952fa211601d2e5ab0 Mon Sep 17 00:00:00 2001 From: Wang Sheng-Hui Date: Fri, 22 Jul 2011 08:50:13 -0500 Subject: [PATCH] ext2: check xattr name_len before acquiring sem lock in ext2_xattr_get The patch is against 3.0. In ext2_xattr_get, the code will acquire sem lock first, later check the length of xattr name_len > 255. It's kind of time consuming, and we should do the basic check before the time consuming acquiring sem lock. Signed-off-by: Wang Sheng-Hui --- fs/ext2/xattr.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c index 5299706..d27b71f 100644 --- a/fs/ext2/xattr.c +++ b/fs/ext2/xattr.c @@ -161,6 +161,10 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name, if (name == NULL) return -EINVAL; + name_len = strlen(name); + if (name_len > 255) + return -ERANGE; + down_read(&EXT2_I(inode)->xattr_sem); error = -ENODATA; if (!EXT2_I(inode)->i_file_acl) @@ -181,12 +185,8 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_get", error = -EIO; goto cleanup; } - /* find named attribute */ - name_len = strlen(name); - error = -ERANGE; - if (name_len > 255) - goto cleanup; + /* find named attribute */ entry = FIRST_ENTRY(bh); while (!IS_LAST_ENTRY(entry)) { struct ext2_xattr_entry *next =