Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp941091pxb; Wed, 3 Mar 2021 21:54:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTcnC7IG0dJVF1fN8Sk5SY1qtq3c/riEC4g2APKe8FslKEItiMv/sfNsqXrIJgNUaGl73p X-Received: by 2002:a17:906:c08f:: with SMTP id f15mr2495526ejz.318.1614837269462; Wed, 03 Mar 2021 21:54:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614837269; cv=none; d=google.com; s=arc-20160816; b=FcphPBBgL3yfSjj4g8gPwR5/sNkuW9C2v+BJ9eHzltlH5QF2XNplLZj2yovsNC71O1 5LNMnzxAfkpQUfAPjUPs8VBM7lW3y/EzglDlIbPRf1aS79GacuYUtWC3pQ+WzEpsIy0f Hqiipw5Fd6tm7SXiqLmaoq3uBjYtjLN68hTAb1xq82TlOe2rdRPj9hJgpYxC02KSEsPb gAKzfd1gCtDatOjDM7ymTIslgXCPquIpAcoUO0iLhk1OEewm5+e2OVdkpjKdDSWhcezv cpjRlQ6Bddmexa9jkamuHoUD52JSooa+dw6l9CAuyrw0ULtMwsTTlMx+2+fMjboZuwWN X5Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=DF5orudlIFbucgfpElCg2gyR+7/7ztsAhtwQfs1QQu0=; b=guSAR2irJRJsZ0JCCV+UHo8f7UtOmMVA5XTgEL2h3w1Dc/8xmwkWzLfkGI9Tiso8h7 rdgrjelfAlP52CbsNeCkqezBYSBGzlMhlnbMyqASzcTB5I+ki8cjVeK90uf+gh71wltN eu8rgAu8/9M9IOkVkpaWOUTbbOu+oWWQ88gc6L/N+drTAxQ+frBqUnZlT+2RuX1sdKnV OOnoZkrZ8hnJ621YTFDEdOWKV9FtRRUbdinYqJymCcRLGU4eEgHH2mAnIZy4Mf411RCi N/tLTsfkEIdv5Ea9zkCxXw2cTkzUkqSuqx++aibVrsomiMpYNu7Bp2NJWh+/ZY9M67oO jAag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e10si14153161ejk.173.2021.03.03.21.54.07; Wed, 03 Mar 2021 21:54:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1836725AbhCBHUa (ORCPT + 99 others); Tue, 2 Mar 2021 02:20:30 -0500 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:57358 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1836040AbhCBGdG (ORCPT ); Tue, 2 Mar 2021 01:33:06 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=yang.lee@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0UQ3O2-B_1614666743; Received: from j63c13417.sqa.eu95.tbsite.net(mailfrom:yang.lee@linux.alibaba.com fp:SMTPD_---0UQ3O2-B_1614666743) by smtp.aliyun-inc.com(127.0.0.1); Tue, 02 Mar 2021 14:32:24 +0800 From: Yang Li To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Li Subject: [PATCH] xattr: switch to vmemdup_user() Date: Tue, 2 Mar 2021 14:32:21 +0800 Message-Id: <1614666741-16796-1-git-send-email-yang.lee@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replace opencoded alloc and copy with vmemdup_user() fixed the following coccicheck: ./fs/xattr.c:561:11-19: WARNING opportunity for vmemdup_user Reported-by: Abaci Robot Signed-off-by: Yang Li --- fs/xattr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/xattr.c b/fs/xattr.c index b3444e0..b947ad2 100644 --- a/fs/xattr.c +++ b/fs/xattr.c @@ -558,11 +558,10 @@ int __vfs_setxattr_noperm(struct user_namespace *mnt_userns, if (size) { if (size > XATTR_SIZE_MAX) return -E2BIG; - kvalue = kvmalloc(size, GFP_KERNEL); - if (!kvalue) - return -ENOMEM; - if (copy_from_user(kvalue, value, size)) { - error = -EFAULT; + kvalue = vmemdup_user(value, size); + + if (IS_ERR(kvalue)) { + r = PTR_ERR(kvalue); goto out; } if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) || -- 1.8.3.1