Skip to contentSkip to conversation

Fix prlimit64 for suid/sgid processes

PATCH Superseded Kacper Kornet 4 participants 6 messages Jan 27, 2011 – Feb 15, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix prlimit64 for suid/sgid processes

Since check_prlimit_permission always fails in the case of SUID/GUID processes, such processes are not able to read or set their own limits. This commit changes this by assuming that process can always read/change its own limits.

---
 kernel/sys.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
kernel/sys.c +6 -4
index e9ad444..0aaafde 100644
@@ -1409,10 +1409,12 @@ SYSCALL_DEFINE4(prlimit64, pid_t, pid, unsigned int, resource,
 		rcu_read_unlock();
 		return -ESRCH;
 	}
-	ret = check_prlimit_permission(tsk);
-	if (ret) {
-		rcu_read_unlock();
-		return ret;
+	if (tsk != current) {
+		ret = check_prlimit_permission(tsk);
+		if (ret) {
+			rcu_read_unlock();
+			return ret;
+		}
 	}
 	get_task_struct(tsk);
 	rcu_read_unlock();
Signature · 1 line
  Kacper Kornet
#1 lore raw
Quoted 4 lines · Kacper Kornet

Since check_prlimit_permission always fails in the case of SUID/GUID processes, such processes are not able to read or set their own limits. This commit changes this by assuming that process can always read/change its own limits.

Shouldn't this be fixed in check_prlimit_permissions() instead of in the caller?

Linus

#2 lore raw

PATCH v2 1/1 Fix prlimit64 for suid/sgid processes

Since check_prlimit_permission always fails in the case of SUID/GUID processes, such processes are not able to read or set their own limits. This commit changes this by assuming that process can always read/change its own limits.

---
 kernel/sys.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/sys.c +2 -1
index e9ad444..03bead7 100644
@@ -1375,7 +1375,8 @@ static int check_prlimit_permission(struct task_struct *task)
 	const struct cred *cred = current_cred(), *tcred;
 
 	tcred = __task_cred(task);
-	if ((cred->uid != tcred->euid ||
+	if (current != task &&
+	    (cred->uid != tcred->euid ||
 	     cred->uid != tcred->suid ||
 	     cred->uid != tcred->uid  ||
 	     cred->gid != tcred->egid ||
Signature · 4 lines
1.7.3.5

-- 
  Kacper 
#3 lore raw
Quoted 6 lines · Kacper Kornet

Since check_prlimit_permission always fails in the case of SUID/GUID processes, such processes are not able to read or set their own limits. This commit changes this by assuming that process can always read/change its own limits.

ACK. The check comes from the ptrace code. I forgot to copy this test.

Quoted 9 lines
---
 kernel/sys.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/sys.c +0 -0
index e9ad444..03bead7 100644

kernel/sys.c static int check_prlimit_permission(struct task_struct *task) · line 1382

Quoted 9 lines
kernel/sys.c +2 -1
@@ -1375,7 +1375,8 @@ static int check_prlimit_permission(struct task_struct *task)
 	const struct cred *cred = current_cred(), *tcred;
 
 	tcred = __task_cred(task);
-	if ((cred->uid != tcred->euid ||
+	if (current != task &&
+	    (cred->uid != tcred->euid ||
 	     cred->uid != tcred->suid ||
 	     cred->uid != tcred->uid  ||
 	     cred->gid != tcred->egid ||

thanks,

Signature · 2 lines
js
suse labs
#4 lore raw
In reply to Kacper Kornet

Ccing stable.

Merged as aa5bd67dcfdf9 and should go into:
->.36-stable (if maintained still)
->.37-stable

Quoted 15 lines · Kacper Kornet

Since check_prlimit_permission always fails in the case of SUID/GUID processes, such processes are not able to read or set their own limits. This commit changes this by assuming that process can always read/change its own limits.

---
 kernel/sys.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/sys.c +0 -0
index e9ad444..03bead7 100644

kernel/sys.c static int check_prlimit_permission(struct task_struct *task) · line 1382

Quoted 9 lines
kernel/sys.c +2 -1
@@ -1375,7 +1375,8 @@ static int check_prlimit_permission(struct task_struct *task)
 	const struct cred *cred = current_cred(), *tcred;
 
 	tcred = __task_cred(task);
-	if ((cred->uid != tcred->euid ||
+	if (current != task &&
+	    (cred->uid != tcred->euid ||
 	     cred->uid != tcred->suid ||
 	     cred->uid != tcred->uid  ||
 	     cred->gid != tcred->egid ||

thanks,

Signature · 2 lines
js
suse labs
#5 lore raw
Quoted 5 lines · Jiri Slaby

Ccing stable.

Merged as aa5bd67dcfdf9 and should go into:
->.36-stable (if maintained still)
->.37-stable

Thanks, now queued up.

greg k-h