* [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface
@ 2017-11-05 2:56 Aleksa Sarai
[not found] ` <20171105025635.10843-1-asarai-l3A5Bk7waGM@public.gmane.org>
2017-11-05 7:31 ` Greg KH
0 siblings, 2 replies; 11+ messages in thread
From: Aleksa Sarai @ 2017-11-05 2:56 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, linux-kernel, containers, Valentin Rothberg, cyphar,
Aleksa Sarai, stable, Eric W. Biederman
Previously, the only capability effectively required to operate on the
/proc/scsi interface was CAP_DAC_OVERRIDE (or for some other files,
having an fsuid of GLOBAL_ROOT_UID was enough). This means that
semi-privileged processes could interfere with core components of a
system (such as causing a DoS by removing the underlying SCSI device of
the host's / mount).
Cc: <stable@vger.kernel.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Aleksa Sarai <asarai@suse.de>
---
drivers/scsi/scsi_proc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index 480a597b3877..05d70e200c5f 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -27,6 +27,7 @@
#include <linux/mutex.h>
#include <linux/gfp.h>
#include <linux/uaccess.h>
+#include <linux/capability.h>
#include <scsi/scsi.h>
#include <scsi/scsi_device.h>
@@ -51,7 +52,10 @@ static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
struct Scsi_Host *shost = PDE_DATA(file_inode(file));
ssize_t ret = -ENOMEM;
char *page;
-
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
if (count > PROC_BLOCK_SIZE)
return -EOVERFLOW;
@@ -313,6 +317,9 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
char *buffer, *p;
int err;
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
if (!buf || length > PAGE_SIZE)
return -EINVAL;
--
2.14.3
^ permalink raw reply related [flat|nested] 11+ messages in thread[parent not found: <20171105025635.10843-1-asarai-l3A5Bk7waGM@public.gmane.org>]
* Re: [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface
2017-11-05 2:56 [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface Aleksa Sarai
@ 2017-11-05 4:02 ` Aleksa Sarai
2017-11-05 7:31 ` Greg KH
1 sibling, 0 replies; 11+ messages in thread
From: Aleksa Sarai @ 2017-11-05 4:02 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
stable-u79uwXL29TY76Z2rM5mHXA, cyphar-gVpy/LI/lHzQT0dZR+AlfA,
Eric W. Biederman
On 11/05/2017 01:56 PM, Aleksa Sarai wrote:
> Previously, the only capability effectively required to operate on the
> /proc/scsi interface was CAP_DAC_OVERRIDE (or for some other files,
> having an fsuid of GLOBAL_ROOT_UID was enough). This means that
> semi-privileged processes could interfere with core components of a
> system (such as causing a DoS by removing the underlying SCSI device of
> the host's / mount).
An alternative to this patch would be to make the open(2) call fail, if
you try to open it write-only or read-write. Not sure which would be
preferred (should it be possible to pass /proc/scsi/scsi to a
semi-privileged process to write to?).
--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
https://www.cyphar.com/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface
@ 2017-11-05 4:02 ` Aleksa Sarai
0 siblings, 0 replies; 11+ messages in thread
From: Aleksa Sarai @ 2017-11-05 4:02 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, linux-kernel, containers, Valentin Rothberg, cyphar,
stable, Eric W. Biederman
On 11/05/2017 01:56 PM, Aleksa Sarai wrote:
> Previously, the only capability effectively required to operate on the
> /proc/scsi interface was CAP_DAC_OVERRIDE (or for some other files,
> having an fsuid of GLOBAL_ROOT_UID was enough). This means that
> semi-privileged processes could interfere with core components of a
> system (such as causing a DoS by removing the underlying SCSI device of
> the host's / mount).
An alternative to this patch would be to make the open(2) call fail, if
you try to open it write-only or read-write. Not sure which would be
preferred (should it be possible to pass /proc/scsi/scsi to a
semi-privileged process to write to?).
--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
https://www.cyphar.com/
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <b3bcff37-d77d-4dc6-ba83-7dddcb51a703-l3A5Bk7waGM@public.gmane.org>]
* Re: [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface
[not found] ` <b3bcff37-d77d-4dc6-ba83-7dddcb51a703-l3A5Bk7waGM@public.gmane.org>
@ 2017-11-09 21:40 ` Eric W. Biederman
0 siblings, 0 replies; 11+ messages in thread
From: Eric W. Biederman @ 2017-11-09 21:40 UTC (permalink / raw)
To: Aleksa Sarai
Cc: Martin K. Petersen, linux-scsi-u79uwXL29TY76Z2rM5mHXA,
greg-U8xfFu+wG4EAvxtiuMwx3w,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
stable-u79uwXL29TY76Z2rM5mHXA, cyphar-gVpy/LI/lHzQT0dZR+AlfA,
James E.J. Bottomley
Aleksa Sarai <asarai-l3A5Bk7waGM@public.gmane.org> writes:
> On 11/05/2017 01:56 PM, Aleksa Sarai wrote:
>> Previously, the only capability effectively required to operate on the
>> /proc/scsi interface was CAP_DAC_OVERRIDE (or for some other files,
>> having an fsuid of GLOBAL_ROOT_UID was enough). This means that
>> semi-privileged processes could interfere with core components of a
>> system (such as causing a DoS by removing the underlying SCSI device of
>> the host's / mount).
>
> An alternative to this patch would be to make the open(2) call fail, if you try
> to open it write-only or read-write. Not sure which would be preferred (should
> it be possible to pass /proc/scsi/scsi to a semi-privileged process to write
> to?).
Making open fail is very much the preferred solution.
Testing for permission on write can be avoided by finding a suid root
application whose error output acts like a suid cat.
The best current practice for adding this kind of permission check is to
add the check in open. For some older use cases where we made this
mistake we had to maintian a check during write to avoid breaking
userspace. But as this check is new there is no reason to add a check
anywhere except in open.
Eric
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface
2017-11-05 4:02 ` Aleksa Sarai
@ 2017-11-09 21:40 ` Eric W. Biederman
-1 siblings, 0 replies; 11+ messages in thread
From: Eric W. Biederman @ 2017-11-09 21:40 UTC (permalink / raw)
To: Aleksa Sarai
Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel, containers, Valentin Rothberg, cyphar, stable, greg
Aleksa Sarai <asarai@suse.de> writes:
> On 11/05/2017 01:56 PM, Aleksa Sarai wrote:
>> Previously, the only capability effectively required to operate on the
>> /proc/scsi interface was CAP_DAC_OVERRIDE (or for some other files,
>> having an fsuid of GLOBAL_ROOT_UID was enough). This means that
>> semi-privileged processes could interfere with core components of a
>> system (such as causing a DoS by removing the underlying SCSI device of
>> the host's / mount).
>
> An alternative to this patch would be to make the open(2) call fail, if you try
> to open it write-only or read-write. Not sure which would be preferred (should
> it be possible to pass /proc/scsi/scsi to a semi-privileged process to write
> to?).
Making open fail is very much the preferred solution.
Testing for permission on write can be avoided by finding a suid root
application whose error output acts like a suid cat.
The best current practice for adding this kind of permission check is to
add the check in open. For some older use cases where we made this
mistake we had to maintian a check during write to avoid breaking
userspace. But as this check is new there is no reason to add a check
anywhere except in open.
Eric
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface
@ 2017-11-09 21:40 ` Eric W. Biederman
0 siblings, 0 replies; 11+ messages in thread
From: Eric W. Biederman @ 2017-11-09 21:40 UTC (permalink / raw)
To: Aleksa Sarai
Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel, containers, Valentin Rothberg, cyphar, stable, greg
Aleksa Sarai <asarai@suse.de> writes:
> On 11/05/2017 01:56 PM, Aleksa Sarai wrote:
>> Previously, the only capability effectively required to operate on the
>> /proc/scsi interface was CAP_DAC_OVERRIDE (or for some other files,
>> having an fsuid of GLOBAL_ROOT_UID was enough). This means that
>> semi-privileged processes could interfere with core components of a
>> system (such as causing a DoS by removing the underlying SCSI device of
>> the host's / mount).
>
> An alternative to this patch would be to make the open(2) call fail, if you try
> to open it write-only or read-write. Not sure which would be preferred (should
> it be possible to pass /proc/scsi/scsi to a semi-privileged process to write
> to?).
Making open fail is very much the preferred solution.
Testing for permission on write can be avoided by finding a suid root
application whose error output acts like a suid cat.
The best current practice for adding this kind of permission check is to
add the check in open. For some older use cases where we made this
mistake we had to maintian a check during write to avoid breaking
userspace. But as this check is new there is no reason to add a check
anywhere except in open.
Eric
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface
2017-11-05 2:56 [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface Aleksa Sarai
[not found] ` <20171105025635.10843-1-asarai-l3A5Bk7waGM@public.gmane.org>
@ 2017-11-05 7:31 ` Greg KH
[not found] ` <20171105073121.GB1431-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
1 sibling, 1 reply; 11+ messages in thread
From: Greg KH @ 2017-11-05 7:31 UTC (permalink / raw)
To: Aleksa Sarai
Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel, containers, Valentin Rothberg, cyphar, stable,
Eric W. Biederman
On Sun, Nov 05, 2017 at 01:56:35PM +1100, Aleksa Sarai wrote:
> Previously, the only capability effectively required to operate on the
> /proc/scsi interface was CAP_DAC_OVERRIDE (or for some other files,
> having an fsuid of GLOBAL_ROOT_UID was enough). This means that
> semi-privileged processes could interfere with core components of a
> system (such as causing a DoS by removing the underlying SCSI device of
> the host's / mount).
Given that the previous patch didn't even compile, I worry that you have
not tested this at all to see what breaks/changes in userspace with this
type of user-visable api change.
What did you do to test this?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface
@ 2017-11-05 2:56 Aleksa Sarai
0 siblings, 0 replies; 11+ messages in thread
From: Aleksa Sarai @ 2017-11-05 2:56 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
stable-u79uwXL29TY76Z2rM5mHXA, cyphar-gVpy/LI/lHzQT0dZR+AlfA,
Eric W. Biederman
Previously, the only capability effectively required to operate on the
/proc/scsi interface was CAP_DAC_OVERRIDE (or for some other files,
having an fsuid of GLOBAL_ROOT_UID was enough). This means that
semi-privileged processes could interfere with core components of a
system (such as causing a DoS by removing the underlying SCSI device of
the host's / mount).
Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Signed-off-by: Aleksa Sarai <asarai-l3A5Bk7waGM@public.gmane.org>
---
drivers/scsi/scsi_proc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index 480a597b3877..05d70e200c5f 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -27,6 +27,7 @@
#include <linux/mutex.h>
#include <linux/gfp.h>
#include <linux/uaccess.h>
+#include <linux/capability.h>
#include <scsi/scsi.h>
#include <scsi/scsi_device.h>
@@ -51,7 +52,10 @@ static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
struct Scsi_Host *shost = PDE_DATA(file_inode(file));
ssize_t ret = -ENOMEM;
char *page;
-
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
if (count > PROC_BLOCK_SIZE)
return -EOVERFLOW;
@@ -313,6 +317,9 @@ static ssize_t proc_scsi_write(struct file *file, const char __user *buf,
char *buffer, *p;
int err;
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
if (!buf || length > PAGE_SIZE)
return -EINVAL;
--
2.14.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-11-09 21:40 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-05 2:56 [PATCH v3] scsi: require CAP_SYS_ADMIN to write to procfs interface Aleksa Sarai
[not found] ` <20171105025635.10843-1-asarai-l3A5Bk7waGM@public.gmane.org>
2017-11-05 4:02 ` Aleksa Sarai
2017-11-05 4:02 ` Aleksa Sarai
[not found] ` <b3bcff37-d77d-4dc6-ba83-7dddcb51a703-l3A5Bk7waGM@public.gmane.org>
2017-11-09 21:40 ` Eric W. Biederman
2017-11-09 21:40 ` Eric W. Biederman
2017-11-09 21:40 ` Eric W. Biederman
2017-11-05 7:31 ` Greg KH
[not found] ` <20171105073121.GB1431-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-11-05 9:11 ` Aleksa Sarai
2017-11-05 9:11 ` Aleksa Sarai
2017-11-05 10:29 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2017-11-05 2:56 Aleksa Sarai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.