Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3495274rdb; Wed, 13 Sep 2023 13:58:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEo8FUTYYmN6ThafSmJh1mjHQiOydlpN97mxL/dzsgaIjJszQaL5oLJRcC2uhg+dZHQuJM3 X-Received: by 2002:a05:6a21:3e09:b0:14e:b4d5:782e with SMTP id bk9-20020a056a213e0900b0014eb4d5782emr3693342pzc.29.1694638684948; Wed, 13 Sep 2023 13:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694638684; cv=none; d=google.com; s=arc-20160816; b=id0O+Y6j/mAcyNc9DHC8TxlGQJpH9g9U0PGNqnNnGl9+fijt+Xu3+58lJCHVcP1nrP r2y0HPzP6bqqnsftWwEx6aPlPyo6fBLWzmmytAFNa6SODwqP5a98Cyj4ruXx0T7NnN4l mi0cuw+7dBAcgJPV3GLG3anlK3TlavB7IfqsdhDOx3eqFWuWPKyRtDK9yOAi2D4Ej//s 6Ai0zELz3EKq/j0ZtUfZdGsBmR51n7fOtYE0RjqqPcpUorNzpBwEohCh1JXtvoBxl33v E+kqjzK4BhpFexQQm55WktoFENKntHFLAgw62QiptDjdolxWlDlRbR24rPxHxkCeJNzq 5+Ww== 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=5D9cmGNnxZclEaUPRp7dDRkIa3NaBWA/5YbPgcSOdlU=; fh=aAv1Cvi1Z6XRUFNoD5R8m8vSvpJYw3pG6D1rKxY/bow=; b=MIZ5lCAo71E6Hg0vUPLxC+6NHbSMpYXQSid61itee4AQNUO9g8TPhNo5lrglqCrGCk hYk/PAuG8G/3pKvFtz3DZHdbTHq8SihSxGHcmnFzTnKg9csGmT28AyMxBBhfDEXuBIky jq2FaJJ6YfX1rwwNDLR8KQ82NQiHpqo1ANcd/D3k5ZyBBk4z43oGH+gJJuaT/Hx2tvAI 36KS5ce4UOA3pzelqUV+JL661WGdrZ3qGEZzQMqquH4wN2hcnqSS8ajNHuUbIR8i1DQF 8KflQGUZaQDkxrr3/2A/Y6Adz9/YAG0AJGo0wQDKzNu7hnU9Yx195Rb/4+ojNMSW1aNB 1QGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FLlzdeFa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u3-20020a656703000000b00573fc129092si11229799pgf.866.2023.09.13.13.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 13:58:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FLlzdeFa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 9697E8297C79; Wed, 13 Sep 2023 12:38:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232334AbjIMTiu (ORCPT + 99 others); Wed, 13 Sep 2023 15:38:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232480AbjIMTit (ORCPT ); Wed, 13 Sep 2023 15:38:49 -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 44ECB91 for ; Wed, 13 Sep 2023 12:38:45 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d8109d3a3bbso229422276.2 for ; Wed, 13 Sep 2023 12:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694633924; x=1695238724; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=5D9cmGNnxZclEaUPRp7dDRkIa3NaBWA/5YbPgcSOdlU=; b=FLlzdeFavhqlzy4MC1JUgkhtQCIAqORJqP4YlKTbXRHHW4SDPUKHATV5MG7sWtoqyw JlOk3w3zl5eiGAfXS3M3FGmu4NefugskyB0wyPlnHqKdpRKDM9trNLQkOF5sP1b9JFfp KwMvVJWqug/Q7aEmu8arEKEGdzhl2pRpVZ/twXErX9CSaUC7i1cx9nhoJvZanZM8Vb4E eWt8veY6YDfVS8EGtK3LT0OLIddNGlWCJBnW8Y1DF/dCIe0tIpMHRgOLRj//eQCr55jy yrEW/Qadkl2zT1V/439SdGxhci5KOcuulo7OIwwAgw0Bb6+75oyxGOXn6GjYg6FPqhlc Nd5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694633924; x=1695238724; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5D9cmGNnxZclEaUPRp7dDRkIa3NaBWA/5YbPgcSOdlU=; b=dTZxDNcutjvpiDkoXN0EFpkCSQ0uEl9LUHHiu/h057Q11w7xzWG8uhhBaiHipt7isL FrI1CTlEMfBOQKkaG9YDvVgstJjB6K7IETJ09tNjxVnfV2krjsK1ecbHASjN/9BATZWk 8oTcAmIGL+lXTHM9F9+GKyceWL8yk2ZXTCNtgnFxfLMkv80mxR4qlk91bLSIu1KlhVq6 f2JCIE68H4Vj+qTa3jpHQJuENS2Ke3wvGgb+KLDdg9vy6tldWGtbWi+HJXQLKM9oZZsR C4nXDJN60muPt5c98w0jIuEJuZUEH42N+h2Jas1jCl/HjXqUUouV+BsiqN5DnBd1RtUg mxZw== X-Gm-Message-State: AOJu0YzVT256Drs4q/m3nA65aG4p0kXeseLpMjUmhfXIamVb/j8C0ZUo K2cEvhggedR+5AdbzwXj0W7lxZMtpwDR2znHKA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:41ca:0:b0:d77:f6f9:159 with SMTP id o193-20020a2541ca000000b00d77f6f90159mr78122yba.9.1694633924538; Wed, 13 Sep 2023 12:38:44 -0700 (PDT) Date: Wed, 13 Sep 2023 19:38:44 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAMMPAmUC/x3NPQ7CMAxA4atUnrGUJkUIroIY8uMEDw2RXQqo6 t0bMX7LexsoCZPCbdhAaGXlV+0YTwPEp6+FkFM3WGOduY4OdZEa2w+T8EqimFnmjxfChYp4DG1 umCi8S1aMeJ7yJXifnY0GerMJZf7+f/fHvh9c242qfwAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694633923; l=1807; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=tFl2PNzqL8STywNv0UTNztdqinU7Ek8sPp6wO3F9Txw=; b=Qx9x2TQmkLa2oDNyG2+vl9LZXozyDkyNECZv70nQl8TbYysev2y1AlZud6Hv+kgnjZSkpklKS SwXrDu/ddO6AXv7TOSpT/PXQeIdImLO9VBF1J2iLFHssovmlcAAlMxf X-Mailer: b4 0.12.3 Message-ID: <20230913-strncpy-drivers-firmware-tegra-bpmp-debugfs-c-v1-1-828b0a8914b5@google.com> Subject: [PATCH] firmware: tegra: bpmp: refactor deprecated strncpy From: Justin Stitt To: Thierry Reding , Jonathan Hunter Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" 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 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 12:38:57 -0700 (PDT) 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 morse.vger.email `strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. It seems like the filename stored at `namevirt` is expected to be NUL-terminated. A suitable replacement is `strscpy_pad` due to the fact that it guarantees NUL-termination on the destination buffer whilst maintaining the NUL-padding behavior that strncpy provides. 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: compile tested only. --- drivers/firmware/tegra/bpmp-debugfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c index 6dfe3d34109e..bbcdd9fed3fb 100644 --- a/drivers/firmware/tegra/bpmp-debugfs.c +++ b/drivers/firmware/tegra/bpmp-debugfs.c @@ -610,7 +610,7 @@ static int debugfs_show(struct seq_file *m, void *p) } len = strlen(filename); - strncpy(namevirt, filename, namesize); + strscpy_pad(namevirt, filename, namesize); err = mrq_debugfs_read(bpmp, namephys, len, dataphys, datasize, &nbytes); @@ -661,7 +661,7 @@ static ssize_t debugfs_store(struct file *file, const char __user *buf, } len = strlen(filename); - strncpy(namevirt, filename, namesize); + strscpy_pad(namevirt, filename, namesize); if (copy_from_user(datavirt, buf, count)) { err = -EFAULT; --- base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec change-id: 20230913-strncpy-drivers-firmware-tegra-bpmp-debugfs-c-54f7baaf32c0 Best regards, -- Justin Stitt