fs: ocfs2: Replace strlcpy with sysfs_emit
PATCH v2 1/1 fs: ocfs2: Replace strlcpy with sysfs_emit
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with sysfs_emit().
Direct replacement is safe here since its ok for kernel_param_ops.get() to return -errno [3].
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
[3] https://elixir.bootlin.com/linux/v6.5/source/include/linux/moduleparam.h#L52
---
v2:
* Removes patch [1/2] which replaced module_param_call with module_param_cb.
* Use sysfs_emit instead of strscpy.
v1:
* https://lore.kernel.org/all/[email protected]/
fs/ocfs2/dlmfs/dlmfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ocfs2/dlmfs/dlmfs.c +1 -2
@@ -80,8 +80,7 @@ static int param_set_dlmfs_capabilities(const char *val,static int param_get_dlmfs_capabilities (char *buffer,const struct kernel_param *kp) { -return strlcpy (buffer,DLMFS_CAPABILITIES , -strlen (DLMFS_CAPABILITIES ) +1 ); +return sysfs_emit (buffer,DLMFS_CAPABILITIES ); }module_param_call (capabilities, param_set_dlmfs_capabilities, param_get_dlmfs_capabilities,NULL ,0444 );
--
2.42.0.283.g2d96d420d3-goog
Quoted 7 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withsysfs_emit().
Quoted 8 lines
Direct replacement is safe here since its ok for
kernel_param_ops.get()to return -errno [3].[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
[3] https://elixir.bootlin.com/linux/v6.5/source/include/linux/moduleparam.h#L52Signed-off-by Azeem Shaikh <[email protected]>
Signature · 1 line
Kees Cook
Quoted 7 lines · Azeem Shaikh
strlcpy()reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to removestrlcpy()completely [2], replacestrlcpy()here withsysfs_emit().
Quoted 8 lines
Direct replacement is safe here since its ok for
kernel_param_ops.get()to return -errno [3].[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89
[3] https://elixir.bootlin.com/linux/v6.5/source/include/linux/moduleparam.h#L52Signed-off-by Azeem Shaikh <[email protected]>
Quoted 28 lines
---
v2:
* Removes patch [1/2] which replacedmodule_param_callwithmodule_param_cb.
* Usesysfs_emitinstead of strscpy.v1:
* https://lore.kernel.org/all/[email protected]/fs/ocfs2/dlmfs/dlmfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/ocfs2/dlmfs/dlmfs.c +1
-3@@ -80,8 +80,7 @@ static int param_set_dlmfs_capabilities(const char *val,static int param_get_dlmfs_capabilities (char *buffer,const struct kernel_param *kp) { -return strlcpy (buffer,DLMFS_CAPABILITIES , -strlen (DLMFS_CAPABILITIES ) +1 ); +return sysfs_emit (buffer,DLMFS_CAPABILITIES ); }module_param_call (capabilities, param_set_dlmfs_capabilities, param_get_dlmfs_capabilities,NULL ,0444 ); --2.42.0.283.g2d96d420d3-goog