Message ID | 20230911-strncpy-drivers-block-aoe-aoenet-c-v1-1-9643d6137ff9@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp762605vqx; Tue, 12 Sep 2023 17:21:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdCspbfu9kHBjgtM9Zql+pX2lEVbYZkTniVXPoCniBRc3SqgTsEIeflgZGsJwPCm5GrGJp X-Received: by 2002:a05:6808:168d:b0:3ab:5e9e:51f8 with SMTP id bb13-20020a056808168d00b003ab5e9e51f8mr1497958oib.9.1694564475929; Tue, 12 Sep 2023 17:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694564475; cv=none; d=google.com; s=arc-20160816; b=DXpdBb+OnYJTRgRYfyIgGbmlgBDIeNd6xne6gyuW5SX0XEHDTH/vJ/kdOzFTIjLXbH kTs3BW1vTpZ7jPf2dcjvxaI2vAwz41VekCd2a5j7ptlzygOyI4/JySkDas5PDu8ygows /adJoMuPp4mRnrMcC4bBlpHrlS6ipsuaNz/9FMx+2luHuQs7pZG6PCwZYsJeWvE3FtI+ vYm8TzLZ/Qy2tSdWVCGHPA0C0jsh2bXbNn3xgic+FtCJk+YQzrdRcViu6WmKgKKRHQ9d s6BHldI2zAlb6N2I9rdmS/m5+r6iJ3bPA8h720xnOSVxNpNm/20UJc5e1gWlK/8c46Uy qxVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=QwxqNL1zXUB9OAJf/Ygs9mELpjYs6oPReuh29ZTVE2Q=; fh=yEquvKw/hQcQgr1T6VQ0LMjRlXDVLPPyWobzvCWX+Ao=; b=YHly+0QFCJ481BySPGV4G8g9BoXRjb48E+5A+6F2qPPt8BXUm8FAx5qerPlj5Fu/Pg Z5n10liwgO+w+iG6+c4xrnOty4pemXgS5GR5tVRYmuE2pJ1VhM8Rpisd8jCZwADelLzf 5/t7kwF6WckHppW3sXk6vJAOckigh1Cu7l1ExjuJ6RXEpV7XesQNtuyOWv4Mg5WqzfVh YJKmX4W2Ih9Dwv1bKpKspJz1H4VhBXoIg+9r9S+K7GsuicUoHge5M7SlEJKJqeXBpcCf 8REvArAGipCUGiREnSaDxLCeu+wey4U2JMb9zXky9r5Dw7dleXCrIZ7RBUWk+pkxZjWj lVYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IohJ7v4y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id y190-20020a638ac7000000b00577646e2b5bsi5497538pgd.652.2023.09.12.17.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 17:21:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IohJ7v4y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 697918239DF6; Mon, 11 Sep 2023 21:32:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241332AbjILDOH (ORCPT <rfc822;ruipengqi7@gmail.com> + 40 others); Mon, 11 Sep 2023 23:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242185AbjILDN5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 11 Sep 2023 23:13:57 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82B4912D56 for <linux-kernel@vger.kernel.org>; Mon, 11 Sep 2023 18:51:23 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id d75a77b69052e-4131d4bc82dso61525501cf.3 for <linux-kernel@vger.kernel.org>; Mon, 11 Sep 2023 18:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694483482; x=1695088282; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=QwxqNL1zXUB9OAJf/Ygs9mELpjYs6oPReuh29ZTVE2Q=; b=IohJ7v4yNEPN4e3HETH7rcD46OlqJZhb20ewU5YC7bgiS+SwIWAvVeyV/xWLruUlQq aLunqiQf/HlP3DQzPWNoVSiQAAeBvsavOWnfKbfBm6HQQdh8IRphMFFFaQCGeOTy/ECv reZssnY1gmfn/+pQmzizI2bgYR+zEaydG/gfxEsL8QbIpUeQiykiwVi0agD3m5pQ3yFq eEHSxKgC0q2/Cu3wNAxvhtkLm9Ju9H2L+oFvqh+7ermjZ51R21nhuxt2KtDDvR4PmdmC wDpvDAFleo+a3Z1vDaaOyY6T0L1QBv4e8kj0oRFHAH3eck39rZZ+p6kNXEo69ucBUQoE ZG7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694483482; x=1695088282; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QwxqNL1zXUB9OAJf/Ygs9mELpjYs6oPReuh29ZTVE2Q=; b=fUmSr3orzTVBRpW4cIAtcA/uP1/QcdBZly6rPK/w+l08m5qWoOeDuZReKkfDOPq3kp YJKNhzI5DFPfGC2iT2+ga1/BG7vL5Y76p/F01SgJbXzukThUBmXSnv1H44PEIszh0maQ LA1KIhlH4mMdGqyaUAUAAi4J5kXlN3wPi+opJ/b5rkdRcgr4EyQJRnyBL8C2nl7NiDJ0 q12TPHihEqRvAxjI7M1QKqK2HIneU9cLp8x0afmXAfgmDHRm2V5M2pDr9Gf9JxlmIu7n Nz6TcGlFmOvuxxwbTbmfcaN+yAJHcaowcjxnMpc0XGy84jEsEUARaNa2kBioYspEhE1r qzyQ== X-Gm-Message-State: AOJu0YxuYMN9PkdYIkScPba7CfGMrQUJRd876CHHq3FASf2DiZMOcePv InBZ3Q1Bew4B8W8S4TlRwCLc/YVSRCllPrJqKQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a81:b708:0:b0:581:3939:59a2 with SMTP id v8-20020a81b708000000b00581393959a2mr281042ywh.3.1694466550612; Mon, 11 Sep 2023 14:09:10 -0700 (PDT) Date: Mon, 11 Sep 2023 21:09:07 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAPOB/2QC/x2NzQrCMBAGX6Xs2YUk/oC+inhIk6+6KEnZLaVS+ u7GHuYwl5mVDCowunUrKWYxqaWJP3SUXrE8wZKbU3Dh6K7es01a0vjlrDJDjftPTW+OFX8KJk7 swimjj/ni3ZlaaFQMsuyT+2Pbfr6XNDh0AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694466549; l=1855; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=isAQzdD4TDo3zPe9CmPoe7IjN/uC1JjTZgMq1hRyNwE=; b=PhU1KfeKpdN/BDvmqV7i6qAIViRdCxXDRe+/LXWdXeF0pas87bxDJPMKvwHjUa7w8g1DIDeue gKAjrn2y7siAoBO+CzhL32W04xXDWNV/yjjqwSJhVE0GfveW0V6sWnm X-Mailer: b4 0.12.3 Message-ID: <20230911-strncpy-drivers-block-aoe-aoenet-c-v1-1-9643d6137ff9@google.com> Subject: [PATCH] aoe: refactor deprecated strncpy From: Justin Stitt <justinstitt@google.com> To: Justin Sanders <justin@coraid.com>, Jens Axboe <axboe@kernel.dk> Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Kees Cook <keescook@chromium.org>, Xu Panda <xu.panda@zte.com.cn>, Yang Yang <yang.yang29@zte.com>, Justin Stitt <justinstitt@google.com> Content-Type: text/plain; charset="utf-8" Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Sep 2023 21:32:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776879639846077578 X-GMAIL-MSGID: 1776879639846077578 |
Series |
aoe: refactor deprecated strncpy
|
|
Commit Message
Justin Stitt
Sept. 11, 2023, 9:09 p.m. UTC
`strncpy` is deprecated for use on NUL-terminated destination strings [1].
`aoe_iflist` is expected to be NUL-terminated which is evident by its
use with string apis later on like `strspn`:
| p = aoe_iflist + strspn(aoe_iflist, WHITESPACE);
It also seems `aoe_iflist` does not need to be NUL-padded which means
`strscpy` [2] is a suitable replacement due to the fact that it
guarantees NUL-termination on the destination buffer while not
unnecessarily NUL-padding.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>
Cc: Xu Panda <xu.panda@zte.com.cn>
Cc: Yang Yang <yang.yang29@zte.com>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note: This exact same patch exists [3] but seemed to die so I'm
resending. If it was actually picked-up somewhere then we can ignore
this patch.
[3]: https://lore.kernel.org/all/202212051930256039214@zte.com.cn/
---
drivers/block/aoe/aoenet.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
---
base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c
change-id: 20230911-strncpy-drivers-block-aoe-aoenet-c-024debad6105
Best regards,
--
Justin Stitt <justinstitt@google.com>
Comments
On Mon, Sep 11, 2023 at 09:09:07PM +0000, Justin Stitt wrote: > `strncpy` is deprecated for use on NUL-terminated destination strings [1]. > > `aoe_iflist` is expected to be NUL-terminated which is evident by its > use with string apis later on like `strspn`: > | p = aoe_iflist + strspn(aoe_iflist, WHITESPACE); > > It also seems `aoe_iflist` does not need to be NUL-padded which means > `strscpy` [2] is a suitable replacement due to the fact that it > guarantees NUL-termination on the destination buffer while not > unnecessarily NUL-padding. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Cc: Kees Cook <keescook@chromium.org> > Cc: Xu Panda <xu.panda@zte.com.cn> > Cc: Yang Yang <yang.yang29@zte.com> > Signed-off-by: Justin Stitt <justinstitt@google.com> Agreed, truncation is the current behavior, and padding isn't needed. (Or more precisely, it's already zeroed and this function is called once.) Reviewed-by: Kees Cook <keescook@chromium.org> > --- > Note: This exact same patch exists [3] but seemed to die so I'm > resending. If it was actually picked-up somewhere then we can ignore > this patch. > > [3]: https://lore.kernel.org/all/202212051930256039214@zte.com.cn/ Ah, weird. Well, I think this current one has a more complete commit log, so let's use this one. -Kees > --- > drivers/block/aoe/aoenet.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/block/aoe/aoenet.c b/drivers/block/aoe/aoenet.c > index 63773a90581d..c51ea95bc2ce 100644 > --- a/drivers/block/aoe/aoenet.c > +++ b/drivers/block/aoe/aoenet.c > @@ -39,8 +39,7 @@ static struct ktstate kts; > #ifndef MODULE > static int __init aoe_iflist_setup(char *str) > { > - strncpy(aoe_iflist, str, IFLISTSZ); > - aoe_iflist[IFLISTSZ - 1] = '\0'; > + strscpy(aoe_iflist, str, IFLISTSZ); > return 1; > } > > > --- > base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c > change-id: 20230911-strncpy-drivers-block-aoe-aoenet-c-024debad6105 > > Best regards, > -- > Justin Stitt <justinstitt@google.com> >
On 9/14/23 9:21 PM, Kees Cook wrote: > On Mon, Sep 11, 2023 at 09:09:07PM +0000, Justin Stitt wrote: >> `strncpy` is deprecated for use on NUL-terminated destination strings [1]. >> >> `aoe_iflist` is expected to be NUL-terminated which is evident by its >> use with string apis later on like `strspn`: >> | p = aoe_iflist + strspn(aoe_iflist, WHITESPACE); >> >> It also seems `aoe_iflist` does not need to be NUL-padded which means >> `strscpy` [2] is a suitable replacement due to the fact that it >> guarantees NUL-termination on the destination buffer while not >> unnecessarily NUL-padding. >> >> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] >> Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] >> Link: https://github.com/KSPP/linux/issues/90 >> Cc: linux-hardening@vger.kernel.org >> Cc: Kees Cook <keescook@chromium.org> >> Cc: Xu Panda <xu.panda@zte.com.cn> >> Cc: Yang Yang <yang.yang29@zte.com> >> Signed-off-by: Justin Stitt <justinstitt@google.com> > > Agreed, truncation is the current behavior, and padding isn't needed. > (Or more precisely, it's already zeroed and this function is called > once.) > > Reviewed-by: Kees Cook <keescook@chromium.org> Change looks fine to me too, but for the love of $deity, please use a proper subject line for these kinds of patches. It's not refactoring anything.
On Fri, Sep 15, 2023 at 6:36 AM Jens Axboe <axboe@kernel.dk> wrote: > > On 9/14/23 9:21 PM, Kees Cook wrote: > > On Mon, Sep 11, 2023 at 09:09:07PM +0000, Justin Stitt wrote: > >> `strncpy` is deprecated for use on NUL-terminated destination strings [1]. > >> > >> `aoe_iflist` is expected to be NUL-terminated which is evident by its > >> use with string apis later on like `strspn`: > >> | p = aoe_iflist + strspn(aoe_iflist, WHITESPACE); > >> > >> It also seems `aoe_iflist` does not need to be NUL-padded which means > >> `strscpy` [2] is a suitable replacement due to the fact that it > >> guarantees NUL-termination on the destination buffer while not > >> unnecessarily NUL-padding. > >> > >> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > >> Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > >> Link: https://github.com/KSPP/linux/issues/90 > >> Cc: linux-hardening@vger.kernel.org > >> Cc: Kees Cook <keescook@chromium.org> > >> Cc: Xu Panda <xu.panda@zte.com.cn> > >> Cc: Yang Yang <yang.yang29@zte.com> > >> Signed-off-by: Justin Stitt <justinstitt@google.com> > > > > Agreed, truncation is the current behavior, and padding isn't needed. > > (Or more precisely, it's already zeroed and this function is called > > once.) > > > > Reviewed-by: Kees Cook <keescook@chromium.org> > > Change looks fine to me too, but for the love of $deity, please use > a proper subject line for these kinds of patches. It's not refactoring > anything. > Fair. Perhaps "xyz: replace strncpy with strscpy"? > -- > Jens Axboe >
On 9/18/23 1:03 AM, Justin Stitt wrote: >> Change looks fine to me too, but for the love of $deity, please use >> a proper subject line for these kinds of patches. It's not refactoring >> anything. >> > > Fair. > > Perhaps "xyz: replace strncpy with strscpy"? That's a lot more descriptive, as a) it's actually accurate, and b) this is what the patch does. You just sent another one with this refactor wording which makes zero sense, please resend this and others targeted at block with a proper description.
diff --git a/drivers/block/aoe/aoenet.c b/drivers/block/aoe/aoenet.c index 63773a90581d..c51ea95bc2ce 100644 --- a/drivers/block/aoe/aoenet.c +++ b/drivers/block/aoe/aoenet.c @@ -39,8 +39,7 @@ static struct ktstate kts; #ifndef MODULE static int __init aoe_iflist_setup(char *str) { - strncpy(aoe_iflist, str, IFLISTSZ); - aoe_iflist[IFLISTSZ - 1] = '\0'; + strscpy(aoe_iflist, str, IFLISTSZ); return 1; }