watchdog: Device must be opened for writing
PATCH 1/1 watchdog: Device must be opened for writing
If userspace opens the watchdog device self-feeding stops. Sometimes opening the device happens by accident, e.g. by mistakenly running grep recursively in a wrong directory which leads to the server being reset.
Watchdog device does not handle read operation therefore the issue can be prevented by requiring the device to be opened for writing:
- Prevent opening the device without FMODE_WRITE
--- drivers/watchdog/watchdog_dev.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/watchdog/watchdog_dev.c +4 -0
@@ -835,6 +835,10 @@ static int watchdog_open(struct inode *inode, struct file *file)bool hw_running;int err; +/* Must be open for writing */ +if (!(file->f_mode &FMODE_WRITE )) +return -EINVAL ; +/* Get the corresponding watchdog device */ if (imajor (inode) ==MISC_MAJOR ) wd_data = old_wd_data;
base-commit: cf813c67d9619fd474c785698cbed543b94209dd
Signature · 1 line
2.25.1
Guenter Roeck
maintainerQuoted 10 lines · Stanislav German-Evtushenko
If userspace opens the watchdog device self-feeding stops. Sometimes opening the device happens by accident, e.g. by mistakenly running grep recursively in a wrong directory which leads to the server being reset.
Watchdog device does not handle read operation therefore the issue can be prevented by requiring the device to be opened for writing:
- Prevent opening the device without
FMODE_WRITESigned-off-by Stanislav German-Evtushenko <[email protected]>
NACK. That would be a major undocumented ABI change. Opening /dev/watchdog for reading can be and is used today to test a watchdog.
Guenter
Quoted 24 lines
--- drivers/watchdog/watchdog_dev.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/watchdog/watchdog_dev.c +4
-0@@ -835,6 +835,10 @@ static int watchdog_open(struct inode *inode, struct file *file)bool hw_running;int err; +/* Must be open for writing */ +if (!(file->f_mode &FMODE_WRITE )) +return -EINVAL ; +/* Get the corresponding watchdog device */ if (imajor (inode) ==MISC_MAJOR ) wd_data = old_wd_data;base-commit:
cf813c67d9619fd474c785698cbed543b94209ddSignature · 1 line
2.25.1
A message that is not in the archive (sent off-list or not yet received): CAPeRZrV+HwdmBKFB3tmG_tEHjsR8h3WLxKQYGDLOLgw178oq=A@mail.gmail.com
Guenter Roeck
maintainerQuoted 16 lines · Stanislav German-Evtushenko
Quoted 15 lines · On Saturday, August 14, 2021, Guenter Roeck <[email protected]…
Quoted 10 lines · Stanislav German-Evtushenko
If userspace opens the watchdog device self-feeding stops. Sometimes opening the device happens by accident, e.g. by mistakenly running grep recursively in a wrong directory which leads to the server being reset.
Watchdog device does not handle read operation therefore the issue can be prevented by requiring the device to be opened for writing:
- Prevent opening the device without
FMODE_WRITESigned-off-by Stanislav German-Evtushenko <[email protected] <mailto:[email protected]>>NACK. That would be a major undocumented ABI change. Opening
/dev/watchdogfor reading can be and is used today to test a watchdog.
Quoted 7 lines
Quoted 2 lines
Guenter
I see. This is unfortunate.
In this case I'll try to find the right place in the documentation and make it more explicit unless it is already there and I've overlooked.
No. That isn't the point. This is used and must not be changed. Again, people (including me( are _using_ this to test watchdogs. We are not going to disable that because some people are not careful when executing commands as root.
Guenter
Quoted 32 lines · Guenter Roeck
Quoted 23 lines · Stanislav German-Evtushenko
Quoted 1 line · On Saturday, August 14, 2021, Guenter Roeck <[email protected]…
On Sun, Aug 15, 2021 at 04:13:45AM +0900, Stanislav German-Evtushenko
Quoted 2 lines · wrote:
Quoted 2 lines
If userspace opens the watchdog device self-feeding stops. Sometimes opening the device happens by accident, e.g. by mistakenly running
grep
Quoted 1 line
Quoted 1 line
recursively in a wrong directory which leads to the server being
reset.
Quoted 2 lines
Quoted 2 lines
Watchdog device does not handle read operation therefore the issue can
be
Quoted 5 lines
Quoted 5 lines
prevented by requiring the device to be opened for writing:
- Prevent opening the device without
FMODE_WRITESigned-off-by Stanislav German-Evtushenko <[email protected]<mailto:[email protected]>>
Quoted 2 lines
NACK. That would be a major undocumented ABI change. Opening
/dev/watchdogQuoted 2 lines
for reading can be and is used today to test a watchdog.
Quoted 8 lines
Quoted 2 lines
Guenter
I see. This is unfortunate.
In this case I'll try to find the right place in the documentation and make it more explicit unless it is already there and I've overlooked.
Quoted 7 lines
No. That isn't the point. This is used and must not be changed. Again, people (including me( are _using_ this to test watchdogs. We are not going to disable that because some people are not careful when executing commands as root.
Guenter
I mean I would describe the existing behavior as this is not obvious.
As for testing, opening for writing is not harder than for reading but I understand that it would be a breaking change now.