Skip to content

Commit

Permalink
vfs: define struct filename and have getname() return it
Browse files Browse the repository at this point in the history
getname() is intended to copy pathname strings from userspace into a
kernel buffer. The result is just a string in kernel space. It would
however be quite helpful to be able to attach some ancillary info to
the string.

For instance, we could attach some audit-related info to reduce the
amount of audit-related processing needed. When auditing is enabled,
we could also call getname() on the string more than once and not
need to recopy it from userspace.

This patchset converts the getname()/putname() interfaces to return
a struct instead of a string. For now, the struct just tracks the
string in kernel space and the original userland pointer for it.

Later, we'll add other information to the struct as it becomes
convenient.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
jtlayton authored and Al Viro committed Oct 13, 2012
1 parent 8e377d1 commit 91a27b2
Show file tree
Hide file tree
Showing 40 changed files with 218 additions and 175 deletions.
16 changes: 8 additions & 8 deletions arch/alpha/kernel/osf_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ osf_ufs_mount(char *dirname, struct ufs_args __user *args, int flags)
{
int retval;
struct cdfs_args tmp;
char *devname;
struct filename *devname;

retval = -EFAULT;
if (copy_from_user(&tmp, args, sizeof(tmp)))
Expand All @@ -458,7 +458,7 @@ osf_ufs_mount(char *dirname, struct ufs_args __user *args, int flags)
retval = PTR_ERR(devname);
if (IS_ERR(devname))
goto out;
retval = do_mount(devname, dirname, "ext2", flags, NULL);
retval = do_mount(devname->name, dirname, "ext2", flags, NULL);
putname(devname);
out:
return retval;
Expand All @@ -469,7 +469,7 @@ osf_cdfs_mount(char *dirname, struct cdfs_args __user *args, int flags)
{
int retval;
struct cdfs_args tmp;
char *devname;
struct filename *devname;

retval = -EFAULT;
if (copy_from_user(&tmp, args, sizeof(tmp)))
Expand All @@ -478,7 +478,7 @@ osf_cdfs_mount(char *dirname, struct cdfs_args __user *args, int flags)
retval = PTR_ERR(devname);
if (IS_ERR(devname))
goto out;
retval = do_mount(devname, dirname, "iso9660", flags, NULL);
retval = do_mount(devname->name, dirname, "iso9660", flags, NULL);
putname(devname);
out:
return retval;
Expand All @@ -499,21 +499,21 @@ SYSCALL_DEFINE4(osf_mount, unsigned long, typenr, const char __user *, path,
int, flag, void __user *, data)
{
int retval;
char *name;
struct filename *name;

name = getname(path);
retval = PTR_ERR(name);
if (IS_ERR(name))
goto out;
switch (typenr) {
case 1:
retval = osf_ufs_mount(name, data, flag);
retval = osf_ufs_mount(name->name, data, flag);
break;
case 6:
retval = osf_cdfs_mount(name, data, flag);
retval = osf_cdfs_mount(name->name, data, flag);
break;
case 9:
retval = osf_procfs_mount(name, data, flag);
retval = osf_procfs_mount(name->name, data, flag);
break;
default:
retval = -EINVAL;
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ asmlinkage long sys_execve(const char __user *filenamei,
struct pt_regs *regs)
{
long error;
char * filename;
struct filename *filename;

filename = getname(filenamei);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = do_execve(filename, argv, envp, regs);
error = do_execve(filename->name, argv, envp, regs);
putname(filename);
out:
return error;
Expand Down
6 changes: 3 additions & 3 deletions arch/arm64/kernel/sys_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ asmlinkage int compat_sys_execve(const char __user *filenamei,
struct pt_regs *regs)
{
int error;
char * filename;
struct filename *filename;

filename = getname(filenamei);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = compat_do_execve(filename, compat_ptr(argv), compat_ptr(envp),
regs);
error = compat_do_execve(filename->name, compat_ptr(argv),
compat_ptr(envp), regs);
putname(filename);
out:
return error;
Expand Down
4 changes: 2 additions & 2 deletions arch/avr32/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,14 @@ asmlinkage int sys_execve(const char __user *ufilename,
struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname(ufilename);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;

error = do_execve(filename, uargv, uenvp, regs);
error = do_execve(filename->name, uargv, uenvp, regs);
putname(filename);

out:
Expand Down
4 changes: 2 additions & 2 deletions arch/blackfin/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ asmlinkage int sys_execve(const char __user *name,
const char __user *const __user *envp)
{
int error;
char *filename;
struct filename *filename;
struct pt_regs *regs = (struct pt_regs *)((&name) + 6);

filename = getname(name);
error = PTR_ERR(filename);
if (IS_ERR(filename))
return error;
error = do_execve(filename, argv, envp, regs);
error = do_execve(filename->name, argv, envp, regs);
putname(filename);
return error;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/cris/arch-v10/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ asmlinkage int sys_execve(const char *fname,
struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname(fname);
error = PTR_ERR(filename);

if (IS_ERR(filename))
goto out;
error = do_execve(filename, argv, envp, regs);
error = do_execve(filename->name, argv, envp, regs);
putname(filename);
out:
return error;
Expand Down
4 changes: 2 additions & 2 deletions arch/cris/arch-v32/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ sys_execve(const char *fname,
struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname(fname);
error = PTR_ERR(filename);

if (IS_ERR(filename))
goto out;

error = do_execve(filename, argv, envp, regs);
error = do_execve(filename->name, argv, envp, regs);
putname(filename);
out:
return error;
Expand Down
4 changes: 2 additions & 2 deletions arch/h8300/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ asmlinkage int sys_execve(const char *name,
int dummy, ...)
{
int error;
char * filename;
struct filename *filename;
struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);

filename = getname(name);
error = PTR_ERR(filename);
if (IS_ERR(filename))
return error;
error = do_execve(filename, argv, envp, regs);
error = do_execve(filename->name, argv, envp, regs);
putname(filename);
return error;
}
Expand Down
4 changes: 2 additions & 2 deletions arch/hexagon/kernel/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ asmlinkage int sys_execve(char __user *ufilename,
const char __user *const __user *envp)
{
struct pt_regs *pregs = current_thread_info()->regs;
char *filename;
struct filename *filename;
int retval;

filename = getname(ufilename);
retval = PTR_ERR(filename);
if (IS_ERR(filename))
return retval;

retval = do_execve(filename, argv, envp, pregs);
retval = do_execve(filename->name, argv, envp, pregs);
putname(filename);

return retval;
Expand Down
4 changes: 2 additions & 2 deletions arch/ia64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,14 @@ sys_execve (const char __user *filename,
const char __user *const __user *envp,
struct pt_regs *regs)
{
char *fname;
struct filename *fname;
int error;

fname = getname(filename);
error = PTR_ERR(fname);
if (IS_ERR(fname))
goto out;
error = do_execve(fname, argv, envp, regs);
error = do_execve(fname->name, argv, envp, regs);
putname(fname);
out:
return error;
Expand Down
4 changes: 2 additions & 2 deletions arch/m32r/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ asmlinkage int sys_execve(const char __user *ufilename,
unsigned long r6, struct pt_regs regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname(ufilename);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;

error = do_execve(filename, uargv, uenvp, &regs);
error = do_execve(filename->name, uargv, uenvp, &regs);
putname(filename);
out:
return error;
Expand Down
4 changes: 2 additions & 2 deletions arch/microblaze/kernel/sys_microblaze.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ asmlinkage long microblaze_execve(const char __user *filenamei,
struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname(filenamei);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = do_execve(filename, argv, envp, regs);
error = do_execve(filename->name, argv, envp, regs);
putname(filename);
out:
return error;
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/kernel/linux32.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len,
asmlinkage int sys32_execve(nabi_no_regargs struct pt_regs regs)
{
int error;
char * filename;
struct filename *filename;

filename = getname(compat_ptr(regs.regs[4]));
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = compat_do_execve(filename, compat_ptr(regs.regs[5]),
error = compat_do_execve(filename->name, compat_ptr(regs.regs[5]),
compat_ptr(regs.regs[6]), &regs);
putname(filename);

Expand Down
4 changes: 2 additions & 2 deletions arch/mips/kernel/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ _sys_clone(nabi_no_regargs struct pt_regs regs)
asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
{
int error;
char * filename;
struct filename *filename;

filename = getname((const char __user *) (long)regs.regs[4]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = do_execve(filename,
error = do_execve(filename->name,
(const char __user *const __user *) (long)regs.regs[5],
(const char __user *const __user *) (long)regs.regs[6],
&regs);
Expand Down
4 changes: 2 additions & 2 deletions arch/openrisc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ asmlinkage long _sys_execve(const char __user *name,
struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname(name);
error = PTR_ERR(filename);

if (IS_ERR(filename))
goto out;

error = do_execve(filename, argv, envp, regs);
error = do_execve(filename->name, argv, envp, regs);
putname(filename);

out:
Expand Down
4 changes: 2 additions & 2 deletions arch/parisc/hpux/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
int hpux_execve(struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname((const char __user *) regs->gr[26]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;

error = do_execve(filename,
error = do_execve(filename->name,
(const char __user *const __user *) regs->gr[25],
(const char __user *const __user *) regs->gr[24],
regs);
Expand Down
4 changes: 2 additions & 2 deletions arch/parisc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ unsigned long thread_saved_pc(struct task_struct *t)
asmlinkage int sys_execve(struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname((const char __user *) regs->gr[26]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = do_execve(filename,
error = do_execve(filename->name,
(const char __user *const __user *) regs->gr[25],
(const char __user *const __user *) regs->gr[24],
regs);
Expand Down
4 changes: 2 additions & 2 deletions arch/parisc/kernel/sys_parisc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
asmlinkage int sys32_execve(struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
filename = getname((const char __user *) regs->gr[26]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = compat_do_execve(filename, compat_ptr(regs->gr[25]),
error = compat_do_execve(filename->name, compat_ptr(regs->gr[25]),
compat_ptr(regs->gr[24]), regs);
putname(filename);
out:
Expand Down
4 changes: 2 additions & 2 deletions arch/score/kernel/sys_score.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ asmlinkage long
score_execve(struct pt_regs *regs)
{
int error;
char *filename;
struct filename *filename;

filename = getname((char __user*)regs->regs[4]);
error = PTR_ERR(filename);
if (IS_ERR(filename))
return error;

error = do_execve(filename,
error = do_execve(filename->name,
(const char __user *const __user *)regs->regs[5],
(const char __user *const __user *)regs->regs[6],
regs);
Expand Down
4 changes: 2 additions & 2 deletions arch/sh/kernel/process_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ asmlinkage int sys_execve(const char __user *ufilename,
{
struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
int error;
char *filename;
struct filename *filename;

filename = getname(ufilename);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;

error = do_execve(filename, uargv, uenvp, regs);
error = do_execve(filename->name, uargv, uenvp, regs);
putname(filename);
out:
return error;
Expand Down
Loading

0 comments on commit 91a27b2

Please sign in to comment.