Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2247002rdb; Tue, 3 Oct 2023 15:16:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwMTxw9EBqIQfLolSGzNGSSuZwO54ZEr6EE4DD6t2rR/IYsurecA/sSIw66Bw8o0Wu7gX2 X-Received: by 2002:a05:6808:1484:b0:3af:6c30:f206 with SMTP id e4-20020a056808148400b003af6c30f206mr1037228oiw.10.1696371370346; Tue, 03 Oct 2023 15:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696371370; cv=none; d=google.com; s=arc-20160816; b=afgh+DVYRrFHcy88uBalnyegrnpYAzmXkPDEAHGffP2qbg8BF5JlX1RCNH6v1sqUkL AvgTZMU3bnYRRTo9PJTAGEW3T2NbhksbJ3obB5+u6bzUr6Oh1yp8CWgZ9uQSX8J+rri3 cl0rObeO4m0SIvk8gFkq1zVRRGAcsNWkn918grXeonlrpH6oCzTtc1jq7EYIp2LPbg5w XiWDsgrZqRtsZW2bGODxp4EH4FagWi74295EQGZcLRBSvWNjwt55v6IOrUYRt06RJOI6 WDiYFSM4jrUyiR3NK7Q+QjcGjvvjNFnWw1UtMFXCX5Ep2ymnwlY1f9EymBMGMeu/qZqE zl6Q== 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=glUGQRb/GBSrrTfvaW6K09zpdeEaoPTJ452gHEUadv0=; fh=RKfebsDNIyH+twZam+5c8yCKZINPKBdqDYwU5GSUkYU=; b=shap3MIkW8hQllRt3tbP0vMueJYDOM8bhrO9t34QFWVsn43qAMFbiEGFz6oXZDyRXx 3UKasUQ531Oy5yrOvmceRx1j1pSIbnNWQTPpjlr+ERwMkP1pK5HuAJkpwgAJqj6qLrNB KMK3UVcvV2V4OFdQjeunO0fZtqq35nqhqLVmLJfUXLGll6M7iK+7rL8Za+s+2lwlT2k8 53ks7zWydCoKfPy1kiCDrLThCCDYCk7P3JJ6kMj/X1skytr7fBphJzfW5osYJ0ieYnWg 1ljMSLn0GcGbWW87NNvnBYHTpb756nqNncWnOAKI00EGBzs2IPxcOs/7sxx2Se2HioI3 FQ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="WTKWNT/Q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id s30-20020a63925e000000b00578e2b20624si2464406pgn.72.2023.10.03.15.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 15:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="WTKWNT/Q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 0584780BB56D; Tue, 3 Oct 2023 15:16:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232460AbjJCWPx (ORCPT + 99 others); Tue, 3 Oct 2023 18:15:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231634AbjJCWPv (ORCPT ); Tue, 3 Oct 2023 18:15:51 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 631C0AB for ; Tue, 3 Oct 2023 15:15:48 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d859ac9ea15so1757856276.2 for ; Tue, 03 Oct 2023 15:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696371347; x=1696976147; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=glUGQRb/GBSrrTfvaW6K09zpdeEaoPTJ452gHEUadv0=; b=WTKWNT/QY1KIvHBOebCr0+RgxvLLRJczRHQlHgZHKjwz3TVC7f5TpSS+6Al3tU4vmW +yaV4kbsIemMjOWfRqCvkb4NHINO1OiwkLdk73sfWIJIaDsNwwQTL4ii7H8ubW9Pub0T gJFtSz5E1D44t6vt0cze6YVGdkizEwWxc0LJozy03GiXqAe3xp++mbVOAWr66+tbrwTh OkARiPtKX/uGMfzIK4otS7aybV3G7EQDZqP72gPCLvt4Pazw0r2At7xp4Nvyvwibtqs9 rDT8TkZfvsZwvtR1nfsP8UPYaAXAZRj+qmne4RJjR4IIJi/+g37N0GYkx5pdB2OaJwoo ADVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696371347; x=1696976147; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=glUGQRb/GBSrrTfvaW6K09zpdeEaoPTJ452gHEUadv0=; b=tvzPa9rR33HZJYM5pTa5CggKdFHu7MoMQLgBy1qpoKsJOqnS+Yk99JaJQDIekildZt k3ZgTZ3ttK6wIhq8LdhaTMyPti2UX98PSffnxdWKNPzkIv/JDyxLfhKOyrU4hzXgiC3f u0p2+sj9tTaW5OdqIcXOiSt3BgDoNSxX4w3NSdaaPk63yZO+GsuV3t1bZkMkdLeqVPrK 4zQ5B3D+ZW0iMG17S4u9EekWPXvMVKmtyPq3IwwFNKDcu3gS+sojJkUe9FHILAokBpKK wvwJw157V+THn4R+nBPQoUeMQJie/802LH9oClrTznKV1Bge8ZXhbnbPcbmq5n93rA8G uJ+g== X-Gm-Message-State: AOJu0Yw+P955HSrhr+zEAsSi9RDZMgv1dSjUtvqxNJ10VuT5FjXCOd13 1oM5usvCu1RY7YKVKqsj83+RImmU5W3J8nphzg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:1603:b0:d7a:bfcf:2d7 with SMTP id bw3-20020a056902160300b00d7abfcf02d7mr8207ybb.6.1696371347547; Tue, 03 Oct 2023 15:15:47 -0700 (PDT) Date: Tue, 03 Oct 2023 22:15:45 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAJCSHGUC/5WNQQ6CMBBFr0K6dkw7iigr72FYNO0ATYSSGWwkh LtbuIHL9/P/f6sS4kCi6mJVTClIiGMGPBXK9XbsCILPrFDjRT+wApl5dNMCnkMiFhhIxOZa+9m nMEyzWAEHLaIv7VXfkVDlt4mpDd/D9Goy90HmyMshTmZP/3ckAwbIW3crna+00c8uxu5NZxcH1 Wzb9gOuMsAt3wAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696371346; l=3172; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=D6TnBFlTL+yFDnhyUKzZ8WPpEO6pZlaPy5QQBmG4HnE=; b=+DWq/nrZH1zk08S36hWN94OBXnhx03M+unNMnYLjJ+uFT7PHncocUUu4CY/RrIzw97eg07gGy UkHDufSUfF+CmRjkJLcW6IfcMUxy+o1rN7x/Ga2VZV3RcaabL63ZD3j X-Mailer: b4 0.12.3 Message-ID: <20231003-strncpy-drivers-message-fusion-mptsas-c-v2-1-5ce07e60bd21@google.com> Subject: [PATCH v2] scsi: message: fusion: replace deprecated strncpy with strscpy From: Justin Stitt To: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Cc: MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Kees Cook , Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 03 Oct 2023 15:16:07 -0700 (PDT) `strncpy` is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. The only caller of mptsas_exp_repmanufacture_info() is mptsas_probe_one_phy() which can allocate rphy in either sas_end_device_alloc() or sas_expander_alloc(). Both of which zero-allocate: | rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); ... this is supplied to mptsas_exp_repmanufacture_info() as edev meaning that no future NUL-padding of edev members is needed. 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. Also use the more idiomatic strscpy pattern of (dest, src, sizeof(dest)) 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 Signed-off-by: Justin Stitt --- Changes in v2: - use sizeof(dest) pattern (thanks Kees) - rebase onto mainline cbf3a2cb156a2c91 - Link to v1: https://lore.kernel.org/r/20230927-strncpy-drivers-message-fusion-mptsas-c-v1-1-edac65cd7010@google.com --- Note: build-tested only. Note: similar to drivers/scsi/mpi3mr/mpi3mr_transport.c +212 which uses strscpy --- drivers/message/fusion/mptsas.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c index 86f16f3ea478..300f8e955a53 100644 --- a/drivers/message/fusion/mptsas.c +++ b/drivers/message/fusion/mptsas.c @@ -2964,17 +2964,17 @@ mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc, goto out_free; manufacture_reply = data_out + sizeof(struct rep_manu_request); - strncpy(edev->vendor_id, manufacture_reply->vendor_id, - SAS_EXPANDER_VENDOR_ID_LEN); - strncpy(edev->product_id, manufacture_reply->product_id, - SAS_EXPANDER_PRODUCT_ID_LEN); - strncpy(edev->product_rev, manufacture_reply->product_rev, - SAS_EXPANDER_PRODUCT_REV_LEN); + strscpy(edev->vendor_id, manufacture_reply->vendor_id, + sizeof(edev->vendor_id)); + strscpy(edev->product_id, manufacture_reply->product_id, + sizeof(edev->product_id)); + strscpy(edev->product_rev, manufacture_reply->product_rev, + sizeof(edev->product_rev)); edev->level = manufacture_reply->sas_format; if (manufacture_reply->sas_format) { - strncpy(edev->component_vendor_id, + strscpy(edev->component_vendor_id, manufacture_reply->component_vendor_id, - SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN); + sizeof(edev->component_vendor_id)); tmp = (u8 *)&manufacture_reply->component_id; edev->component_id = tmp[0] << 8 | tmp[1]; edev->component_revision_id = --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20230927-strncpy-drivers-message-fusion-mptsas-c-f22d5a4082e2 Best regards, -- Justin Stitt