summaryrefslogtreecommitdiffstats
path: root/kernel/power/hibernate.c
diff options
context:
space:
mode:
authorJustin Stitt <justinstitt@google.com>2024-04-29 20:50:30 +0000
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-04-30 12:59:30 +0200
commit7b831bd3cf322fdacd07f321d6d7297914ed79bc (patch)
tree9fd3ca93a7a72b395c55dc188381a71f6a5b0850 /kernel/power/hibernate.c
parent68313be43d4d1bc3b1a39d7d8d2887697e84607c (diff)
downloadlinux-stable-7b831bd3cf322fdacd07f321d6d7297914ed79bc.tar.gz
linux-stable-7b831bd3cf322fdacd07f321d6d7297914ed79bc.tar.bz2
linux-stable-7b831bd3cf322fdacd07f321d6d7297914ed79bc.zip
PM: hibernate: replace deprecated strncpy() with strscpy()
strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. This kernel config option is simply assigned with the resume_file buffer. It should be NUL-terminated but not necessarily NUL-padded as per its further usage with other string apis: | static int __init find_resume_device(void) | { | if (!strlen(resume_file)) | return -ENOENT; | | pm_pr_dbg("Checking hibernation image partition %s\n", resume_file); Use strscpy() [2] as it guarantees NUL-termination on the destination buffer. Specifically, use the new 2-argument version of strscpy() introduced in Commit e6584c3964f2f ("string: Allow 2-argument strscpy()"). 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: https://github.com/KSPP/linux/issues/90 Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Dhruva Gole <d-gole@ti.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'kernel/power/hibernate.c')
-rw-r--r--kernel/power/hibernate.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 43b1a82e800c..0a213f69a9e4 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -1361,7 +1361,7 @@ static int __init resume_setup(char *str)
if (noresume)
return 1;
- strncpy(resume_file, str, 255);
+ strscpy(resume_file, str);
return 1;
}