Message ID | 20230921-strncpy-drivers-infiniband-hw-qib-qib_iba7322-c-v1-1-373727763f5b@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5185240vqi; Thu, 21 Sep 2023 15:43:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8Nv3gdbULsF4K9dcmJAY+i147FDIpxsS8t9fMDMImiJMRlJ6lr+mKfI/88MS2jtcd9SAA X-Received: by 2002:a05:6808:de2:b0:3a9:e8bd:8510 with SMTP id g34-20020a0568080de200b003a9e8bd8510mr5750290oic.49.1695336215745; Thu, 21 Sep 2023 15:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695336215; cv=none; d=google.com; s=arc-20160816; b=VKdAyCEwdvwMNRwzxJ197SBk2xDWRCbBS4kT6V6lnoIQwm+PHhe7zbFdpuiutGaXjj lN/nIgRT5wy0s3fOMN7qAk7JGb7tful/sepENEQj8NjaD3UsLYxix1QgFxvG8BE/ykY+ dNde2sMV2tMxEXd1lE33AAVzqfvZivMmSdpRcfLUajE2xS4kWM0xA4QFRdQnWUKmiPRZ eg5sXgLOquujvp0iQA4qBQvnHkQ7Y5uHWHEG/4g37NZUdpykwjG3lzTTcDmHwkLz0oYF /e7vr9NNC8yjgasEAMUqBeFMfCmb9KMh/vR/9iby4FY2TGEJWQNwx9O5UT3ur2YQg6Nb UPNw== 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=yNCF6Zt81nxj8UQ8gNIU503gdPKJ22mbn5cyKbzYsNE=; fh=Du6LaqmSbX/L0lRBu7+9mJtYs+JHNh3Qn9UVZMoEs5I=; b=GF2z4cFjKOX/xx16Gy4L1hnbfMn3DEzTfPSS56qhKRqC+7zA8lg03xbShpNUGiSYVA /kRa3yCcWS1E1RsMn996p0izvz+Xwc6/dzdVAENH4w4Wv0NK8f/6jKE3eGYJqw5LCmZ1 2iBLvDEs0AeL8t8t2gPAzkev7m40zwmOGgoAc2m7CGQlzpt8JS/xErGhDpVK4zYGGsbo /n6Ya+/zCD+KbahhxPL9nGvdGbd5K4fPb1wqjlr5hhIpNqb7w8RewyZlbgJwinTh2q7k LojjWBfdsYB/bncrPJhPqt9136ksbz/IL0whQ5Pt//iDmwD5THC5zPclAAS3vyDi7F7G 596Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3CYaPaag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id by36-20020a056a0205a400b00563796a3ec6si2925647pgb.570.2023.09.21.15.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:43:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3CYaPaag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id E2F16811246C; Thu, 21 Sep 2023 12:26:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbjIUT0B (ORCPT <rfc822;ruipengqi7@gmail.com> + 28 others); Thu, 21 Sep 2023 15:26:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbjIUTZ7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 21 Sep 2023 15:25:59 -0400 Received: from mail-ua1-x94a.google.com (mail-ua1-x94a.google.com [IPv6:2607:f8b0:4864:20::94a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D4B1E6CE1 for <linux-kernel@vger.kernel.org>; Thu, 21 Sep 2023 12:25:53 -0700 (PDT) Received: by mail-ua1-x94a.google.com with SMTP id a1e0cc1a2514c-7a52a27dcc0so1247329241.0 for <linux-kernel@vger.kernel.org>; Thu, 21 Sep 2023 12:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695324352; x=1695929152; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yNCF6Zt81nxj8UQ8gNIU503gdPKJ22mbn5cyKbzYsNE=; b=3CYaPaag9BgPyD/BSrLigOIsBL/JhgHEiJqtsg7RdQb6EqM7Ne69H2AT+WjY6BV1d/ F2Dp/JJy35Hne4gWVdvbeozduZDEzPXugIcbC7RwxGgSRGpFHNQoiCwaW4SYWdCf5hWM +eNaGfDVUnRO7jBqqKcDqxqLzyfG+VUh5TZedBP8u+DbYDIOvmLSB3X/ood5yjI9AnaS UA5/nNPLsBsb/nL3VuueNyzigngkEu1FJNziPdmBsht6JRATVh/BeleU/yVn+AnVyNnL t4KJadsN99/8GbdJ3NdpEK8v+/cP+pCY30+63rZ1aaIwQZtRbUt8/YKoR8wgYWpegl1j dUgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695324352; x=1695929152; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yNCF6Zt81nxj8UQ8gNIU503gdPKJ22mbn5cyKbzYsNE=; b=FkzyXFlWSx8xRHP3w0hGOLPnp/II+Jl5np/opgSL3Z/5r5ugMsPdJFLLqlZOBVMj+A E23b8iNarJp4WvBcLQQ3bCDpUQqnTrJO8xs+A8Ogiyrvu2HpvEAbOOcLXXc/ChlGAJcF bbU2nQeRv6+r2PPUIiBm+1m+hRJrN2Bz1yywiqLNUzH4PCikd6U5nWMYVTxyDQoVSJln gC1maaTI0o5s7eBPg4i1Nz6yPPUgaWyiSZ8bner2zIHYiufaXmQS5mZpC7DVLARBrxC8 PaQ29r8/ocy+CBxDqfUFnl2w8T4V4CsdtJFCXk4Y7QIVbqIBzXucfQ0/lRfTD/4BiSLk UohQ== X-Gm-Message-State: AOJu0YyORvqTivwHSCRF56T2qJltaXKrKK66ZHVZo87kr4y3a+T/mwru hTVwR0YuRkpm7iNAIKHO0hInhQzgZDoZCuQMLA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:690c:d8f:b0:59b:5a5b:3a91 with SMTP id da15-20020a05690c0d8f00b0059b5a5b3a91mr235089ywb.2.1695283130297; Thu, 21 Sep 2023 00:58:50 -0700 (PDT) Date: Thu, 21 Sep 2023 07:58:48 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIALf3C2UC/x2NSw7CMAwFr1J5jaXU4VO4CkJVkzjUG1McVIqq3 p3AYhYzi/dWKGzCBS7NCsazFHlolXbXQBwHvTNKqg7kyLsztVhepnH6YDKZ2QqKZlEJgyYc3/i U8KOv4eSJMOK+S4fQ5aPzzFBXJ+Msy//xetu2Lx6W2eyBAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1695283129; l=2260; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=yG7G6SjuBc3zLcpp7gnhrmEb8A3RYwBew7uUX2315CY=; b=Yl+wEYYRm8WEbB2hhRaqUxc1tVIoc6ZKIs0c9VOUvp7taB3+qAlHxPrlAMZm8qubfP1QqWv9s qlGem8Mov1TAxEmbCRIduUctIT2LKxA/mRraFOOFJzFPh6rM/HxWvj/ X-Mailer: b4 0.12.3 Message-ID: <20230921-strncpy-drivers-infiniband-hw-qib-qib_iba7322-c-v1-1-373727763f5b@google.com> Subject: [PATCH] IB/qib: replace deprecated strncpy From: Justin Stitt <justinstitt@google.com> To: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>, Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org> Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt <justinstitt@google.com> Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DATE_IN_PAST_06_12, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:26:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777688867777955685 X-GMAIL-MSGID: 1777688867777955685 |
Series |
IB/qib: replace deprecated strncpy
|
|
Commit Message
Justin Stitt
Sept. 21, 2023, 7:58 a.m. UTC
`strncpy` is deprecated for use on NUL-terminated destination strings [1]
and as such we should prefer more robust and less ambiguous string
interfaces.
We know `txselect_list` is expected to be NUL-terminated based on its
use in `param_get_string()`:
| int param_get_string(char *buffer, const struct kernel_param *kp)
| {
| const struct kparam_string *kps = kp->str;
| return scnprintf(buffer, PAGE_SIZE, "%s\n", kps->string);
| }
Note that `txselect_list` is assigned to `kp_txselect`'s string field:
| static struct kparam_string kp_txselect = {
| .string = txselect_list,
| .maxlen = MAX_ATTEN_LEN
| };
Wherein it is then assigned the set and get methods:
| module_param_call(txselect, setup_txselect, param_get_string,
| &kp_txselect, S_IWUSR | S_IRUGO);
Considering the above, a suitable replacement is `strscpy` [2] due to
the fact that it guarantees NUL-termination on the destination buffer
without 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
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note: build-tested
---
drivers/infiniband/hw/qib/qib_iba7322.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
base-commit: 2cf0f715623872823a72e451243bbf555d10d032
change-id: 20230921-strncpy-drivers-infiniband-hw-qib-qib_iba7322-c-48d5b8f603ee
Best regards,
--
Justin Stitt <justinstitt@google.com>
Comments
On Thu, 21 Sep 2023 07:58:48 +0000, Justin Stitt wrote: > `strncpy` is deprecated for use on NUL-terminated destination strings [1] > and as such we should prefer more robust and less ambiguous string > interfaces. > > We know `txselect_list` is expected to be NUL-terminated based on its > use in `param_get_string()`: > | int param_get_string(char *buffer, const struct kernel_param *kp) > | { > | const struct kparam_string *kps = kp->str; > | return scnprintf(buffer, PAGE_SIZE, "%s\n", kps->string); > | } > > [...] Applied, thanks! [1/1] IB/qib: replace deprecated strncpy https://git.kernel.org/rdma/rdma/c/cb7ab7854bc709 Best regards,
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c index 9d2dd135b784..f93906d8fc09 100644 --- a/drivers/infiniband/hw/qib/qib_iba7322.c +++ b/drivers/infiniband/hw/qib/qib_iba7322.c @@ -6127,7 +6127,7 @@ static int setup_txselect(const char *str, const struct kernel_param *kp) TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ); return -EINVAL; } - strncpy(txselect_list, str, ARRAY_SIZE(txselect_list) - 1); + strscpy(txselect_list, str, sizeof(txselect_list)); xa_for_each(&qib_dev_table, index, dd) if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)