Skip to contentSkip to conversation

2.5.40 capget fix

PATCH New Chris Wright 1 participant 1 message Oct 5, 2002 Capabilities

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.5.40 capget fix

Linus,

Daniel Jacobowitz noticed that sys_capget is not behaving properly when called with pid of 0. It is supposed to return current capabilities, not those of swapper. Also cleaned up some duplicate code from a merge error. Patch is tested, please apply.

thanks,
-chris

kernel/capability.c +9 -10
@@ -33,7 +33,7 @@
      int ret = 0;
      pid_t pid;
      __u32 version;
-     task_t *target;
+     task_t *target = current;
      struct __user_cap_data_struct data;
 
      if (get_user(version, &header->version))
@@ -52,21 +52,20 @@
              return -EINVAL;
 
      spin_lock(&task_capability_lock);
-     read_lock(&tasklist_lock); 
 
-     target = find_task_by_pid(pid);
-     if (!target) {
-          ret = -ESRCH;
-          goto out;
+     if (pid && pid != current->pid) {
+	     read_lock(&tasklist_lock); 
+	     target = find_task_by_pid(pid);
+	     read_unlock(&tasklist_lock); 
+	     if (!target) {
+	          ret = -ESRCH;
+	          goto out;
+	     }
      }
 
-     data.permitted = cap_t(target->cap_permitted);
-     data.inheritable = cap_t(target->cap_inheritable); 
-     data.effective = cap_t(target->cap_effective);
      ret = security_ops->capget(target, &data.effective, &data.inheritable, &data.permitted);
 
 out:
-     read_unlock(&tasklist_lock); 
      spin_unlock(&task_capability_lock);
 
      if (!ret && copy_to_user(dataptr, &data, sizeof data))