* [PATCH] ALSA: hda/tegra: refactor deprecated strncpy
@ 2023-08-07 17:49 Justin Stitt
2023-08-08 12:46 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Justin Stitt @ 2023-08-07 17:49 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Thierry Reding, Jonathan Hunter
Cc: alsa-devel, linux-tegra, linux-kernel, Kees Cook, linux-hardening,
Justin Stitt
`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 <justinstitt@google.com>
---
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 <justinstitt@google.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ALSA: hda/tegra: refactor deprecated strncpy
2023-08-07 17:49 [PATCH] ALSA: hda/tegra: refactor deprecated strncpy Justin Stitt
@ 2023-08-08 12:46 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2023-08-08 12:46 UTC (permalink / raw)
To: Justin Stitt
Cc: Jaroslav Kysela, Takashi Iwai, Thierry Reding, Jonathan Hunter,
alsa-devel, linux-tegra, linux-kernel, Kees Cook, linux-hardening
On Mon, 07 Aug 2023 19:49:28 +0200,
Justin Stitt wrote:
>
> `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 <justinstitt@google.com>
Thanks, applied.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-08 17:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-07 17:49 [PATCH] ALSA: hda/tegra: refactor deprecated strncpy Justin Stitt
2023-08-08 12:46 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).