* [PATCH v2] selftests/x86/lam: Zero out buffer for readlink()
@ 2023-10-16 6:24 Binbin Wu
2023-10-16 8:47 ` kirill.shutemov
2023-10-16 9:44 ` [tip: x86/mm] " tip-bot2 for Binbin Wu
0 siblings, 2 replies; 4+ messages in thread
From: Binbin Wu @ 2023-10-16 6:24 UTC (permalink / raw)
To: dave.hansen, luto, peterz, shuah
Cc: linux-kselftest, x86, linux-kernel, kirill.shutemov, binbin.wu
Zero out the buffer for readlink() since readlink() does not append a
terminating null byte to the buffer. Also change the buffer length
passed to readlink() to 'PATH_MAX - 1' to ensure the resulting string
is always null terminated.
Fixes: 833c12ce0f430 ("selftests/x86/lam: Add inherit test cases for linear-address masking")
Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
---
v1->v2:
- Change the buffer length passed to readlink() to 'PATH_MAX - 1' to ensure the
resulting string is always null terminated. [Kirill]
tools/testing/selftests/x86/lam.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c
index eb0e46905bf9..8f9b06d9ce03 100644
--- a/tools/testing/selftests/x86/lam.c
+++ b/tools/testing/selftests/x86/lam.c
@@ -573,7 +573,7 @@ int do_uring(unsigned long lam)
char path[PATH_MAX] = {0};
/* get current process path */
- if (readlink("/proc/self/exe", path, PATH_MAX) <= 0)
+ if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0)
return 1;
int file_fd = open(path, O_RDONLY);
@@ -680,14 +680,14 @@ static int handle_execve(struct testcases *test)
perror("Fork failed.");
ret = 1;
} else if (pid == 0) {
- char path[PATH_MAX];
+ char path[PATH_MAX] = {0};
/* Set LAM mode in parent process */
if (set_lam(lam) != 0)
return 1;
/* Get current binary's path and the binary was run by execve */
- if (readlink("/proc/self/exe", path, PATH_MAX) <= 0)
+ if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0)
exit(-1);
/* run binary to get LAM mode and return to parent process */
base-commit: 58720809f52779dc0f08e53e54b014209d13eebb
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] selftests/x86/lam: Zero out buffer for readlink()
2023-10-16 6:24 [PATCH v2] selftests/x86/lam: Zero out buffer for readlink() Binbin Wu
@ 2023-10-16 8:47 ` kirill.shutemov
2023-10-16 19:11 ` Shuah Khan
2023-10-16 9:44 ` [tip: x86/mm] " tip-bot2 for Binbin Wu
1 sibling, 1 reply; 4+ messages in thread
From: kirill.shutemov @ 2023-10-16 8:47 UTC (permalink / raw)
To: Binbin Wu
Cc: dave.hansen, luto, peterz, shuah, linux-kselftest, x86,
linux-kernel
On Mon, Oct 16, 2023 at 02:24:46PM +0800, Binbin Wu wrote:
> Zero out the buffer for readlink() since readlink() does not append a
> terminating null byte to the buffer. Also change the buffer length
> passed to readlink() to 'PATH_MAX - 1' to ensure the resulting string
> is always null terminated.
>
> Fixes: 833c12ce0f430 ("selftests/x86/lam: Add inherit test cases for linear-address masking")
>
> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
--
Kiryl Shutsemau / Kirill A. Shutemov
^ permalink raw reply [flat|nested] 4+ messages in thread
* [tip: x86/mm] selftests/x86/lam: Zero out buffer for readlink()
2023-10-16 6:24 [PATCH v2] selftests/x86/lam: Zero out buffer for readlink() Binbin Wu
2023-10-16 8:47 ` kirill.shutemov
@ 2023-10-16 9:44 ` tip-bot2 for Binbin Wu
1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Binbin Wu @ 2023-10-16 9:44 UTC (permalink / raw)
To: linux-tip-commits
Cc: Binbin Wu, Ingo Molnar, Kirill A. Shutemov, x86, linux-kernel
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 29060633411a02f6f2dd9d5245919385d69d81f0
Gitweb: https://git.kernel.org/tip/29060633411a02f6f2dd9d5245919385d69d81f0
Author: Binbin Wu <binbin.wu@linux.intel.com>
AuthorDate: Mon, 16 Oct 2023 14:24:46 +08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 16 Oct 2023 11:39:57 +02:00
selftests/x86/lam: Zero out buffer for readlink()
Zero out the buffer for readlink() since readlink() does not append a
terminating null byte to the buffer. Also change the buffer length
passed to readlink() to 'PATH_MAX - 1' to ensure the resulting string
is always null terminated.
Fixes: 833c12ce0f430 ("selftests/x86/lam: Add inherit test cases for linear-address masking")
Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Link: https://lore.kernel.org/r/20231016062446.695-1-binbin.wu@linux.intel.com
---
tools/testing/selftests/x86/lam.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c
index eb0e469..8f9b06d 100644
--- a/tools/testing/selftests/x86/lam.c
+++ b/tools/testing/selftests/x86/lam.c
@@ -573,7 +573,7 @@ int do_uring(unsigned long lam)
char path[PATH_MAX] = {0};
/* get current process path */
- if (readlink("/proc/self/exe", path, PATH_MAX) <= 0)
+ if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0)
return 1;
int file_fd = open(path, O_RDONLY);
@@ -680,14 +680,14 @@ static int handle_execve(struct testcases *test)
perror("Fork failed.");
ret = 1;
} else if (pid == 0) {
- char path[PATH_MAX];
+ char path[PATH_MAX] = {0};
/* Set LAM mode in parent process */
if (set_lam(lam) != 0)
return 1;
/* Get current binary's path and the binary was run by execve */
- if (readlink("/proc/self/exe", path, PATH_MAX) <= 0)
+ if (readlink("/proc/self/exe", path, PATH_MAX - 1) <= 0)
exit(-1);
/* run binary to get LAM mode and return to parent process */
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] selftests/x86/lam: Zero out buffer for readlink()
2023-10-16 8:47 ` kirill.shutemov
@ 2023-10-16 19:11 ` Shuah Khan
0 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2023-10-16 19:11 UTC (permalink / raw)
To: kirill.shutemov, Binbin Wu
Cc: dave.hansen, luto, peterz, shuah, linux-kselftest, x86,
linux-kernel, Shuah Khan
On 10/16/23 02:47, kirill.shutemov@linux.intel.com wrote:
> On Mon, Oct 16, 2023 at 02:24:46PM +0800, Binbin Wu wrote:
>> Zero out the buffer for readlink() since readlink() does not append a
>> terminating null byte to the buffer. Also change the buffer length
>> passed to readlink() to 'PATH_MAX - 1' to ensure the resulting string
>> is always null terminated.
>>
>> Fixes: 833c12ce0f430 ("selftests/x86/lam: Add inherit test cases for linear-address masking")
>>
>> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
>
> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>
Thank you. Applied to linux-kselftest next for Linux 6.7-rc1
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-16 19:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-16 6:24 [PATCH v2] selftests/x86/lam: Zero out buffer for readlink() Binbin Wu
2023-10-16 8:47 ` kirill.shutemov
2023-10-16 19:11 ` Shuah Khan
2023-10-16 9:44 ` [tip: x86/mm] " tip-bot2 for Binbin Wu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox