Skip to contentSkip to conversation

kernfs: use strscpy() is more robust and safer

PATCH In review [email protected] 2 participants 3 messages Nov 15, 2022 kernfs

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernfs: use strscpy() is more robust and safer

From: guo ziliang <[email protected]>

The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings.

---
 fs/kernfs/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/kernfs/dir.c +1 -1
index 77d7a3a..fbb8df4 100644
@@ -844,7 +844,7 @@ static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent,
 
        spin_lock_irq(&kernfs_pr_cont_lock);
 
-       len = strlcpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf));
+       len = strscpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf));
 
        if (len >= sizeof(kernfs_pr_cont_buf)) {
                spin_unlock_irq(&kernfs_pr_cont_lock);

--
1.8.3.1

maintainer
#1 lore raw
Quoted 3 lines · On Tue, Nov 15, 2022 at 08:47:45AM +0800, [email protected] wrote:

From: guo ziliang <[email protected]>

The implementation of strscpy() is more robust and safer.

How exactly is it more robust and safer?

Quoted 1 line

That's now the recommended way to copy NUL terminated strings.

Recommended by whom for what?

Quoted 11 lines
---
 fs/kernfs/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/kernfs/dir.c +0 -0
index 77d7a3a..fbb8df4 100644

fs/kernfs/dir.c static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent, · line 847

Quoted 5 lines
fs/kernfs/dir.c +1 -1
@@ -844,7 +844,7 @@ static struct kernfs_node *kernfs_walk_ns(struct kernfs_node *parent,
 
        spin_lock_irq(&kernfs_pr_cont_lock);
 
-       len = strlcpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf));
+       len = strscpy(kernfs_pr_cont_buf, path, sizeof(kernfs_pr_cont_buf));

How did you test this change is correct and does not cause any problems?

How was this issue found?

thanks,

greg k-h

maintainer
#2 lore raw
In reply to [email protected]
Quoted 6 lines · On Tue, Nov 15, 2022 at 08:47:45AM +0800, [email protected] wrote:

From: guo ziliang <[email protected]>

The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL terminated strings.

Note, your email is showing up as "unvalidated" with in invalid signature based on your domain. Please fix that up so that your patches will be able to be accepted, otherwise we have to consider this as a spoofed email :(

thanks,

greg k-h