Re: [RFC][PATCH 10/13] get rid of audit_reusename()

Al Viro
2025-11-10T19:58:35Z

On Mon, Nov 10, 2025 at 08:41:45AM -0800, Linus Torvalds wrote:

> > IMO things like "xfs" or "ceph" don't look like pathnames - if
> > anything, we ought to use copy_mount_string() for consistency with
> > mount(2)...
>
> Oh, absolutely not.
>
> But that code certainly could just do strndup_user(). That's the
> normal thing for "get a string from user space" these days, but it
> didn't historically exist..

There would be a minor change in errors (s/ENAMETOOLONG/EINVAL/
and s/ENOENT/EINVAL/, AFAICS), but nobody really gives a damn,
so...

If we go that way, do you see any problems with treating
osf_{ufs,cdfs}_mount() in the same manner? Yes, these are pathnames,
but the strings copied there are going to be fed (after another round
of copying) to lookup_bdev(), i.e. getname_kernel(). At least that
way it would be consistent with what mount(2) does...

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index a08e8edef1a4..21a8f985999b 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -454,42 +454,34 @@ static int
osf_ufs_mount(const char __user *dirname,
struct ufs_args __user *args, int flags)
{
- int retval;
+ char *devname __free(kfree) = NULL;
struct cdfs_args tmp;
- struct filename *devname;

- retval = -EFAULT;
if (copy_from_user(&tmp, args, sizeof(tmp)))
- goto out;
- devname = getname(tmp.devname);
- retval = PTR_ERR(devname);
+ return -EFAULT;
+
+ devname = strndup_user(tmp.devname, PATH_MAX);
if (IS_ERR(devname))
- goto out;
- retval = do_mount(devname->name, dirname, "ext2", flags, NULL);
- putname(devname);
- out:
- return retval;
+ return PTR_ERR(devname);
+
+ return do_mount(devname, dirname, "ext2", flags, NULL);
}

static int
osf_cdfs_mount(const char __user *dirname,
struct cdfs_args __user *args, int flags)
{
- int retval;
+ char *devname __free(kfree) = NULL;
struct cdfs_args tmp;
- struct filename *devname;

- retval = -EFAULT;
if (copy_from_user(&tmp, args, sizeof(tmp)))
- goto out;
- devname = getname(tmp.devname);
- retval = PTR_ERR(devname);
+ return -EFAULT;
+
+ devname = strndup_user(tmp.devname, PATH_MAX);
if (IS_ERR(devname))
- goto out;
- retval = do_mount(devname->name, dirname, "iso9660", flags, NULL);
- putname(devname);
- out:
- return retval;
+ return PTR_ERR(devname);
+
+ return do_mount(devname, dirname, "iso9660", flags, NULL);
}

static int