Message ID | 202301091940437129873@zte.com.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2106359wrt; Mon, 9 Jan 2023 03:44:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXtd3EcrheDdTqpDcOjqoZejtaz4ucYcMGCLusMe98raJUeElgIcNEolgvnR4haak0De9i91 X-Received: by 2002:a05:6a20:2a01:b0:a2:17a6:44cd with SMTP id e1-20020a056a202a0100b000a217a644cdmr74034287pzh.58.1673264678705; Mon, 09 Jan 2023 03:44:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673264678; cv=none; d=google.com; s=arc-20160816; b=N0dYFRDzXGvtlDiWc/95ceDmab2GAp9nmIjUhczZtk4M5aGgzLWRHlBHkB4YrOxqp9 6Wt9n6lZR1qxeZrZ1byiICWM8Z5axZ2z3AS2EwM5SnqLDSTrF8Kf9HQoHgR9JtnmI/T8 uw9QeucxeWUccAgYCkNmA6Ofsp2ne4jupPiPK7fGwFp6to4FOCrz4RNh7DUTLWLrStvw dJAGEkjhYzsq4/7TnWUQlgbXOWZyJTnMCvYfA+QxsIovoZlL2WDEbDoAWvR/oeqTYi2b PhLVWwqF/mEuiwuMf+JJfhbsYg/rw263g9lwtCrP588fMh5FVjkxvqCNN5XS1ZjUBKAX 46fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=dAENBolQvIxVlrwq6KnikUabrDZPTj2EZawts2dh1Zw=; b=grqwTjDdPAsT8M3CRMraTTOcKnxgTbieOwCvaj0nkBnRBTg/+A7gxFC6bgCbRQpe54 mXaS9WRmdHLb2EC6c91KpNA3A0BFKaE2ptWJTqBe0dWadtyqSMb/KJcREI643wggqLL8 ddRGOOopEbjg8w5DcoAC6hGD8qjUFbfNvNS/2c+/G/FEHtnLWBvB6PdkUGrYViKPoIi4 tndod/cXX0o5fE6UYp0dnWsoA4mw0kZATJ7Tas0YEBoY06arR+ulDd+HpjdpqzpAX1Ea ws/fg09JqmgmMV5FQ/z2Bu1nVYhcEcAQy2xG/UcvYVhFQL7rD2GYacpcWVsTb2EKJxpD TO4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a63f14a000000b0046b121a3246si9586686pgk.842.2023.01.09.03.44.25; Mon, 09 Jan 2023 03:44:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjAILlJ (ORCPT <rfc822;zhanglyra.2023@gmail.com> + 99 others); Mon, 9 Jan 2023 06:41:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237012AbjAILku (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 06:40:50 -0500 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2747BB36; Mon, 9 Jan 2023 03:40:47 -0800 (PST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4NrBpP5TMYz4y3Z2; Mon, 9 Jan 2023 19:40:45 +0800 (CST) Received: from szxlzmapp04.zte.com.cn ([10.5.231.166]) by mse-fl1.zte.com.cn with SMTP id 309BeefP089112; Mon, 9 Jan 2023 19:40:40 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Mon, 9 Jan 2023 19:40:43 +0800 (CST) Date: Mon, 9 Jan 2023 19:40:43 +0800 (CST) X-Zmail-TransId: 2b0363bbfd3b029d1fed X-Mailer: Zmail v1.0 Message-ID: <202301091940437129873@zte.com.cn> Mime-Version: 1.0 From: <yang.yang29@zte.com.cn> To: <djwong@kernel.org> Cc: <linux-xfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <xu.panda@zte.com.cn>, <yang.yang29@zte.com.cn> Subject: =?utf-8?q?=5BPATCH_linux-next=5D_xfs=3A_use_strscpy=28=29_to_instea?= =?utf-8?q?d_of_strncpy=28=29?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl1.zte.com.cn 309BeefP089112 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.251.13.novalocal with ID 63BBFD3D.000 by FangMail milter! X-FangMail-Envelope: 1673264445/4NrBpP5TMYz4y3Z2/63BBFD3D.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/<yang.yang29@zte.com.cn> X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63BBFD3D.000/4NrBpP5TMYz4y3Z2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754545183507343565?= X-GMAIL-MSGID: =?utf-8?q?1754545183507343565?= |
Series |
[linux-next] xfs: use strscpy() to instead of strncpy()
|
|
Commit Message
Yang Yang
Jan. 9, 2023, 11:40 a.m. UTC
From: Xu Panda <xu.panda@zte.com.cn> The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL-terminated strings. Signed-off-by: Xu Panda <xu.panda@zte.com.cn> Signed-off-by: Yang Yang <yang.yang29@zte.com.cn> --- fs/xfs/xfs_xattr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Comments
On Mon, Jan 09, 2023 at 07:40:43PM +0800, yang.yang29@zte.com.cn wrote: > From: Xu Panda <xu.panda@zte.com.cn> > > The implementation of strscpy() is more robust and safer. > That's now the recommended way to copy NUL-terminated strings. > > Signed-off-by: Xu Panda <xu.panda@zte.com.cn> > Signed-off-by: Yang Yang <yang.yang29@zte.com.cn> Looks fine, Reviewed-by: Darrick J. Wong <djwong@kernel.org> --D > --- > fs/xfs/xfs_xattr.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c > index 10aa1fd39d2b..913c1794bc2f 100644 > --- a/fs/xfs/xfs_xattr.c > +++ b/fs/xfs/xfs_xattr.c > @@ -212,9 +212,7 @@ __xfs_xattr_put_listent( > offset = context->buffer + context->count; > memcpy(offset, prefix, prefix_len); > offset += prefix_len; > - strncpy(offset, (char *)name, namelen); /* real name */ > - offset += namelen; > - *offset = '\0'; > + strscpy(offset, (char *)name, namelen + 1); /* real name */ > > compute_size: > context->count += prefix_len + namelen + 1; > -- > 2.15.2
On Wed, Feb 01, 2023 at 04:57:02PM -0800, Darrick J. Wong wrote: > On Mon, Jan 09, 2023 at 07:40:43PM +0800, yang.yang29@zte.com.cn wrote: > > From: Xu Panda <xu.panda@zte.com.cn> > > > > The implementation of strscpy() is more robust and safer. > > That's now the recommended way to copy NUL-terminated strings. > > > > Signed-off-by: Xu Panda <xu.panda@zte.com.cn> > > Signed-off-by: Yang Yang <yang.yang29@zte.com.cn> > > Looks fine, > Reviewed-by: Darrick J. Wong <djwong@kernel.org> > > --D > > > --- > > fs/xfs/xfs_xattr.c | 4 +--- > > 1 file changed, 1 insertion(+), 3 deletions(-) > > > > diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c > > index 10aa1fd39d2b..913c1794bc2f 100644 > > --- a/fs/xfs/xfs_xattr.c > > +++ b/fs/xfs/xfs_xattr.c > > @@ -212,9 +212,7 @@ __xfs_xattr_put_listent( > > offset = context->buffer + context->count; > > memcpy(offset, prefix, prefix_len); > > offset += prefix_len; > > - strncpy(offset, (char *)name, namelen); /* real name */ > > - offset += namelen; > > - *offset = '\0'; > > + strscpy(offset, (char *)name, namelen + 1); /* real name */ The name is not null terminated, it will result slab-out-of-bounds in strscpy(). [1] https://lore.kernel.org/linux-xfs/00000000000065a46a05f4529f59@google.com/T/#u > > > > compute_size: > > context->count += prefix_len + namelen + 1; > > -- > > 2.15.2
diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c index 10aa1fd39d2b..913c1794bc2f 100644 --- a/fs/xfs/xfs_xattr.c +++ b/fs/xfs/xfs_xattr.c @@ -212,9 +212,7 @@ __xfs_xattr_put_listent( offset = context->buffer + context->count; memcpy(offset, prefix, prefix_len); offset += prefix_len; - strncpy(offset, (char *)name, namelen); /* real name */ - offset += namelen; - *offset = '\0'; + strscpy(offset, (char *)name, namelen + 1); /* real name */ compute_size: context->count += prefix_len + namelen + 1;