* [PATCH] selftests/exec: Avoid future NULL argv execve warning
@ 2022-02-01 0:08 Kees Cook
2022-02-02 15:13 ` Alexey Dobriyan
0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2022-02-01 0:08 UTC (permalink / raw)
To: Eric Biederman
Cc: Kees Cook, Alexey Dobriyan, Shuah Khan, linux-kselftest,
Ariadne Conill, Michael Kerrisk, Matthew Wilcox,
Christian Brauner, Rich Felker, Alexander Viro, linux-fsdevel,
linux-kernel, linux-hardening
Build actual argv for launching recursion test to avoid future warning
about using an empty argv in execve().
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
tools/testing/selftests/exec/recursion-depth.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/exec/recursion-depth.c b/tools/testing/selftests/exec/recursion-depth.c
index 2dbd5bc45b3e..35348db00c52 100644
--- a/tools/testing/selftests/exec/recursion-depth.c
+++ b/tools/testing/selftests/exec/recursion-depth.c
@@ -24,8 +24,14 @@
#include <sys/mount.h>
#include <unistd.h>
+#define FILENAME "/tmp/1"
+#define HASHBANG "#!" FILENAME "\n"
+
int main(void)
{
+ char * const argv[] = { FILENAME, NULL };
+ int rv;
+
if (unshare(CLONE_NEWNS) == -1) {
if (errno == ENOSYS || errno == EPERM) {
fprintf(stderr, "error: unshare, errno %d\n", errno);
@@ -44,21 +50,19 @@ int main(void)
return 1;
}
-#define FILENAME "/tmp/1"
int fd = creat(FILENAME, 0700);
if (fd == -1) {
fprintf(stderr, "error: creat, errno %d\n", errno);
return 1;
}
-#define S "#!" FILENAME "\n"
- if (write(fd, S, strlen(S)) != strlen(S)) {
+ if (write(fd, HASHBANG, strlen(HASHBANG)) != strlen(HASHBANG)) {
fprintf(stderr, "error: write, errno %d\n", errno);
return 1;
}
close(fd);
- int rv = execve(FILENAME, NULL, NULL);
+ rv = execve(FILENAME, argv, NULL);
if (rv == -1 && errno == ELOOP) {
return 0;
}
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/exec: Avoid future NULL argv execve warning
2022-02-01 0:08 [PATCH] selftests/exec: Avoid future NULL argv execve warning Kees Cook
@ 2022-02-02 15:13 ` Alexey Dobriyan
2022-02-02 17:38 ` Shuah Khan
0 siblings, 1 reply; 5+ messages in thread
From: Alexey Dobriyan @ 2022-02-02 15:13 UTC (permalink / raw)
To: Kees Cook
Cc: Eric Biederman, Shuah Khan, linux-kselftest, Ariadne Conill,
Michael Kerrisk, Matthew Wilcox, Christian Brauner, Rich Felker,
Alexander Viro, linux-fsdevel, linux-kernel, linux-hardening
On Mon, Jan 31, 2022 at 04:08:07PM -0800, Kees Cook wrote:
> Build actual argv for launching recursion test to avoid future warning
> about using an empty argv in execve().
> --- a/tools/testing/selftests/exec/recursion-depth.c
> +++ b/tools/testing/selftests/exec/recursion-depth.c
> @@ -24,8 +24,14 @@
> #include <sys/mount.h>
> #include <unistd.h>
>
> +#define FILENAME "/tmp/1"
> +#define HASHBANG "#!" FILENAME "\n"
> +
> int main(void)
> {
> + char * const argv[] = { FILENAME, NULL };
> + int rv;
Can we move out of -Wdeclaration-after-statement mentality in tests at least?
> - int rv = execve(FILENAME, NULL, NULL);
> + rv = execve(FILENAME, argv, NULL);
int rv = execve(FILENAME, (char*[]){FILENAME, NULL}, NULL);
is cleaner (and modern)!
> if (rv == -1 && errno == ELOOP) {
> return 0;
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/exec: Avoid future NULL argv execve warning
2022-02-02 15:13 ` Alexey Dobriyan
@ 2022-02-02 17:38 ` Shuah Khan
2022-02-02 21:00 ` Alexey Dobriyan
0 siblings, 1 reply; 5+ messages in thread
From: Shuah Khan @ 2022-02-02 17:38 UTC (permalink / raw)
To: Alexey Dobriyan, Kees Cook
Cc: Eric Biederman, Shuah Khan, linux-kselftest, Ariadne Conill,
Michael Kerrisk, Matthew Wilcox, Christian Brauner, Rich Felker,
Alexander Viro, linux-fsdevel, linux-kernel, linux-hardening,
Shuah Khan
On 2/2/22 8:13 AM, Alexey Dobriyan wrote:
> On Mon, Jan 31, 2022 at 04:08:07PM -0800, Kees Cook wrote:
>> Build actual argv for launching recursion test to avoid future warning
>> about using an empty argv in execve().
>
>> --- a/tools/testing/selftests/exec/recursion-depth.c
>> +++ b/tools/testing/selftests/exec/recursion-depth.c
>> @@ -24,8 +24,14 @@
>> #include <sys/mount.h>
>> #include <unistd.h>
>>
>> +#define FILENAME "/tmp/1"
>> +#define HASHBANG "#!" FILENAME "\n"
>> +
>> int main(void)
>> {
>> + char * const argv[] = { FILENAME, NULL };
>> + int rv;
>
> Can we move out of -Wdeclaration-after-statement mentality in tests at least?
selftest like the rest of the kernel follows the same coding guidelines.
It will follow the moving "-Wdeclaration-after-statement mentality" when
the rest of the kernel does.
Looks like this topic was discussed in the following:
https://patchwork.kernel.org/project/linux-kbuild/patch/c6fda26e8d134264b04fadc3386d6c32@gmail.com/
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/exec: Avoid future NULL argv execve warning
2022-02-02 17:38 ` Shuah Khan
@ 2022-02-02 21:00 ` Alexey Dobriyan
2022-02-04 16:11 ` Shuah Khan
0 siblings, 1 reply; 5+ messages in thread
From: Alexey Dobriyan @ 2022-02-02 21:00 UTC (permalink / raw)
To: Shuah Khan
Cc: Kees Cook, Eric Biederman, Shuah Khan, linux-kselftest,
Ariadne Conill, Michael Kerrisk, Matthew Wilcox,
Christian Brauner, Rich Felker, Alexander Viro, linux-fsdevel,
linux-kernel, linux-hardening
On Wed, Feb 02, 2022 at 10:38:57AM -0700, Shuah Khan wrote:
> On 2/2/22 8:13 AM, Alexey Dobriyan wrote:
> > On Mon, Jan 31, 2022 at 04:08:07PM -0800, Kees Cook wrote:
> > > Build actual argv for launching recursion test to avoid future warning
> > > about using an empty argv in execve().
> >
> > > --- a/tools/testing/selftests/exec/recursion-depth.c
> > > +++ b/tools/testing/selftests/exec/recursion-depth.c
> > > @@ -24,8 +24,14 @@
> > > #include <sys/mount.h>
> > > #include <unistd.h>
> > > +#define FILENAME "/tmp/1"
> > > +#define HASHBANG "#!" FILENAME "\n"
> > > +
> > > int main(void)
> > > {
> > > + char * const argv[] = { FILENAME, NULL };
> > > + int rv;
> >
> > Can we move out of -Wdeclaration-after-statement mentality in tests at least?
>
> selftest like the rest of the kernel follows the same coding guidelines.
> It will follow the moving "-Wdeclaration-after-statement mentality" when
> the rest of the kernel does.
>
> Looks like this topic was discussed in the following:
> https://patchwork.kernel.org/project/linux-kbuild/patch/c6fda26e8d134264b04fadc3386d6c32@gmail.com/
The only real argument is "gcc miscompiles /proc" to which adding -Wdeclaration-after-statement
looks like a too big hammer.
Why can't we have nice things?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/exec: Avoid future NULL argv execve warning
2022-02-02 21:00 ` Alexey Dobriyan
@ 2022-02-04 16:11 ` Shuah Khan
0 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2022-02-04 16:11 UTC (permalink / raw)
To: Alexey Dobriyan
Cc: Kees Cook, Eric Biederman, Shuah Khan, linux-kselftest,
Ariadne Conill, Michael Kerrisk, Matthew Wilcox,
Christian Brauner, Rich Felker, Alexander Viro, linux-fsdevel,
linux-kernel, linux-hardening, Shuah Khan
On 2/2/22 2:00 PM, Alexey Dobriyan wrote:
> On Wed, Feb 02, 2022 at 10:38:57AM -0700, Shuah Khan wrote:
>> On 2/2/22 8:13 AM, Alexey Dobriyan wrote:
>>> On Mon, Jan 31, 2022 at 04:08:07PM -0800, Kees Cook wrote:
>>>> Build actual argv for launching recursion test to avoid future warning
>>>> about using an empty argv in execve().
>>>
>>>> --- a/tools/testing/selftests/exec/recursion-depth.c
>>>> +++ b/tools/testing/selftests/exec/recursion-depth.c
>>>> @@ -24,8 +24,14 @@
>>>> #include <sys/mount.h>
>>>> #include <unistd.h>
>>>> +#define FILENAME "/tmp/1"
>>>> +#define HASHBANG "#!" FILENAME "\n"
>>>> +
>>>> int main(void)
>>>> {
>>>> + char * const argv[] = { FILENAME, NULL };
>>>> + int rv;
>>>
>>> Can we move out of -Wdeclaration-after-statement mentality in tests at least?
>>
>> selftest like the rest of the kernel follows the same coding guidelines.
>> It will follow the moving "-Wdeclaration-after-statement mentality" when
>> the rest of the kernel does.
>>
>> Looks like this topic was discussed in the following:
>> https://patchwork.kernel.org/project/linux-kbuild/patch/c6fda26e8d134264b04fadc3386d6c32@gmail.com/
>
> The only real argument is "gcc miscompiles /proc" to which adding -Wdeclaration-after-statement
> looks like a too big hammer.
>
Either way - selftest will stay in sync with the kernel coding standards
for good reasons. Doing its own thing confuses developers and makes it
hard for maintainers.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-02-04 16:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 0:08 [PATCH] selftests/exec: Avoid future NULL argv execve warning Kees Cook
2022-02-02 15:13 ` Alexey Dobriyan
2022-02-02 17:38 ` Shuah Khan
2022-02-02 21:00 ` Alexey Dobriyan
2022-02-04 16:11 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).