Skip to content

Commit 75b3d5d

Browse files
JustinStittweiny2
authored andcommitted
dax: refactor deprecated strncpy
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. `dax_id->dev_name` is expected to be NUL-terminated and has been zero-allocated. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer. Moreover, due to `dax_id` being zero-allocated the padding behavior of `strncpy` is not needed and a simple 1:1 replacement of strncpy -> strscpy should suffice. 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: KSPP#90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
1 parent 6465e26 commit 75b3d5d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/dax/bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf,
103103
if (action == ID_ADD) {
104104
dax_id = kzalloc(sizeof(*dax_id), GFP_KERNEL);
105105
if (dax_id) {
106-
strncpy(dax_id->dev_name, buf, DAX_NAME_LEN);
106+
strscpy(dax_id->dev_name, buf, DAX_NAME_LEN);
107107
list_add(&dax_id->list, &dax_drv->ids);
108108
} else
109109
rc = -ENOMEM;

0 commit comments

Comments
 (0)