Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2457634rdh; Wed, 27 Sep 2023 03:20:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLp/zEsDsPFNGPwbrAwPEMG1vywjCYY5CKeL9D8Mki80MIgxfrWfH6k70KLoIKIiir12L/ X-Received: by 2002:a17:90b:4a83:b0:274:24e2:ae6d with SMTP id lp3-20020a17090b4a8300b0027424e2ae6dmr1233557pjb.0.1695810046272; Wed, 27 Sep 2023 03:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695810046; cv=none; d=google.com; s=arc-20160816; b=Y1rNC/uE52YWhrQu/l6qVvW0ADT3Z8QCmd/Y7kNTxg9tKxbsaERnSy9PZzqPIzbMHc +AEd32c8/0YREyJWJtrkIHk9JBekfGpSLaHfWLtLrxE9BcUgx0w2AfWUaMiGbA58NWb7 EiyNvzVevNCXTTWz5arAMa4BeU92TLxS3pCg37+2qyZxUbuQkdMjRJmqlaeNRKkUP7OU Jabz3WgQ/Q5N/X5dYjvboTietuUrpaO4/lKZzX7RqIbcVny6NR8EO8TaxeMQsKUcVLBj n7u10B/akvpi1osEpk4E48foCqZvvhAgapQNwDa0CaDS87xy30bUyUCRysH7EuKtu610 zfEw== 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=PdEyDvEQWoBI92qpF/Uzb1GUaex9NeolFXPHe23E1k8=; fh=aeIUXSTUtm8l55YzFG0DBkCxMyXC6AC8zyXZuSsTxN4=; b=WhlQJYwrokO7uHMP2P0efzatPK0lHumAPv0g2Dcek+SEdArJMussv81oCrwQnsjrf+ L15yittUBFajeDGcvaQ1WbOkTaIBkTy4e2HwjfdAzElQy2tx2ONYEc5lRaKffbCWwuDj 54OAiBRnM16t9dj2KEcgOL4ddVt3UDE1zb4nEQTTj3Dp6jzdkF7GtlnatYrxhY9PeT8p RfrENTT0dxpgLNwqw9nGL14EpKXoz3ghTapJ2neu3cMowx4a/56z42RWIo1RNtuzDZdn pyGLzsfCE/ZpfesIutv6MBU1KW+YGmbGy/Ru44vMKK3JZazfb870MgqouStz1qF0jrnH fCQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RzSvcCoZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id pf17-20020a17090b1d9100b00277387ac962si11086851pjb.2.2023.09.27.03.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 03:20:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RzSvcCoZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 552B5801BEAF; Tue, 26 Sep 2023 22:53:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbjI0Fxb (ORCPT + 99 others); Wed, 27 Sep 2023 01:53:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjI0Fwx (ORCPT ); Wed, 27 Sep 2023 01:52:53 -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 54485199 for ; Tue, 26 Sep 2023 22:52:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d84acda47aeso17821783276.3 for ; Tue, 26 Sep 2023 22:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695793935; x=1696398735; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=PdEyDvEQWoBI92qpF/Uzb1GUaex9NeolFXPHe23E1k8=; b=RzSvcCoZN1JIWrqdM8SYFc/lG7oJ3rZn/MloLV8r/A1Bltyj2o7Kg9r9zusYwajApS GHNqHKIzV+VDBd0d/kLqzwK8kJMeWc7jJohq9aaq9vX8yQDxJWIqnR2TcHZ9ox0X42/9 NkgFnitQWnJGaikxL2+WsX+PXSgoOf+DbcgUDwL+A/AU4Vd3LJ31LU1b+ajMd98UrjBG 23ITdrNScc2RqBiZB9HC48wVh7nOzisfuWAk9/SPnsbv0Ncl+YBep/uPokNL33cSTeOg oFJuNC4JfH7UEmLfDURfzT82WSWJPCcrpe5DykpT58kwrQRCaJYF5rs9Qnwx6hmVfclQ Nt9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695793935; x=1696398735; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PdEyDvEQWoBI92qpF/Uzb1GUaex9NeolFXPHe23E1k8=; b=wQYM7XODDlDGZVUKSKF+mYj5Hhdk2xxYWat3j7bE5Ghuba1uADZG/BuAtzBlDUePRR ELuzkJesM8YNRbIjUQjn9DkAkRNcPTu+rOD3gB0wJ6gMkvgZMllMicaluWsNYpgEtP9c qwZcc/EBJMqIzVrpOgNFOj8JS6TLOjLqiGHw0h1ozw5YmodSJWCSPRcJXC45EGFLHues EvcPw+JBb8owE2scEkePcI+a8ViKXmyF4u2TWKwdw3P/MHPTw38Ik5x46XQYwNKGVG7m Z2uFDHM4xwVddw10d6S82lQs+IZm1sHEpzljjlb00s+KQPPr02pBsCR1U35xfecQvCxt lAIw== X-Gm-Message-State: AOJu0Yz72Aiw9qxEYedV88Bwe6bxd4HM1VtMF/vMnr3OEzkjrhFFP6J9 q536/zOgAxHwZnOk5RvJM43gjGDWicpIqd3LZQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:cc57:0:b0:d4d:8ade:4dfa with SMTP id l84-20020a25cc57000000b00d4d8ade4dfamr11730ybf.1.1695793935601; Tue, 26 Sep 2023 22:52:15 -0700 (PDT) Date: Wed, 27 Sep 2023 05:52:14 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAA3DE2UC/x3MwQqDMAwA0F+RnBfQtk7crwwPLkaXQztJpDjEf 7d4fJd3gLEKG7yqA5SzmPxSQfOogL5jWhhlKgZXO1/3rkPbNNH6x0klsxpGMUL5xBwJCVsffOi 75jmPAcqxKs+y3/97OM8L8ryHqG8AAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1695793934; l=1586; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=wWwjcICs9gtgVAVLbVDl2AzKRTJfFBmL/hPhS0rX2sU=; b=H91kmNzP7h9iUJihNntBjcaYva+p8s04nGgbyn8MlVRybrFRnzz2WT4H/o661VS+FNDHi3FnW uYdMPF/jBmNBYE0aW5zXwz90P8UWU4tGEdGpR3XL4ospVokhUoyAQg2 X-Mailer: b4 0.12.3 Message-ID: <20230927-strncpy-drivers-misc-ibmvmc-c-v1-1-29f56cd3a269@google.com> Subject: [PATCH] ibmvmc: replace deprecated strncpy with strscpy From: Justin Stitt To: Brad Warrum , Ritu Agarwal , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 26 Sep 2023 22:53:39 -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. 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 --- Note: build-tested only. --- drivers/misc/ibmvmc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/misc/ibmvmc.c b/drivers/misc/ibmvmc.c index 2101eb12bcba..6d9ed9325f9f 100644 --- a/drivers/misc/ibmvmc.c +++ b/drivers/misc/ibmvmc.c @@ -1249,9 +1249,7 @@ static long ibmvmc_ioctl_sethmcid(struct ibmvmc_file_session *session, return -EIO; } - /* Make sure buffer is NULL terminated before trying to print it */ - memset(print_buffer, 0, HMC_ID_LEN + 1); - strncpy(print_buffer, hmc->hmc_id, HMC_ID_LEN); + strscpy(print_buffer, hmc->hmc_id, sizeof(print_buffer)); pr_info("ibmvmc: sethmcid: Set HMC ID: \"%s\"\n", print_buffer); memcpy(buffer->real_addr_local, hmc->hmc_id, HMC_ID_LEN); --- base-commit: 6465e260f48790807eef06b583b38ca9789b6072 change-id: 20230927-strncpy-drivers-misc-ibmvmc-c-534349716fa4 Best regards, -- Justin Stitt