Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3383262rwb; Mon, 7 Aug 2023 12:36:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOuCu/hJBqnUMElpj7nxI5bGlkTkCdhjr9yAhmv3vxYdPEkYT2nBXXBqOnahuiTuBJqwmN X-Received: by 2002:a17:902:e314:b0:1bc:7001:6e5e with SMTP id q20-20020a170902e31400b001bc70016e5emr2564032plc.32.1691436976034; Mon, 07 Aug 2023 12:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691436976; cv=none; d=google.com; s=arc-20160816; b=dNLmi5KklreGoXdtMqtH80GN7qAEfvoz/ZxvRalo87h2VIUFpHpxdjr4sj5FiKSoN2 B9Uhx7Wzq9LIcEvxgSddkSUO+Gio/O6Ue6OmdX+LpzXQYiczwij8lPN3HPltnzUtJRet f39WvMJhyLKQ/XQ364gGorUM4Nb5GbAVfDJSFtwYVjmbphmLiaLSfcyRzKfWvftr5inn cY/Kg+nplsbv1VACd7s/U2t1rh4fxBh8PFEpuCmQ+geRyR8C9PYN0SXmU0GA7OBQ9frG 76PrzWOfcUMZxJXoXkAv6hGRxO9V7600bhiVpkp04/byMyqz4di3/xDf9UVsVwdfKqxL ab+g== 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=lvTqsAuYDg6pJiZTtB6ZMlYo7Jtn6FS/cj5mVT1Lh+0=; fh=sy/vTbxZ/WlkqimytAgqbE20Zt9CjqN9xU/CWWeSTUg=; b=wcwUSzzq49DT5RBUuWliXpxTkBW/dIuUEPtP0kDyTii8Nacp0l5CnKfKV0L1lFwE78 Pjr9LkKkQ3Qjb8jXPuBXApUacLEDiGShR0lI1FmaVP6Ym5AxmDYYk7+yTQhGkOXv/USu Sasls7emreWySfotULOs0jct0QTg1CAVVd41D2WN232GRgkRW6yCfDrePo86bGt7NnjM 9pgje3Xl4+BPTEfeX0K2eSWk3fJ3B4iSzvnVb/MDi+68H55N94xSy81Xn7B2AZaCQLq8 geiAsaD81+GPdwctRkEt+lpItNAXov9BkBzQxJumJah5rFfRYT1VLcvC1QhLPx7HDgmJ dsLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=VYtva0u1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t6-20020a170902bc4600b001bbbbb61c71si6142842plz.399.2023.08.07.12.36.03; Mon, 07 Aug 2023 12:36:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=VYtva0u1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231688AbjHGRtf (ORCPT + 99 others); Mon, 7 Aug 2023 13:49:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbjHGRtd (ORCPT ); Mon, 7 Aug 2023 13:49:33 -0400 Received: from mail-ot1-x34a.google.com (mail-ot1-x34a.google.com [IPv6:2607:f8b0:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3230C10F0 for ; Mon, 7 Aug 2023 10:49:32 -0700 (PDT) Received: by mail-ot1-x34a.google.com with SMTP id 46e09a7af769-6bc7afd0498so9390447a34.0 for ; Mon, 07 Aug 2023 10:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691430571; x=1692035371; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lvTqsAuYDg6pJiZTtB6ZMlYo7Jtn6FS/cj5mVT1Lh+0=; b=VYtva0u1UQj3x9ZSO1yuqxuAHrjmu3o+hHzAmbTG2LG3SW2I2x4Ahm/h0/boF43ElS R0NKeHmz2vFckrQPp1dqMkPRx6riDwxHuE7ZyWa3TrfpFB6ZTRYgeIqvZn/epGrEnuIk AqaGb2CAHARkz1eTMLvLPSvlZJiXdeKgtc6QDIbwbUdN+tcDmkD2QmCYORDCqaZ8TM0p nHoNrvHy00LeCE/OIBaB8xqpf3NbTvh+USGgky0bv85rwQTXy1mBcPYn9j7AMZrFQauP ce3GruZFlczh3rr90Z/gYYsqoV4dzqt0jUBTja+enXD/QUJSETU8FXP+RCGEffwzv+nq xzEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691430571; x=1692035371; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lvTqsAuYDg6pJiZTtB6ZMlYo7Jtn6FS/cj5mVT1Lh+0=; b=NMXwGTPpPJ7A39un8CfDjQjrZkOKYsjBAHsf4hjWMGVL5BBOiwE6z84rSMiMCAc53L 6d8iQt7DG8G0h3DdvhttZSnAM7tLxTiLFqOg488nbmdwzl3vMG92liPGGT352wED2j8p tqdPVj0LYdu6ZjgjC1ohTaYona2cDACgzddP7OcKKME7w8CeJyAPvsZ/sYTeg3MLSk/9 /clRm5YFccTp/IAxDZyVjh5qOYpMEysrw4O5PNCJ3Ol5R/nanqcay3jx22fcBacMKOwo HWMjlp4OlnYmUlDX5J7HFjKcRufwU7MdAUDwapN1auJDHXh8Eslw76V0a9BMJpK3+LLE QKyg== X-Gm-Message-State: AOJu0Yyg2Du/Glwuv1DnMA27FFXlvOcmsfA4WmUyPSbokxXoGgQpa60e 5GaCGdpCI/SpFQfZXhACFwbeV0ZgGKsLwoQXJw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a9d:7c95:0:b0:6bc:b75c:f32f with SMTP id q21-20020a9d7c95000000b006bcb75cf32fmr11241444otn.2.1691430571266; Mon, 07 Aug 2023 10:49:31 -0700 (PDT) Date: Mon, 07 Aug 2023 17:49:28 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAKcu0WQC/x3MTQqAIBBA4avIrBvwhyi6SrQwnXI2KkoRhHdPW n6L916oVJgqLOKFQjdXTrFDDQJcsPEkZN8NWmojZ2mwpit6zI4xeIvO2EnpfdLWjNCbXOjg5/+ tW2sfnbTOTl8AAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1691430570; l=1948; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=xdOHWoLsICV7kUxr/6xDknStuYMXv78lIRyu9paMiP8=; b=tFxAj2FlZPOq0oZKEB/bIYDagN+DiU16Koww8F9rnQI1LEkVkzSsnFMSpUQ4J53g/GPHsTbiL jC4KhL4eV8mA93uTvIXU3O3oEwXceeyJagwD2lIK4s1jLye7qa03Wcg X-Mailer: b4 0.12.3 Message-ID: <20230807-sound-pci-hda-v1-1-6d9cdcd085ca@google.com> Subject: [PATCH] ALSA: hda/tegra: refactor deprecated strncpy From: Justin Stitt To: Jaroslav Kysela , Takashi Iwai , Thierry Reding , Jonathan Hunter Cc: alsa-devel@alsa-project.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , 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=unavailable 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 `strncpy` is deprecated for use on NUL-terminated destination strings [1]. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on its destination buffer argument which is _not_ the case for `strncpy`! It should be noted that the current implementation is unlikely to have a bug because `drv_name` is a string literal with a size of 9 while `card->driver` has a size of 16. However, it is probably worthwhile to switch to a more robust and less ambiguous interface. [1]: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [2]: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- sound/pci/hda/hda_tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 9d0ab043880b..f16740500d46 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -378,14 +378,14 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) } /* driver name */ - strncpy(card->driver, drv_name, sizeof(card->driver)); + strscpy(card->driver, drv_name, sizeof(card->driver)); /* shortname for card */ sname = of_get_property(np, "nvidia,model", NULL); if (!sname) sname = drv_name; if (strlen(sname) > sizeof(card->shortname)) dev_info(card->dev, "truncating shortname for card\n"); - strncpy(card->shortname, sname, sizeof(card->shortname)); + strscpy(card->shortname, sname, sizeof(card->shortname)); /* longname for card */ snprintf(card->longname, sizeof(card->longname), --- base-commit: c1a515d3c0270628df8ae5f5118ba859b85464a2 change-id: 20230803-sound-pci-hda-c3a712b72a35 Best regards, -- Justin Stitt