Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1337334rdb; Fri, 20 Oct 2023 16:19:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHD1trhwjeaN4R6R2luiNppiBsEyQVdDWXup2XhOka5AOtZ/DUuOK7LFLKtF55iY1QE6S50 X-Received: by 2002:a05:6a00:230b:b0:6b4:6b34:8ce0 with SMTP id h11-20020a056a00230b00b006b46b348ce0mr3903415pfh.31.1697843950422; Fri, 20 Oct 2023 16:19:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697843950; cv=none; d=google.com; s=arc-20160816; b=vLkvnjmeajNe4DHiRo/fuyqwEtXFpejOsUDt0+WB78I8TQ4xAm/TPlwbPdHYT3YLYH MbD8wV4CHjLc2J2rBHHUUxl9b/qi8vn5Jbze9fD+G0SbGMuG36SVL5ZT5pXhIxSuu285 HaLagk/3HuvW6kwKRtUQesSOVEwHh0l2rVR3pUd3tKt8Fi/IBPQxF01RY5bVMpGGftDR HU/tiLsO8fKWJLIeOQoAsAcDuLaRGsebd+FDSKes6vwVWZ+gQYo6Fjqs9ayHV/dXwZUU UcAjac60cDU8JdRi/uXIaWa9aEhg0QbNfEzVDMI217MGbLnTdmoVzRkyhXbZ5Bwnxrl+ fvPw== 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=LidG2fExW0rwMYjQ9PdGz9R964tJxbhZmIPXqTMSy5E=; fh=b7RIYDdeCE9vm6+wpios8G7aVa2LsR2ZMGz66hkqU7U=; b=HAZMoPVkynLLAeF0uSlk/RYI+77Tu6sxtdb8F675f8j699z/FTTnBupd9uHysFGayf YVotdOFLBvr9WuukBHG9xUqRufy/lK1t1yYvycsHPZJcg6cuoTE9swLJlHHvakJmtV1p pBgjrYkZ4SU3u6i3UIz6SSN1ynuSiJJl8kz6yfXeCOjzuB822mmWl51F3E5Q1uyqKIim j1K/TdCQ9NAoPYu73opXTV21RRdy4VhMp6bGs74HQMmO6jGvQAbwySZLjyGWwghTRaHc w4TcqHUD73w3fHIIKtKRFBxgqmtyAX0pfbDwoVWP/MxFpfL05pxoNxs9z3CRpmROUNOW s7FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=u6fzuD3r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s13-20020a056a0008cd00b006bf53b69e21si153303pfu.359.2023.10.20.16.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 16:19:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=u6fzuD3r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 919D78338178; Fri, 20 Oct 2023 16:19:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229559AbjJTXTH (ORCPT + 99 others); Fri, 20 Oct 2023 19:19:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbjJTXTG (ORCPT ); Fri, 20 Oct 2023 19:19:06 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79B52D46 for ; Fri, 20 Oct 2023 16:19:00 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d9bc6447193so1689181276.3 for ; Fri, 20 Oct 2023 16:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697843939; x=1698448739; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=LidG2fExW0rwMYjQ9PdGz9R964tJxbhZmIPXqTMSy5E=; b=u6fzuD3rsjn3z3aHoTB50cXFsZlu5skZpJMntd8lw9hv8gL45x3eQgBgP/F7SESm7t l80guAEAEXVrdMor2zJpyzSpPzJvtV934Rb/hYMVE0iTBGvI/oZEBrvdMXrZiNvVdg8X h/RRshIw1SPsEVUdy1FZ55TC3yL28hMilns9oaPumWwaAKnT7Q91Btg9FB/8MZS6gUIs 9lsZvrczqbp01lU9PRNXiXrR8LaJXG93NeFRcFGqQfxdeczXjD1TzP1dymspTHzGjW/1 1pwDHF8OOTA6+Yiml2hLWHkABGCHgJdRqhy/AIdQrIu7X2ZYwJbq/9ZYVuiZY9V3KFcO tpUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697843939; x=1698448739; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LidG2fExW0rwMYjQ9PdGz9R964tJxbhZmIPXqTMSy5E=; b=Dj8B8C3Vfw945WRp9ZeZptTo5cCrG3hDUdDIZzzqN3F+NobZpIgdv/bXOc1IG54aqq NP3c8KIJJH/ZGS5MHiwXsiMlxKflEFrpRPQEGYX20Cb69M9or3dRwM+4XEHiAnPXTOV7 6p/C6iF673LPCifv/TT0r/wOV9sguRXYjqRhYahA4QpBc6X9hcn33y75SWayx+BNmPsH pFEHYn2WA/2XRpLKSsR6Z1IV2NHMl7H0ygV7kBF5eQljaiIY9APVm7ParlgIRpYsdmmL xnpmcMsipYPJAjfLuqhNspJOFbCt2BH/aDwjBQ7IR0E8d0YqEisuabjcHLYE/ZtSUIMs L1hQ== X-Gm-Message-State: AOJu0YzQ8d28M7/lP9zBb7/cF/ALX+XK3DonIYEAvMRCfuJaxIWn2iVr QDlIORguxJ7h6fOA/LTRpf3qfnpNRn5+Ptq1zg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:868d:0:b0:d9a:3f67:672c with SMTP id z13-20020a25868d000000b00d9a3f67672cmr73076ybk.3.1697843939429; Fri, 20 Oct 2023 16:18:59 -0700 (PDT) Date: Fri, 20 Oct 2023 23:18:59 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAOIKM2UC/yWNQQqEMAwAvyI5G6j1pF8RWbQmmoO1JIso4t8te hmYy8wFRipk0BYXKO1issUsVVlAWIY4E8qUHbzzdeW8Q/trDOnESWUnNdS02vzxFw0DMlPNgx/ HhhlyJimxHO+i6+/7AZWwx81yAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697843938; l=1846; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=llDPq5cpan48qP/R2KAFEviR6LsPU5tD/kVlkY7ZT6w=; b=gSmFNZVEghVuGZ1QS+hwXLkUsPakqZ2ey8hP3gdAEqKztchsCYGZ3kvhhioAzBjOCIjiQ5ZDr dmN+6PRIoUyCYc+q36XkXT3ghMHtL5a7jLdyBrtHBLjb+Xfd7TxspxV X-Mailer: b4 0.12.3 Message-ID: <20231020-strncpy-drivers-rpmsg-rpmsg_ns-c-v1-1-99b16b00c36c@google.com> Subject: [PATCH] rpmsg: replace deprecated strncpy with strscpy_pad From: Justin Stitt To: Bjorn Andersson , Mathieu Poirier Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,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=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: 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]); Fri, 20 Oct 2023 16:19:08 -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. We expect chinfo.name to be NUL-terminated based on its use with format strings: | dev_err(&ctrldev->dev, "failed to create %s channel\n", chinfo.name); Since chinfo is not default initialized, we should NUL-pad the `name` field so that the behavior is consistent with what strncpy() provides: | struct rpmsg_channel_info chinfo; Considering the above, a suitable replacement is `strscpy_pad` due to the fact that it guarantees both NUL-termination and NUL-padding on the destination buffer. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/rpmsg/rpmsg_ns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c index c70ad03ff2e9..bde8c8d433e0 100644 --- a/drivers/rpmsg/rpmsg_ns.c +++ b/drivers/rpmsg/rpmsg_ns.c @@ -50,7 +50,7 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, /* don't trust the remote processor for null terminating the name */ msg->name[RPMSG_NAME_SIZE - 1] = '\0'; - strncpy(chinfo.name, msg->name, sizeof(chinfo.name)); + strscpy_pad(chinfo.name, msg->name, sizeof(chinfo.name)); chinfo.src = RPMSG_ADDR_ANY; chinfo.dst = rpmsg32_to_cpu(rpdev, msg->addr); --- base-commit: 9c5d00cb7b6bbc5a7965d9ab7d223b5402d1f02c change-id: 20231020-strncpy-drivers-rpmsg-rpmsg_ns-c-ffe3fa2bb9ff Best regards, -- Justin Stitt