inotify: Use strscpy() for event->name copies
Subsystems (3)
PATCH 1/1 inotify: Use strscpy() for event->name copies
Since we have already allocated "len + 1" space for event->name, make sure that name->name cannot ever accidentally cause a copy overflow by calling strscpy() instead of the unbounded strcpy() routine. This assists in the ongoing efforts to remove the unsafe strcpy() API[1] from the kernel.
---
Cc: Jan Kara <[email protected]>
Cc: Amir Goldstein <[email protected]>
Cc: [email protected]
--- fs/notify/inotify/inotify_fsnotify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/notify/inotify/inotify_fsnotify.c +1 -1
@@ -121,7 +121,7 @@ int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask, event->sync_cookie = cookie; event->name_len = len;if (len) -strcpy (event->name, name->name); +strscpy (event->name, name->name, event->name_len +1 ); ret =fsnotify_add_event (group, fsn_event, inotify_merge);if (ret) {
Signature · 1 line
2.34.1
Quoted 4 lines · Kees Cook
Since we have already allocated "len + 1" space for
event->name, make sure thatname->namecannot ever accidentally cause a copy overflow by callingstrscpy()instead of the unboundedstrcpy()routine. This assists in the ongoing efforts to remove the unsafestrcpy()API[1] from the kernel.
Since a qstr can't contain a NUL before the length, why not just use memcpy()?
Quoted 4 lines
fs/notify/inotify/inotify_fsnotify.c +1
-1event->name_len = len;if (len) -strcpy (event->name, name->name); +strscpy (event->name, name->name, event->name_len +1 );
Quoted 6 lines · Matthew Wilcox
Quoted 4 lines · Kees Cook
Since we have already allocated "len + 1" space for
event->name, make sure thatname->namecannot ever accidentally cause a copy overflow by callingstrscpy()instead of the unboundedstrcpy()routine. This assists in the ongoing efforts to remove the unsafestrcpy()API[1] from the kernel.
Quoted 7 lines
Since a qstr can't contain a NUL before the length, why not just use
memcpy()?fs/notify/inotify/inotify_fsnotify.c int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask, · line 124
Quoted 4 lines
fs/notify/inotify/inotify_fsnotify.c +1
-1event->name_len = len;if (len) -strcpy (event->name, name->name); +strscpy (event->name, name->name, event->name_len +1 );
So that the destination is guaranteed to be NUL terminated no matter what's in the source. :) (i.e. try to limit unlikely conditions from expanding.)
Signature · 1 line
Kees Cook
Jan Kara
maintainerQuoted 7 lines · Kees Cook
Since we have already allocated "len + 1" space for
event->name, make sure thatname->namecannot ever accidentally cause a copy overflow by callingstrscpy()instead of the unboundedstrcpy()routine. This assists in the ongoing efforts to remove the unsafestrcpy()API[1] from the kernel.Signed-off-by Kees Cook <[email protected]>
Thanks. Added to my tree.
Honza
Quoted 24 lines
---
Cc: Jan Kara <[email protected]>
Cc: Amir Goldstein <[email protected]>
Cc: [email protected]--- fs/notify/inotify/inotify_fsnotify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/notify/inotify/inotify_fsnotify.c +1
-1@@ -121,7 +121,7 @@ int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask, event->sync_cookie = cookie; event->name_len = len;if (len) -strcpy (event->name, name->name); +strscpy (event->name, name->name, event->name_len +1 ); ret =fsnotify_add_event (group, fsn_event, inotify_merge);if (ret) {Signature · 1 line
2.34.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR