Skip to content

Commit

Permalink
[PATCH] sanitize security_getprocattr() API
Browse files Browse the repository at this point in the history
have it return the buffer it had allocated

Acked-by: Stephen Smalley <[email protected]>
Acked-by: James Morris <[email protected]>
Signed-off-by: Al Viro <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Al Viro authored and Linus Torvalds committed Mar 14, 2007
1 parent c4823bc commit 04ff970
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
21 changes: 6 additions & 15 deletions fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1558,29 +1558,20 @@ static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
size_t count, loff_t *ppos)
{
struct inode * inode = file->f_path.dentry->d_inode;
unsigned long page;
char *p = NULL;
ssize_t length;
struct task_struct *task = get_proc_task(inode);

length = -ESRCH;
if (!task)
goto out_no_task;

if (count > PAGE_SIZE)
count = PAGE_SIZE;
length = -ENOMEM;
if (!(page = __get_free_page(GFP_KERNEL)))
goto out;
return -ESRCH;

length = security_getprocattr(task,
(char*)file->f_path.dentry->d_name.name,
(void*)page, count);
if (length >= 0)
length = simple_read_from_buffer(buf, count, ppos, (char *)page, length);
free_page(page);
out:
&p);
put_task_struct(task);
out_no_task:
if (length > 0)
length = simple_read_from_buffer(buf, count, ppos, p, length);
kfree(p);
return length;
}

Expand Down
8 changes: 4 additions & 4 deletions include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ struct security_operations {

void (*d_instantiate) (struct dentry *dentry, struct inode *inode);

int (*getprocattr)(struct task_struct *p, char *name, void *value, size_t size);
int (*getprocattr)(struct task_struct *p, char *name, char **value);
int (*setprocattr)(struct task_struct *p, char *name, void *value, size_t size);
int (*secid_to_secctx)(u32 secid, char **secdata, u32 *seclen);
void (*release_secctx)(char *secdata, u32 seclen);
Expand Down Expand Up @@ -2092,9 +2092,9 @@ static inline void security_d_instantiate (struct dentry *dentry, struct inode *
security_ops->d_instantiate (dentry, inode);
}

static inline int security_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
static inline int security_getprocattr(struct task_struct *p, char *name, char **value)
{
return security_ops->getprocattr(p, name, value, size);
return security_ops->getprocattr(p, name, value);
}

static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
Expand Down Expand Up @@ -2749,7 +2749,7 @@ static inline int security_sem_semop (struct sem_array * sma,
static inline void security_d_instantiate (struct dentry *dentry, struct inode *inode)
{ }

static inline int security_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
static inline int security_getprocattr(struct task_struct *p, char *name, char **value)
{
return -EINVAL;
}
Expand Down
2 changes: 1 addition & 1 deletion security/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ static void dummy_d_instantiate (struct dentry *dentry, struct inode *inode)
return;
}

static int dummy_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
static int dummy_getprocattr(struct task_struct *p, char *name, char **value)
{
return -EINVAL;
}
Expand Down
8 changes: 6 additions & 2 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -4468,11 +4468,12 @@ static void selinux_d_instantiate (struct dentry *dentry, struct inode *inode)
}

static int selinux_getprocattr(struct task_struct *p,
char *name, void *value, size_t size)
char *name, char **value)
{
struct task_security_struct *tsec;
u32 sid;
int error;
unsigned len;

if (current != p) {
error = task_has_perm(current, p, PROCESS__GETATTR);
Expand Down Expand Up @@ -4500,7 +4501,10 @@ static int selinux_getprocattr(struct task_struct *p,
if (!sid)
return 0;

return selinux_getsecurity(sid, value, size);
error = security_sid_to_context(sid, value, &len);
if (error)
return error;
return len;
}

static int selinux_setprocattr(struct task_struct *p,
Expand Down

0 comments on commit 04ff970

Please sign in to comment.