Skip to contentSkip to conversation

scsi: require CAP_SYS_ADMIN to write to procfs interface

PATCH Superseded Aleksa Sarai 3 participants 4 messages Nov 4, 2017 1 message not in the archive

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: require CAP_SYS_ADMIN to write to procfs interface

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).

---
 drivers/scsi/scsi_proc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/scsi/scsi_proc.c +7 -1
index 480a597b3877..486aedce2f05 100644
@@ -51,7 +51,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 +316,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;
 
Signature · 1 line
2.14.3
#1 lore raw
Quoted 19 lines · Aleksa Sarai

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).

---
 drivers/scsi/scsi_proc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/scsi/scsi_proc.c +0 -0
index 480a597b3877..486aedce2f05 100644

drivers/scsi/scsi_proc.c static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf, · line 56

Quoted 7 lines
drivers/scsi/scsi_proc.c +3 -1
@@ -51,7 +51,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

did that build without a trailing ';' ?

Quoted 15 lines
drivers/scsi/scsi_proc.c +4 -0
+
 	if (count > PROC_BLOCK_SIZE)
 		return -EOVERFLOW;
 
@@ -313,6 +316,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;
 
Signature · 1 line
~Randy
#2 lore raw
Quoted 14 lines
Quoted 14 lines

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 "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected]>
---
  drivers/scsi/scsi_proc.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/scsi/scsi_proc.c static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf, · line 56

Quoted 12 lines
drivers/scsi/scsi_proc.c +3 -1
index 480a597b3877..486aedce2f05 100644
@@ -51,7 +51,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

did that build without a trailing ';' ?

D'oh. Re-sent, thanks.

Signature · 4 lines
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
https://www.cyphar.com/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 19 lines · Aleksa Sarai

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 "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected]>
---
 drivers/scsi/scsi_proc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/scsi/scsi_proc.c +0 -0
index 480a597b3877..486aedce2f05 100644

drivers/scsi/scsi_proc.c static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf, · line 56

Quoted 7 lines
drivers/scsi/scsi_proc.c +3 -1
@@ -51,7 +51,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

did that build without a trailing ';' ?

Quoted 15 lines
drivers/scsi/scsi_proc.c +4 -0
+
 	if (count > PROC_BLOCK_SIZE)
 		return -EOVERFLOW;
 
@@ -313,6 +316,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;
 
Signature · 1 line
~Randy