pps: require CAP_SYS_TIME to attach N_PPS ldisc
PATCH 1/1 pps: require CAP_SYS_TIME to attach N_PPS ldisc
Any unprivileged user can attach the N_PPS ldisc to a pty, and every attach registers a PPS source. At most PPS_MAX_SOURCES (256) sources can exist, so such a user can take all of them, after which registering a real PPS source fails with -EBUSY.
Require CAP_SYS_TIME to attach N_PPS, the capability that PPS_SETPARAMS already needs to configure a source.
--- drivers/pps/clients/pps-ldisc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pps/clients/pps-ldisc.c +3 -0
@@ -46,6 +46,9 @@ static int pps_tty_open(struct tty_struct *tty)struct pps_device *pps;int ret; +if (!capable (CAP_SYS_TIME )) +return -EPERM ; + info.owner =THIS_MODULE ; info.dev =NULL ;snprintf (info.name,PPS_MAX_NAME_LEN ,"%s%d" , drv->driver_name, index);
--
2.43.0
Rodolfo Giometti
maintainerQuoted 10 lines · Hungyu Lin
Any unprivileged user can attach the
N_PPSldisc to a pty, and every attach registers a PPS source. At mostPPS_MAX_SOURCES(256) sources can exist, so such a user can take all of them, after which registering a real PPS source fails with-EBUSY.Require
CAP_SYS_TIMEto attachN_PPS, the capability thatPPS_SETPARAMSalready needs to configure a source.Fixes a0880df0ccde ("pps: serial clients support")
Are you sure this is stable material? It changes what a user without CAP_SYS_TIME can do, also on kernels already in the field.
Quoted 10 lines
Signed-off-by Hungyu Lin <[email protected]>--- drivers/pps/clients/pps-ldisc.c | 3 +++ 1 file changed, 3 insertions(+)drivers/pps/clients/pps-ldisc.c +0
-0
drivers/pps/clients/pps-ldisc.c static int pps_tty_open(struct tty_struct *tty) · line 51
Quoted 6 lines
drivers/pps/clients/pps-ldisc.c +3
-0@@ -46,6 +46,9 @@ static int pps_tty_open(struct tty_struct *tty)struct pps_device *pps;int ret; +if (!capable (CAP_SYS_TIME )) +return -EPERM ; +
Did you check whether this breaks existing setups? Today whoever can open the serial port can attach N_PPS (e.g. ldattach run by a user in the dialout group), and with this change they get -EPERM.
Also, is pps_tty_open() called only from TIOCSETD? If it can also be called when the tty is reopened after a hangup (tty_reopen()?), the check would be done against whoever reopens the tty, not against whoever attached N_PPS. Did you consider that case?
As you say, the cheap way to take all the sources is a pty. But can N_PPS on a pty ever report a pulse? If pps_tty_dcd_change() is never called there, wouldn't refusing N_PPS on a pty be enough, leaving the real serial ports as they are today?
Quoted 5 lines
drivers/pps/clients/pps-ldisc.c +0
-1info.owner =THIS_MODULE ; info.dev =NULL ;snprintf (info.name,PPS_MAX_NAME_LEN ,"%s%d" , drv->driver_name, index); --2.43.0
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming
Quoted 1 line
Are you sure this is stable material?
I added the stable tag because an unprivileged user can exhaust the global source pool. I'll reassess it with the narrower fix.
Quoted 1 line
Did you check whether this breaks existing setups?
The check would reject that setup. The default capture settings can be used without PPS_SETPARAMS, so that comparison was insufficient.
Quoted 1 line
Also, is
pps_tty_open()called only from TIOCSETD?
No. Reopening an existing tty after hangup can reach it through tty_ldisc_reinit(). The check would use the reopener's credentials and could make open() fail with -EPERM.
Quoted 3 lines
If
pps_tty_dcd_change()is never
called there, wouldn't refusingN_PPSon a pty be enough, leaving the real serial ports as they are today?
PTYs don't call dcd_change. Rejecting N_PPS on PTYs would block this path and leave serial ports as they are.
Thanks,
Hungyu