From patchwork Fri Apr 11 07:15:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZhangZhen X-Patchwork-Id: 338403 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 4E54C1400DB for ; Fri, 11 Apr 2014 17:16:56 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755199AbaDKHQz (ORCPT ); Fri, 11 Apr 2014 03:16:55 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:11466 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755172AbaDKHQy (ORCPT ); Fri, 11 Apr 2014 03:16:54 -0400 Received: from 172.24.2.119 (EHLO szxeml209-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BTZ36473; Fri, 11 Apr 2014 15:15:16 +0800 (CST) Received: from SZXEML451-HUB.china.huawei.com (10.82.67.194) by szxeml209-edg.china.huawei.com (172.24.2.184) with Microsoft SMTP Server (TLS) id 14.3.158.1; Fri, 11 Apr 2014 15:15:13 +0800 Received: from [127.0.0.1] (10.111.69.77) by szxeml451-hub.china.huawei.com (10.82.67.194) with Microsoft SMTP Server id 14.3.158.1; Fri, 11 Apr 2014 15:15:09 +0800 Message-ID: <5347967B.5090401@huawei.com> Date: Fri, 11 Apr 2014 15:15:07 +0800 From: Zhang Zhen User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: , Christoph Hellwig CC: Subject: [PATCH] ext4: avoid unneeded lookup when xattr name is invalid References: <1397199813-71623-1-git-send-email-zhenzhang.zhang@huawei.com> In-Reply-To: <1397199813-71623-1-git-send-email-zhenzhang.zhang@huawei.com> X-Forwarded-Message-Id: <1397199813-71623-1-git-send-email-zhenzhang.zhang@huawei.com> X-Originating-IP: [10.111.69.77] X-CFilter-Loop: Reflected Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In ext4_xattr_set_handle() we have checked the xattr name's length. So we should also check it in ext4_xattr_get() to avoid unneeded lookup caused by invalid name. In addition, we deleted the check of NULL in ext4_xattr_set_handle(), because in all the callers of the ext4_xattr_set_handle(), the name can't be NULL. Signed-off-by: Zhang Zhen --- fs/ext4/xattr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 1f5cf58..340bdfa 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -369,6 +369,9 @@ ext4_xattr_get(struct inode *inode, int name_index, const char *name, { int error; + if (strlen(name) > 255) + return -ERANGE; + down_read(&EXT4_I(inode)->xattr_sem); error = ext4_xattr_ibody_get(inode, name_index, name, buffer, buffer_size); @@ -1073,8 +1076,6 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, unsigned long no_expand; int error; - if (!name) - return -EINVAL; if (strlen(name) > 255) return -ERANGE; down_write(&EXT4_I(inode)->xattr_sem);