selftests: watchdog: Validate optional file argument
PATCH 1/2 selftests: watchdog: Validate optional file argument
From: "George G. Davis" <[email protected]>
As reported by Eugeniu Rosca, the newly added optional file argument does not validate if the file is indeed a watchdog, e.g.:
./watchdog-test -f /dev/zero
Watchdog Ticking Away!
Fix it by confirming that the WDIOC_GETSUPPORT ioctl succeeds.
---
v1: Applied/tested on commit ce54eab71e210f ("kunit: fix failure to build without printk") of
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=next
tools/testing/selftests/watchdog/watchdog-test.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/testing/selftests/watchdog/watchdog-test.c +11 -0
@@ -97,6 +97,7 @@ int main(int argc, char *argv[])int c;int oneshot =0 ;char *file ="/dev/watchdog" ; +struct watchdog_info info;setbuf (stdout,NULL );
@@ -118,6 +119,16 @@ int main(int argc, char *argv[])exit (-1 ); } +/* +* Validate that `file` is a watchdog device +*/ + ret =ioctl (fd,WDIOC_GETSUPPORT , &info); +if (ret) { +printf ("WDIOC_GETSUPPORT error '%s'\n" ,strerror (errno)); +close (fd); +exit (ret); + } + optind =0 ;while ((c =getopt_long (argc, argv, sopts, lopts,NULL )) !=-1 ) {
Signature · 1 line
2.23.0
PATCH 2/2 selftests: watchdog: Add command line option to show watchdog_info
From: "George G. Davis" <[email protected]>
A side of affect of commit "selftests: watchdog: Add optional file argument" is that arbitrary files may be opened for watchdog testing, e.g. /dev/null. To prevent watchdog-test from operating on non-watchdog device files, commit "selftests: watchdog: Validate optional file argument" was added to validate that a file is indeed a watchdog device via an ioctl(WDIOC_GETSUPPORT) call. Since the watchdog_info is available as a result of the ioctl(WDIOC_GETSUPPORT) call, add a command line option to show the watchdog_info.
---
v1: Applied/tested on commit ce54eab71e210f ("kunit: fix failure to build without printk") of
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=next
tools/testing/selftests/watchdog/watchdog-test.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
tools/testing/selftests/watchdog/watchdog-test.c +15 -1
@@ -19,7 +19,7 @@int fd;const char v ='V' ; -static const char sopts[] ="bdehp:t:Tn:NLf:" ; +static const char sopts[] ="bdehp:t:Tn:NLf:i" ;static const struct option lopts[] = { {"bootstatus" , no_argument,NULL ,'b' }, {"disable" , no_argument,NULL ,'d' },
@@ -32,6 +32,7 @@ static const struct option lopts[] = { {"getpretimeout", no_argument, NULL, 'N'}, {"gettimeleft", no_argument, NULL, 'L'}, {"file", required_argument, NULL, 'f'}, + {"info", no_argument, NULL, 'i'}, {NULL, no_argument, NULL, 0x0} };
@@ -72,6 +73,7 @@ static void usage(char *progname)printf ("Usage: %s [options]\n" , progname);printf (" -f, --file\t\tOpen watchdog device file\n" );printf ("\t\t\tDefault is /dev/watchdog\n" ); +printf (" -i, --info\t\tShow watchdog_info\n" );printf (" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n" );printf (" -d, --disable\t\tTurn off the watchdog timer\n" );printf (" -e, --enable\t\tTurn on the watchdog timer\n" );
@@ -216,6 +218,18 @@ int main(int argc, char *argv[])case 'f' :/* Handled above */ break ; +case 'i' : +/* +* watchdog_info was obtained as part of file open +* validation. So we just show it here. +*/ + oneshot =1 ; +printf ("watchdog_info:\n" ); +printf (" identity:\t\t%s\n" , info.identity); +printf (" firmware_version:\t%u\n" , + info.firmware_version); +printf (" options:\t\t%08x\n" , info.options); +break ;default :usage (argv[0 ]);
Signature · 1 line
2.23.0
shuah
maintainerRe: [PATCH 2/2] selftests: watchdog: Add command line option to show watchdog_info
Quoted 60 lines · Eugeniu Rosca
From: "George G. Davis" <[email protected]>
A side of affect of commit "selftests: watchdog: Add optional file argument" is that arbitrary files may be opened for watchdog testing, e.g.
/dev/null. To prevent watchdog-test from operating on non-watchdog device files, commit "selftests: watchdog: Validate optional file argument" was added to validate that a file is indeed a watchdog device via anioctl(WDIOC_GETSUPPORT)call. Since thewatchdog_infois available as a result of theioctl(WDIOC_GETSUPPORT)call, add a command line option to show thewatchdog_info.Suggested-by Eugeniu Rosca <[email protected]>Signed-off-by George G. Davis <[email protected]>Signed-off-by Eugeniu Rosca <[email protected]>---
v1: Applied/tested on commitce54eab71e210f("kunit: fix failure to build without printk") of
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=nexttools/testing/selftests/watchdog/watchdog-test.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)tools/testing/selftests/watchdog/watchdog-test.c +8
-1@@ -19,7 +19,7 @@int fd;const char v ='V' ; -static const char sopts[] ="bdehp:t:Tn:NLf:" ; +static const char sopts[] ="bdehp:t:Tn:NLf:i" ;static const struct option lopts[] = { {"bootstatus" , no_argument,NULL ,'b' }, {"disable" , no_argument,NULL ,'d' },@@ -32,6 +32,7 @@ static const struct option lopts[] = { {"getpretimeout", no_argument, NULL, 'N'}, {"gettimeleft", no_argument, NULL, 'L'}, {"file", required_argument, NULL, 'f'}, + {"info", no_argument, NULL, 'i'}, {NULL, no_argument, NULL, 0x0} };@@ -72,6 +73,7 @@ static void usage(char *progname)printf ("Usage: %s [options]\n" , progname);printf (" -f, --file\t\tOpen watchdog device file\n" );printf ("\t\t\tDefault is /dev/watchdog\n" ); +printf (" -i, --info\t\tShow watchdog_info\n" );printf (" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n" );printf (" -d, --disable\t\tTurn off the watchdog timer\n" );printf (" -e, --enable\t\tTurn on the watchdog timer\n" );@@ -216,6 +218,18 @@ int main(int argc, char *argv[])case 'f' :/* Handled above */ break ; +case 'i' : +/* +* watchdog_info was obtained as part of file open +* validation. So we just show it here. +*/
tools/testing/selftests/watchdog/watchdog-test.c int main(int argc, char *argv[]) · line 235
Quoted 10 lines
tools/testing/selftests/watchdog/watchdog-test.c +7
-0+ oneshot =1 ; +printf ("watchdog_info:\n" ); +printf (" identity:\t\t%s\n" , info.identity); +printf (" firmware_version:\t%u\n" , + info.firmware_version); +printf (" options:\t\t%08x\n" , info.options); +break ;default :usage (argv[0 ]);
I would like to see these combined. Please don't add another argument. Combine patch and 1&2.
thanks,
-- Shuah
Re: [PATCH 2/2] selftests: watchdog: Add command line option to show watchdog_info
Hello,
Quoted 41 lines · shuah
Quoted 40 lines · Eugeniu Rosca
tools/testing/selftests/watchdog/watchdog-test.c +12
-1@@ -19,7 +19,7 @@int fd;const char v ='V' ; -static const char sopts[] ="bdehp:t:Tn:NLf:" ; +static const char sopts[] ="bdehp:t:Tn:NLf:i" ;static const struct option lopts[] = { {"bootstatus" , no_argument,NULL ,'b' }, {"disable" , no_argument,NULL ,'d' },@@ -32,6 +32,7 @@ static const struct option lopts[] = { {"getpretimeout", no_argument, NULL, 'N'}, {"gettimeleft", no_argument, NULL, 'L'}, {"file", required_argument, NULL, 'f'}, + {"info", no_argument, NULL, 'i'}, {NULL, no_argument, NULL, 0x0} };@@ -72,6 +73,7 @@ static void usage(char *progname)printf ("Usage: %s [options]\n" , progname);printf (" -f, --file\t\tOpen watchdog device file\n" );printf ("\t\t\tDefault is /dev/watchdog\n" ); +printf (" -i, --info\t\tShow watchdog_info\n" );printf (" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n" );printf (" -d, --disable\t\tTurn off the watchdog timer\n" );printf (" -e, --enable\t\tTurn on the watchdog timer\n" );@@ -216,6 +218,18 @@ int main(int argc, char *argv[])case 'f' :/* Handled above */ break ; +case 'i' : +/* +* watchdog_info was obtained as part of file open +* validation. So we just show it here. +*/ + oneshot =1 ; +printf ("watchdog_info:\n" ); +printf (" identity:\t\t%s\n" , info.identity); + printf(" firmware_version:\t%u\n",
Quoted 8 lines
tools/testing/selftests/watchdog/watchdog-test.c int main(int argc, char *argv[])
Quoted 6 lines
tools/testing/selftests/watchdog/watchdog-test.c +3
-0+ info.firmware_version); +printf (" options:\t\t%08x\n" , info.options); +break ;default :usage (argv[0 ]);I would like to see these combined.
Ok.
Quoted 1 line
Please don't add another argument.
I'm not clear on your request here. Do you want to drop the addition of optional --info|-i command line option and always display the watchdog_info?
If yes, perhaps Eugeniu may mention what he has already mentioned to me earlier that "it's very useful to see the watchdog identity" but "some users might perceive the console output a bit busy if the Watchdog identity: <WDT name> message is always on" so perhaps it is "more user-friendly to still call the WDIOC_GETSUPPORT ioctl to sanitize the device file, but to only print the Watchdog identity: message when the user passes e.g. a new -i, --identity parameter".
Quoted 1 line
Combine patch and 1&2.
I'll do that but I'm not entirely clear on your "Please don't add another argument" request.
Quoted 3 lines
thanks,
-- Shuah
Signature · 2 lines
Regards, George
Re: [PATCH 2/2] selftests: watchdog: Add command line option to show watchdog_info
In reply to shuahHi Shuah,
CC George
On Mon, Sep 16, 2019 at 07:26:41AM -0600, shuah wrote:
[..]
Quoted 13 lines
Quoted 13 lines
case 'f':
/* Handled above */
break;tools/testing/selftests/watchdog/watchdog-test.c +10
-0+case 'i' : +/* +* watchdog_info was obtained as part of file open +* validation. So we just show it here. +*/ + oneshot =1 ; +printf ("watchdog_info:\n" ); +printf (" identity:\t\t%s\n" , info.identity); +printf (" firmware_version:\t%u\n" , + info.firmware_version);
Quoted 8 lines
tools/testing/selftests/watchdog/watchdog-test.c int main(int argc, char *argv[]) · line 235
Quoted 5 lines
tools/testing/selftests/watchdog/watchdog-test.c +2
-0+printf (" options:\t\t%08x\n" , info.options); +break ;default :usage (argv[0 ]);I would like to see these combined. Please don't add another argument. Combine patch and 1&2.
With all my appreciation for your comment, why do you think it is better to get rid of the new argument? I don't think it is user-friendly to always report the watchdog_info to the user. Just look at outputs [1-2] and imagine that the watchdog_info part would pop up unconditionally. It looks too busy to me.
[1] watchdog-test -b -i
Last boot is caused by: Power-On-Reset.watchdog_info:
identity: Renesas WDT Watchdog firmware_version: 0 options: 000081a0
[2] watchdog-test -i --helpwatchdog_info:
identity: Renesas WDT Watchdog
firmware_version: 0
options: 000081a0
Usage: ./watchdog-test [options]
-f, --file Open watchdog device file
Default is /dev/watchdog
-i, --info Show watchdog_info
-b, --bootstatus Get last boot status (Watchdog/POR)
-d, --disable Turn off the watchdog timer
-e, --enable Turn on the watchdog timer
-h, --help Print the help message
-p, --pingrate=P Set ping rate to P seconds (default 1)
-t, --timeout=T Set timeout to T seconds
-T, --gettimeout Get the timeout
-n, --pretimeout=T Set the pretimeout to T seconds
-N, --getpretimeout Get the pretimeout
-L, --gettimeleft Get the time left until timer expiresParameters are parsed left-to-right in real-time.
Example: ./watchdog-test -d -t 10 -p 5 -e
Example: ./watchdog-test -t 12 -T -n 7 -N
Signature · 2 lines
Best Regards, Eugeniu.
shuah
maintainerRe: [PATCH 2/2] selftests: watchdog: Add command line option to show watchdog_info
Quoted 27 lines · Eugeniu Rosca
Hi Shuah,
CC GeorgeOn Mon, Sep 16, 2019 at 07:26:41AM -0600, shuah wrote:
[..]Quoted 13 lines
Quoted 13 lines
case 'f': /* Handled above */ break;tools/testing/selftests/watchdog/watchdog-test.c +10
-0+case 'i' : +/* +* watchdog_info was obtained as part of file open +* validation. So we just show it here. +*/ + oneshot =1 ; +printf ("watchdog_info:\n" ); +printf (" identity:\t\t%s\n" , info.identity); +printf (" firmware_version:\t%u\n" , + info.firmware_version);Quoted 8 lines
tools/testing/selftests/watchdog/watchdog-test.c int main(int argc, char *argv[]) · line 235
Quoted 5 lines
tools/testing/selftests/watchdog/watchdog-test.c +2
-0+printf (" options:\t\t%08x\n" , info.options); +break ;default :usage (argv[0 ]);I would like to see these combined. Please don't add another argument. Combine patch and 1&2.
Quoted 5 lines
With all my appreciation for your comment, why do you think it is better to get rid of the new argument? I don't think it is user-friendly to always report the
watchdog_infoto the user. Just look at outputs [1-2] and imagine that thewatchdog_infopart would pop up unconditionally. It looks too busy to me.
Yes it does look busy. I am okay with adding a second options based on what you both said.
I don't like the commit log.
Unfortunately this thread no longer contains the commit log.
I would like to see the commit log without any references to side effects. It make it rather confusing.
"A side of affect of commit "selftests: watchdog: Add optional file argument" is that arbitrary files may be opened for watchdog testing, e.g. /dev/null. To prevent watchdog-test from operating on non-watchdog device files, commit "selftests: watchdog: Validate optional file argument" was added to validate that a file is indeed a watchdog device via an ioctl(WDIOC_GETSUPPORT) call. Since the watchdog_info is available as a result of the ioctl(WDIOC_GETSUPPORT) call, add a command line option to show the watchdog_info."
I would drop all references to that.
thanks,
-- Shuah
Re: [PATCH 2/2] selftests: watchdog: Add command line option to show watchdog_info
Hello Shuah,
Quoted 34 lines · shuah
Quoted 27 lines · Eugeniu Rosca
Hi Shuah,
CC GeorgeOn Mon, Sep 16, 2019 at 07:26:41AM -0600, shuah wrote:
[..]Quoted 13 lines
Quoted 13 lines
case 'f':
/* Handled above */
break;tools/testing/selftests/watchdog/watchdog-test.c +10
-0+case 'i' : +/* +* watchdog_info was obtained as part of file open +* validation. So we just show it here. +*/ + oneshot =1 ; +printf ("watchdog_info:\n" ); +printf (" identity:\t\t%s\n" , info.identity); +printf (" firmware_version:\t%u\n" , + info.firmware_version);Quoted 8 lines
tools/testing/selftests/watchdog/watchdog-test.c int main(int argc, char *argv[]) · line 235
Quoted 5 lines
tools/testing/selftests/watchdog/watchdog-test.c +2
-0+printf (" options:\t\t%08x\n" , info.options); +break ;default :usage (argv[0 ]);I would like to see these combined. Please don't add another argument. Combine patch and 1&2.
Quoted 5 lines
With all my appreciation for your comment, why do you think it is better to get rid of the new argument? I don't think it is user-friendly to always report the
watchdog_infoto the user. Just look at outputs [1-2] and imagine that thewatchdog_infopart would pop up unconditionally. It looks too busy to me.
Quoted 4 lines
Yes it does look busy. I am okay with adding a second options based on what you both said.
I don't like the commit log.
Agreed, I didn't like it either - it was rather a draft.
Quoted 15 lines
Unfortunately this thread no longer contains the commit log.
I would like to see the commit log without any references to side effects. It make it rather confusing.
"A side of affect of commit "selftests: watchdog: Add optional file argument" is that arbitrary files may be opened for watchdog testing, e.g.
/dev/null. To prevent watchdog-test from operating on non-watchdog device files, commit "selftests: watchdog: Validate optional file argument" was added to validate that a file is indeed a watchdog device via anioctl(WDIOC_GETSUPPORT)call. Since thewatchdog_infois available as a result of theioctl(WDIOC_GETSUPPORT)call, add a command line option to show thewatchdog_info."
Quoted 1 line
I would drop all references to that.
How about the following commit message for the squash commit for [1] and [2]?:
"
selftests: watchdog: Validate optional file argument
As reported by Eugeniu Rosca, a side of affect of commit c3f2490d6e92 ("selftests: watchdog: Add optional file argument") is that arbitrary files may be opened for watchdog testing, e.g.
./watchdog-test -f /dev/zero
Watchdog Ticking Away!
To prevent watchdog-test from operating on non-watchdog device files, validate that a file is indeed a watchdog device via an ioctl(WDIOC_GETSUPPORT) call.
While we're at it, since the watchdog_info is available as a result of the ioctl(WDIOC_GETSUPPORT) call, add a command line option to optionally show the watchdog_info.
"
Thanks!
Quoted 3 lines
thanks,
-- Shuah
Signature · 2 lines
Regards, George
Re: [PATCH 2/2] selftests: watchdog: Add command line option to show watchdog_info
(For LKML readability) Superseded by:
- https://patchwork.kernel.org/patch/11149289/
("[v3,2/2] selftests: watchdog: Add command line option to show watchdog_info")
Signature · 2 lines
Best Regards, Eugeniu.
Hi Shuah,
Quoted 8 lines · Eugeniu Rosca
From: "George G. Davis" <[email protected]>
As reported by Eugeniu Rosca, the newly added optional file argument does not validate if the file is indeed a watchdog, e.g.:
./watchdog-test -f
/dev/zero
Watchdog Ticking Away!
Quoted 8 lines
Fix it by confirming that the
WDIOC_GETSUPPORTioctl succeeds.Reported-by Eugeniu Rosca <[email protected]>Signed-off-by George G. Davis <[email protected]>Signed-off-by Eugeniu Rosca <[email protected]>---
v1: Applied/tested on commitce54eab71e210f("kunit: fix failure to build without printk") of
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=next
Any concerns about the two patches?
Can you please confirm they are in your queue?
Signature · 2 lines
Best Regards, Eugeniu.
shuah
maintainerQuoted 13 lines · Eugeniu Rosca
Hi Shuah,
Quoted 10 lines · Eugeniu Rosca
From: "George G. Davis" <[email protected]>
As reported by Eugeniu Rosca, the newly added optional file argument does not validate if the file is indeed a watchdog, e.g.:
./watchdog-test -f
/dev/zero
Watchdog Ticking Away!Fix it by confirming that the
WDIOC_GETSUPPORTioctl succeeds.
Quoted 8 lines
Quoted 6 lines
Reported-by Eugeniu Rosca <[email protected]>Signed-off-by George G. Davis <[email protected]>Signed-off-by Eugeniu Rosca <[email protected]>---
v1: Applied/tested on commitce54eab71e210f("kunit: fix failure to build without printk") of
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=nextAny concerns about the two patches?
I responded to the patches as well.
Quoted 2 lines
Can you please confirm they are in your queue?
I just sent response. Please collapse the two patches. They will go in for 5.4-rc1 second update.
thanks,
-- Shuah
(For LKML readability) Superseded by:
- https://patchwork.kernel.org/patch/11149287/
("[v3,1/2] selftests: watchdog: Validate optional file argument")
Signature · 2 lines
Best Regards, Eugeniu.
shuah
maintainerQuoted 40 lines · Eugeniu Rosca
From: "George G. Davis" <[email protected]>
As reported by Eugeniu Rosca, the newly added optional file argument does not validate if the file is indeed a watchdog, e.g.:
./watchdog-test -f
/dev/zero
Watchdog Ticking Away!Fix it by confirming that the
WDIOC_GETSUPPORTioctl succeeds.Reported-by Eugeniu Rosca <[email protected]>Signed-off-by George G. Davis <[email protected]>Signed-off-by Eugeniu Rosca <[email protected]>---
v1: Applied/tested on commitce54eab71e210f("kunit: fix failure to build without printk") of
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=nexttools/testing/selftests/watchdog/watchdog-test.c | 11 +++++++++++ 1 file changed, 11 insertions(+)tools/testing/selftests/watchdog/watchdog-test.c +4
-0@@ -97,6 +97,7 @@ int main(int argc, char *argv[])int c;int oneshot =0 ;char *file ="/dev/watchdog" ; +struct watchdog_info info;setbuf (stdout,NULL );@@ -118,6 +119,16 @@ int main(int argc, char *argv[])exit (-1 ); } +/* +* Validate that `file` is a watchdog device +*/
tools/testing/selftests/watchdog/watchdog-test.c int main(int argc, char *argv[]) · line 134
Quoted 10 lines
tools/testing/selftests/watchdog/watchdog-test.c +7
-0+ ret =ioctl (fd,WDIOC_GETSUPPORT , &info); +if (ret) { +printf ("WDIOC_GETSUPPORT error '%s'\n" ,strerror (errno)); +close (fd); +exit (ret); + } + optind =0 ;while ((c =getopt_long (argc, argv, sopts, lopts,NULL )) !=-1 ) {
Thanks for catching this. I will pull this in for second update for 5.4-rc1.
thanks,
-- Shuah