summaryrefslogtreecommitdiffstats
path: root/fs/namei.c
diff options
context:
space:
mode:
authorPaul Moore <pmoore@redhat.com>2015-01-21 23:59:56 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2015-01-23 00:22:20 -0500
commit08518549722f0c992a9e4be71a0777f37147e9d2 (patch)
tree80ac5b25e4b113fb80125c01e26e846f5fde4b98 /fs/namei.c
parentfa14a0b8d2bca1d2226afaa04bdf80200d8e9b03 (diff)
downloadop-kernel-dev-08518549722f0c992a9e4be71a0777f37147e9d2.zip
op-kernel-dev-08518549722f0c992a9e4be71a0777f37147e9d2.tar.gz
fs: rework getname_kernel to handle up to PATH_MAX sized filenames
In preparation for expanded use in the kernel, make getname_kernel() more useful by allowing it to handle any legal filename length. Thanks to Guenter Roeck for his suggestion to substitute memcpy() for strlcpy(). CC: linux@roeck-us.net CC: viro@zeniv.linux.org.uk CC: linux-fsdevel@vger.kernel.org Signed-off-by: Paul Moore <pmoore@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namei.c')
-rw-r--r--fs/namei.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/fs/namei.c b/fs/namei.c
index 73fcf42..71dc1cc 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -212,32 +212,38 @@ getname(const char __user * filename)
return getname_flags(filename, 0, NULL);
}
-/*
- * The "getname_kernel()" interface doesn't do pathnames longer
- * than EMBEDDED_NAME_MAX. Deal with it - you're a kernel user.
- */
struct filename *
getname_kernel(const char * filename)
{
struct filename *result;
- char *kname;
- int len;
-
- len = strlen(filename);
- if (len >= EMBEDDED_NAME_MAX)
- return ERR_PTR(-ENAMETOOLONG);
+ int len = strlen(filename) + 1;
result = __getname();
if (unlikely(!result))
return ERR_PTR(-ENOMEM);
- kname = (char *)result + sizeof(*result);
- result->name = kname;
+ if (len <= EMBEDDED_NAME_MAX) {
+ result->name = (char *)(result) + sizeof(*result);
+ result->separate = false;
+ } else if (len <= PATH_MAX) {
+ struct filename *tmp;
+
+ tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
+ if (unlikely(!tmp)) {
+ __putname(result);
+ return ERR_PTR(-ENOMEM);
+ }
+ tmp->name = (char *)result;
+ tmp->separate = true;
+ result = tmp;
+ } else {
+ __putname(result);
+ return ERR_PTR(-ENAMETOOLONG);
+ }
+ memcpy((char *)result->name, filename, len);
result->uptr = NULL;
result->aname = NULL;
- result->separate = false;
- strlcpy(kname, filename, EMBEDDED_NAME_MAX);
return result;
}
OpenPOWER on IntegriCloud