Bug#583435: rpcbind: Insecure handling of state files
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 41 lines · Guillem Jover
Hi!
Quoted 10 lines · Guillem Jover
Package: rpcbind
Version: 0.2.0-4
Severity: serious
Tags: securityThe rpcbind daemon, which runs as root, uses
/tmp/portmap.xdrand/tmp/rpcbind.xdrfor doing warm starts as what seems to be a way to preserve state between invokations. It parses (through libtirpc) and removes them on start. It creates them before exiting.Quoted 4 lines
So first off, *any* user can craft those two files before the daemon has started for the first time, which the daemon will parse. This might be ok, depending on the checks done on parse, I'd still be very wary of letting a user be able to craft such files at will.
It seems to be doing no checks whatsoever. A simple test I performed at the time of filing this report, but didn't seem to have any obvious consequence, shows this which I noticed later on:
,---
gaara:~# /etc/init.d/rpcbind start Starting rpcbind daemon.... gaara:~# ps axuOp|egrep '(^USER|[r]pcbind)' USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 23424 0.0 0.0 18768 704 ? Ss 13:53 0:00 /sbin/rpcbind -w gaara:~# /etc/init.d/rpcbind stop Stopping rpcbind daemon.... gaara:~# dd if=/dev/urandom of=/tmp/rpcbind.xdr bs=1024 count=1 1+0 records in 1+0 records out 1024 bytes (1,0 kB) copied, 0,000861307 s, 1,2 MB/s gaara:~# /etc/init.d/rpcbind start Starting rpcbind daemon.... gaara:~# ps axuOp|egrep '(^USER|[r]pcbind)' USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 23440 0.0 0.0 4008972 772 ? Ss 13:54 0:00 /sbin/rpcbind -w `---
Quoted 7 lines
The first start is a normal clean invokation, the second one is using the crafted file. See how it has allocated almost 4 GiB. Disregard though, me running all this as root, a user would be able to craft those files as long as they were not already in /tmp.
thanks,
guillem
I'm sending this bug report to the linux-nfs mailing list.
The original bug report is at http://bugs.debian.org/583435
Thank you.
A message that is not in the archive (sent off-list or not yet received): 20100602112520.GA22639-q3oZDYqQg6zyUObV3Cmqeti2O/[email protected]
Quoted 4 lines · An=EDbal Monsalve Salazar
Quoted 3 lines · Guillem Jover
Hi!
On Thu, 2010-05-27 at 19:09:08 +0200, Guillem Jover wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Package: rpcbind
Version: 0.2.0-4
Severity: serious
Tags: securityThe rpcbind daemon, which runs as root, uses
/tmp/portmap.xdrand/tmp/rpcbind.xdrfor doing warm starts as what seems to be a way to preserve state between invokations. It parses (through libtirpc) an=
d
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
removes them on start. It creates them before exiting.
So first off, *any* user can craft those two files before the daemo=
n
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
has started for the first time, which the daemon will parse. This might be ok, depending on the checks done on parse, I'd still be ve=
ry
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
wary of letting a user be able to craft such files at will.
It seems to be doing no checks whatsoever. A simple test I performed=
at
Quoted 8 lines
Quoted 8 lines
the time of filing this report, but didn't seem to have any obvious consequence, shows this which I noticed later on:
,---
gaara:~# /etc/init.d/rpcbind start Starting rpcbind daemon.... gaara:~# ps axuOp|egrep '(^USER|[r]pcbind)' USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COM=
MAND
Quoted 1 line
Quoted 1 line
root 23424 0.0 0.0 18768 704 ? Ss 13:53 0:00 /sb=
in/rpcbind -w
Quoted 3 lines
Quoted 3 lines
gaara:~# /etc/init.d/rpcbind stop Stopping rpcbind daemon.... gaara:~# dd if=3D/dev/urandom of=3D/tmp/rpcbind.xdr bs=3D1024 count=3D=
1
Quoted 7 lines
Quoted 7 lines
1+0 records in
1+0 records out
1024 bytes (1,0 kB) copied, 0,000861307 s, 1,2 MB/sgaara:~# /etc/init.d/rpcbind start Starting rpcbind daemon.... gaara:~# ps axuOp|egrep '(^USER|[r]pcbind)' USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COM=
MAND
Quoted 1 line
Quoted 1 line
root 23440 0.0 0.0 4008972 772 ? Ss 13:54 0:00 /sb=
in/rpcbind -w
Quoted 3 lines
Quoted 3 lines
`---
The first start is a normal clean invokation, the second one is usin=
g
Quoted 1 line
Quoted 1 line
the crafted file. See how it has allocated almost 4 GiB. Disregard t=
hough,
Quoted 1 line
Quoted 1 line
me running all this as root, a user would be able to craft those fil=
es as
Quoted 8 lines
Quoted 4 lines
long as they were not already in /tmp.
thanks,
guillemI'm sending this bug report to the linux-nfs mailing list.
The original bug report is at http://bugs.debian.org/583435
Would /var/run (or a subdirectory of it) be a better choice than /tmp ?
Hi!
Quoted 10 lines · Chuck Lever
Quoted 9 lines · On 06/ 2/10 07:25 AM, An=C3=ADbal Monsalve Salazar wrote:
Quoted 8 lines · Guillem Jover
Quoted 7 lines · Guillem Jover
Package: rpcbind
Version: 0.2.0-4
Severity: serious
Tags: securityThe rpcbind daemon, which runs as root, uses
/tmp/portmap.xdrand/tmp/rpcbind.xdrfor doing warm starts as what seems to be a way =
to
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
preserve state between invokations. It parses (through libtirpc) =
and
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
removes them on start. It creates them before exiting.
So first off, *any* user can craft those two files before the dae=
mon
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
has started for the first time, which the daemon will parse. This might be ok, depending on the checks done on parse, I'd still be =
very
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
wary of letting a user be able to craft such files at will.
It seems to be doing no checks whatsoever. A simple test I performe=
d at
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
the time of filing this report, but didn't seem to have any obvious consequence, shows this which I noticed later on:
The original bug report is at http://bugs.debian.org/583435
I'm adding here part of the initial mail that I trimmed when replying to myself:
,---
The second problem is that those files get created by the daemon on shutdown, and they *do* follow symlinks. So a user can drop two symlinks
there while the daemon is running and overwrite any file on the file system on shutdown.
The fix would consist of passing to configure something like =E2=80=9C--with-statedir=3D/var/cache/rpcbind=E2=80=9D, and make sure the=
daemon creates
such directory if missing on exit in src/warmstart.c:write_struct(), which it does not seem to be doing currently.
In addition it would be wise to notify upstream to change the default statedir to something else than /tmp.
`---
Quoted 1 line
Would
/var/run(or a subdirectory of it) be a better choice than /tmp ?
/var/run might not be preserved across reboots, but regardless of that I think /var/cache is a better fit, it's internal state, but it's used to speed up start up time, and can be removed w/o ill effects.
regards,
guillem
A message that is not in the archive (sent off-list or not yet received): 20100603202743.GA6643-v62vTE6/wQGgM1MOaoewpti2O/[email protected]
Quoted 13 lines · Guillem Jover
Hi!
Quoted 10 lines · Chuck Lever
Quoted 9 lines · On 06/ 2/10 07:25 AM, An=C3=ADbal Monsalve Salazar wrote:
Quoted 8 lines · Guillem Jover
Quoted 7 lines · Guillem Jover
Package: rpcbind
Version: 0.2.0-4
Severity: serious
Tags: securityThe rpcbind daemon, which runs as root, uses
/tmp/portmap.xdrand/tmp/rpcbind.xdrfor doing warm starts as what seems to be a way =
to
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
preserve state between invokations. It parses (through libtirpc) =
and
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
removes them on start. It creates them before exiting.
So first off, *any* user can craft those two files before the dae=
mon
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
has started for the first time, which the daemon will parse. This might be ok, depending on the checks done on parse, I'd still be =
very
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
wary of letting a user be able to craft such files at will.
It seems to be doing no checks whatsoever. A simple test I perform=
ed at
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the time of filing this report, but didn't seem to have any obviou=
s
Quoted 14 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
consequence, shows this which I noticed later on:
The original bug report is at http://bugs.debian.org/583435
I'm adding here part of the initial mail that I trimmed when replying to myself:
,---
The second problem is that those files get created by the daemon on shutdown, and they *do* follow symlinks. So a user can drop two symlinks
there while the daemon is running and overwrite any file on the file system on shutdown.
Quoted 2 lines
The fix would consist of passing to configure something like =E2=80=9C--with-statedir=3D/var/cache/rpcbind=E2=80=9D, and make sure=
the daemon creates
Quoted 6 lines
such directory if missing on exit in src/warmstart.c:write_struct(), which it does not seem to be doing currently.
In addition it would be wise to notify upstream to change the default statedir to something else than /tmp.
`---
Agree changing the upstream default is a good idea.
Generally, that kind of directory is created as part of installation=20 (like, by rpm --install) rather than by the daemon itself.
Quoted 1 line
Quoted 1 line
Would
/var/run(or a subdirectory of it) be a better choice than /tm=
p ?
Quoted 2 lines
/var/runmight not be preserved across reboots, but regardless of tha=
t I
Quoted 2 lines
think
/var/cacheis a better fit, it's internal state, but it's used to speed up start up time, and can be removed w/o ill effects.
No, it's not intended to speed start up.
The cache files aren't really supposed to be retained over a reboot.=20 After a system restart, all of the RPC services will restart and=20 register themselves again. If just rpcbind restarts, all that=20 registration state is lost, so that's the point of saving it in a file.
I don't have a preference wrt /var/run or /var/cache.
Quoted 9 lines · Chuck Lever
Quoted 8 lines · Guillem Jover
The second problem is that those files get created by the daemon on shutdown, and they *do* follow symlinks. So a user can drop two symlinks
there while the daemon is running and overwrite any file on the file system on shutdown.The fix would consist of passing to configure something like =E2=80=9C--with-statedir=3D/var/cache/rpcbind=E2=80=9D, and make sur=
e the daemon creates
Quoted 4 lines
Quoted 4 lines
such directory if missing on exit in src/warmstart.c:write_struct(), which it does not seem to be doing currently.
In addition it would be wise to notify upstream to change the defaul=
t
Quoted 6 lines
Quoted 1 line
statedir to something else than /tmp.
=20
Agree changing the upstream default is a good idea.
=20
Generally, that kind of directory is created as part of installation (like, by rpm --install) rather than by the daemon itself.
At least for /var/run I think it's common for systems to mount it as tmpfs, so the directories might not be there on boot. But those can always be created by the init script (or equivalent), it might be a problem if run from inetd though.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Would
/var/run(or a subdirectory of it) be a better choice than /t=
mp ?
Quoted 2 lines
Quoted 2 lines
/var/runmight not be preserved across reboots, but regardless of th=
at I
Quoted 10 lines
Quoted 2 lines
think
/var/cacheis a better fit, it's internal state, but it's used to speed up start up time, and can be removed w/o ill effects.=20
No, it's not intended to speed start up.
=20
The cache files aren't really supposed to be retained over a reboot. After a system restart, all of the RPC services will restart and register themselves again. If just rpcbind restarts, all that registration state is lost, so that's the point of saving it in a file.
Ah, yeah that makes more sense! More so given the configure option, I should have written "AFAIS" or something like that. :)
Quoted 1 line
I don't have a preference wrt
/var/runor/var/cache.
So given that this is actually run time state, /var/run seems more appropriate, indeed.
regards,
guillem
A message that is not in the archive (sent off-list or not yet received): 20100603210707.GA7377-v62vTE6/wQGgM1MOaoewpti2O/[email protected]
Quoted 6 lines · Guillem Jover
Quoted 5 lines · Chuck Lever
Quoted 4 lines · Guillem Jover
The second problem is that those files get created by the daemon on shutdown, and they *do* follow symlinks. So a user can drop two symlinks
there while the daemon is running and overwrite any file on the fil=
e
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
system on shutdown.
The fix would consist of passing to configure something like =E2=80=9C--with-statedir=3D/var/cache/rpcbind=E2=80=9D, and make su=
re the daemon creates
Quoted 1 line
Quoted 1 line
Quoted 1 line
such directory if missing on exit in src/warmstart.c:write_struct()=
,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
which it does not seem to be doing currently.
In addition it would be wise to notify upstream to change the defau=
lt
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
statedir to something else than /tmp.
Agree changing the upstream default is a good idea.
Generally, that kind of directory is created as part of installation (like, by rpm --install) rather than by the daemon itself.
At least for
/var/runI think it's common for systems to mount it as tmpfs, so the directories might not be there on boot. But those ca=
n
Quoted 2 lines
always be created by the init script (or equivalent), it might be a problem if run from inetd though.
Sure, that makes sense. Having the daemon create the directory also=20 means there are fewer ways distributors can get this wrong.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Would
/var/run(or a subdirectory of it) be a better choice than /=
tmp ?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
/var/runmight not be preserved across reboots, but regardless of t=
hat I
Quoted 1 line
Quoted 1 line
Quoted 1 line
think
/var/cacheis a better fit, it's internal state, but it's use=
d
Quoted 17 lines
Quoted 9 lines
Quoted 1 line
to speed up start up time, and can be removed w/o ill effects.
No, it's not intended to speed start up.
The cache files aren't really supposed to be retained over a reboot. After a system restart, all of the RPC services will restart and register themselves again. If just rpcbind restarts, all that registration state is lost, so that's the point of saving it in a file.
Ah, yeah that makes more sense! More so given the configure option, I should have written "AFAIS" or something like that. :)
Quoted 1 line
I don't have a preference wrt
/var/runor/var/cache.So given that this is actually run time state,
/var/runseems more appropriate, indeed.