diff mbox series

[1/2] selftests: watchdog: Validate optional file argument

Message ID 20190907085833.21167-1-erosca@de.adit-jv.com (mailing list archive)
State Mainlined
Commit 8f9577eda5b74de4bd8b186c67f20736bdea6e07
Headers show
Series [1/2] selftests: watchdog: Validate optional file argument | expand

Commit Message

Eugeniu Rosca Sept. 7, 2019, 8:58 a.m. UTC
From: "George G. Davis" <george_davis@mentor.com>

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.

Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: George G. Davis <george_davis@mentor.com>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
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(+)

Comments

Eugeniu Rosca Sept. 16, 2019, 12:08 p.m. UTC | #1
Hi Shuah,

On Sat, Sep 07, 2019 at 10:58:32AM +0200, Eugeniu Rosca wrote:
> From: "George G. Davis" <george_davis@mentor.com>
> 
> 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.
> 
> Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> Signed-off-by: George G. Davis <george_davis@mentor.com>
> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> ---
> 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

Any concerns about the two patches?
Can you please confirm they are in your queue?
shuah Sept. 16, 2019, 1:25 p.m. UTC | #2
On 9/7/19 2:58 AM, Eugeniu Rosca wrote:
> From: "George G. Davis" <george_davis@mentor.com>
> 
> 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.
> 
> Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> Signed-off-by: George G. Davis <george_davis@mentor.com>
> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> ---
> 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(+)
> 
> diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
> index afff120c7be6..6ed822dc2222 100644
> --- a/tools/testing/selftests/watchdog/watchdog-test.c
> +++ b/tools/testing/selftests/watchdog/watchdog-test.c
> @@ -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) {
> 

Thanks for catching this. I will pull this in for second update for
5.4-rc1.

thanks,
-- Shuah
shuah Sept. 16, 2019, 1:29 p.m. UTC | #3
On 9/16/19 6:08 AM, Eugeniu Rosca wrote:
> Hi Shuah,
> 
> On Sat, Sep 07, 2019 at 10:58:32AM +0200, Eugeniu Rosca wrote:
>> From: "George G. Davis" <george_davis@mentor.com>
>>
>> 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.
>>
>> Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
>> Signed-off-by: George G. Davis <george_davis@mentor.com>
>> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
>> ---
>> 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
> 
> Any concerns about the two patches?
I responded to the patches as well.

> 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
Eugeniu Rosca Sept. 17, 2019, 6:55 p.m. UTC | #4
(For LKML readability) Superseded by:
 - https://patchwork.kernel.org/patch/11149287/
   ("[v3,1/2] selftests: watchdog: Validate optional file argument")
diff mbox series

Patch

diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index afff120c7be6..6ed822dc2222 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -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) {