2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* linux/fs/hfsplus/options.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001
|
|
|
|
* Brad Boyer (flar@allandria.com)
|
|
|
|
* (C) 2003 Ardis Technologies <roman@ardistech.com>
|
|
|
|
*
|
|
|
|
* Option parsing
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/parser.h>
|
|
|
|
#include <linux/nls.h>
|
2005-09-06 22:18:48 +00:00
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/seq_file.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "hfsplus_fs.h"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
opt_creator, opt_type,
|
|
|
|
opt_umask, opt_uid, opt_gid,
|
|
|
|
opt_part, opt_session, opt_nls,
|
|
|
|
opt_nodecompose, opt_decompose,
|
2010-11-23 13:38:21 +00:00
|
|
|
opt_barrier, opt_nobarrier,
|
2005-11-30 03:34:41 +00:00
|
|
|
opt_force, opt_err
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2008-10-13 09:46:57 +00:00
|
|
|
static const match_table_t tokens = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ opt_creator, "creator=%s" },
|
|
|
|
{ opt_type, "type=%s" },
|
|
|
|
{ opt_umask, "umask=%o" },
|
|
|
|
{ opt_uid, "uid=%u" },
|
|
|
|
{ opt_gid, "gid=%u" },
|
|
|
|
{ opt_part, "part=%u" },
|
|
|
|
{ opt_session, "session=%u" },
|
|
|
|
{ opt_nls, "nls=%s" },
|
|
|
|
{ opt_decompose, "decompose" },
|
|
|
|
{ opt_nodecompose, "nodecompose" },
|
2010-11-23 13:38:21 +00:00
|
|
|
{ opt_barrier, "barrier" },
|
|
|
|
{ opt_nobarrier, "nobarrier" },
|
2005-11-30 03:34:41 +00:00
|
|
|
{ opt_force, "force" },
|
2005-04-16 22:20:36 +00:00
|
|
|
{ opt_err, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialize an options object to reasonable defaults */
|
2005-09-06 22:18:48 +00:00
|
|
|
void hfsplus_fill_defaults(struct hfsplus_sb_info *opts)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if (!opts)
|
|
|
|
return;
|
|
|
|
|
|
|
|
opts->creator = HFSPLUS_DEF_CR_TYPE;
|
|
|
|
opts->type = HFSPLUS_DEF_CR_TYPE;
|
2009-03-29 23:08:22 +00:00
|
|
|
opts->umask = current_umask();
|
2008-11-13 23:38:54 +00:00
|
|
|
opts->uid = current_uid();
|
|
|
|
opts->gid = current_gid();
|
2005-04-16 22:20:36 +00:00
|
|
|
opts->part = -1;
|
|
|
|
opts->session = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert a "four byte character" to a 32 bit int with error checks */
|
|
|
|
static inline int match_fourchar(substring_t *arg, u32 *result)
|
|
|
|
{
|
|
|
|
if (arg->to - arg->from != 4)
|
|
|
|
return -EINVAL;
|
|
|
|
memcpy(result, arg->from, 4);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-07 22:01:17 +00:00
|
|
|
int hfsplus_parse_options_remount(char *input, int *force)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
substring_t args[MAX_OPT_ARGS];
|
|
|
|
int token;
|
|
|
|
|
|
|
|
if (!input)
|
hfsplus: fix remount issue
Current implementation of HFS+ driver has small issue with remount
option. Namely, for example, you are unable to remount from RO mode
into RW mode by means of command "mount -o remount,rw /dev/loop0
/mnt/hfsplus". Trying to execute sequence of commands results in an
error message:
mount /dev/loop0 /mnt/hfsplus
mount -o remount,ro /dev/loop0 /mnt/hfsplus
mount -o remount,rw /dev/loop0 /mnt/hfsplus
mount: you must specify the filesystem type
mount -t hfsplus -o remount,rw /dev/loop0 /mnt/hfsplus
mount: /mnt/hfsplus not mounted or bad option
The reason of such issue is failure of mount syscall:
mount("/dev/loop0", "/mnt/hfsplus", 0x2282a60, MS_MGC_VAL|MS_REMOUNT, NULL) = -1 EINVAL (Invalid argument)
Namely, hfsplus_parse_options_remount() method receives empty "input"
argument and return false in such case. As a result, hfsplus_remount()
returns -EINVAL error code.
This patch fixes the issue by means of return true for the case of empty
"input" argument in hfsplus_parse_options_remount() method.
Signed-off-by: Vyacheslav Dubeyko <slava@dubeyko.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-03-03 23:38:35 +00:00
|
|
|
return 1;
|
2010-11-07 22:01:17 +00:00
|
|
|
|
|
|
|
while ((p = strsep(&input, ",")) != NULL) {
|
|
|
|
if (!*p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
token = match_token(p, tokens, args);
|
|
|
|
switch (token) {
|
|
|
|
case opt_force:
|
|
|
|
*force = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Parse options from mount. Returns 0 on failure */
|
|
|
|
/* input is the options passed to mount() as a string */
|
2005-09-06 22:18:48 +00:00
|
|
|
int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
substring_t args[MAX_OPT_ARGS];
|
|
|
|
int tmp, token;
|
|
|
|
|
|
|
|
if (!input)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
while ((p = strsep(&input, ",")) != NULL) {
|
|
|
|
if (!*p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
token = match_token(p, tokens, args);
|
|
|
|
switch (token) {
|
|
|
|
case opt_creator:
|
|
|
|
if (match_fourchar(&args[0], &sbi->creator)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("creator requires a 4 character value\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case opt_type:
|
|
|
|
if (match_fourchar(&args[0], &sbi->type)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("type requires a 4 character value\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case opt_umask:
|
|
|
|
if (match_octal(&args[0], &tmp)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("umask requires a value\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
sbi->umask = (umode_t)tmp;
|
|
|
|
break;
|
|
|
|
case opt_uid:
|
|
|
|
if (match_int(&args[0], &tmp)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("uid requires an argument\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-02-08 00:27:17 +00:00
|
|
|
sbi->uid = make_kuid(current_user_ns(), (uid_t)tmp);
|
|
|
|
if (!uid_valid(sbi->uid)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("invalid uid specified\n");
|
2012-02-08 00:27:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case opt_gid:
|
|
|
|
if (match_int(&args[0], &tmp)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("gid requires an argument\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-02-08 00:27:17 +00:00
|
|
|
sbi->gid = make_kgid(current_user_ns(), (gid_t)tmp);
|
|
|
|
if (!gid_valid(sbi->gid)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("invalid gid specified\n");
|
2012-02-08 00:27:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case opt_part:
|
|
|
|
if (match_int(&args[0], &sbi->part)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("part requires an argument\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case opt_session:
|
|
|
|
if (match_int(&args[0], &sbi->session)) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("session requires an argument\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case opt_nls:
|
|
|
|
if (sbi->nls) {
|
2013-04-30 22:27:55 +00:00
|
|
|
pr_err("unable to change nls mapping\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
p = match_strdup(&args[0]);
|
2008-04-29 07:59:08 +00:00
|
|
|
if (p)
|
|
|
|
sbi->nls = load_nls(p);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!sbi->nls) {
|
2014-06-06 21:36:26 +00:00
|
|
|
pr_err("unable to load nls mapping \"%s\"\n",
|
|
|
|
p);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
kfree(p);
|
|
|
|
break;
|
|
|
|
case opt_decompose:
|
2010-10-01 03:45:20 +00:00
|
|
|
clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case opt_nodecompose:
|
2010-10-01 03:45:20 +00:00
|
|
|
set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2010-11-23 13:38:21 +00:00
|
|
|
case opt_barrier:
|
|
|
|
clear_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
|
|
|
|
break;
|
|
|
|
case opt_nobarrier:
|
|
|
|
set_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags);
|
|
|
|
break;
|
2005-11-30 03:34:41 +00:00
|
|
|
case opt_force:
|
2010-10-01 03:45:20 +00:00
|
|
|
set_bit(HFSPLUS_SB_FORCE, &sbi->flags);
|
2005-11-30 03:34:41 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (!sbi->nls) {
|
|
|
|
/* try utf8 first, as this is the old default behaviour */
|
|
|
|
sbi->nls = load_nls("utf8");
|
|
|
|
if (!sbi->nls)
|
|
|
|
sbi->nls = load_nls_default();
|
|
|
|
if (!sbi->nls)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2005-09-06 22:18:48 +00:00
|
|
|
|
2011-12-09 02:32:45 +00:00
|
|
|
int hfsplus_show_options(struct seq_file *seq, struct dentry *root)
|
2005-09-06 22:18:48 +00:00
|
|
|
{
|
2011-12-09 02:32:45 +00:00
|
|
|
struct hfsplus_sb_info *sbi = HFSPLUS_SB(root->d_sb);
|
2005-09-06 22:18:48 +00:00
|
|
|
|
|
|
|
if (sbi->creator != HFSPLUS_DEF_CR_TYPE)
|
fs: create and use seq_show_option for escaping
Many file systems that implement the show_options hook fail to correctly
escape their output which could lead to unescaped characters (e.g. new
lines) leaking into /proc/mounts and /proc/[pid]/mountinfo files. This
could lead to confusion, spoofed entries (resulting in things like
systemd issuing false d-bus "mount" notifications), and who knows what
else. This looks like it would only be the root user stepping on
themselves, but it's possible weird things could happen in containers or
in other situations with delegated mount privileges.
Here's an example using overlay with setuid fusermount trusting the
contents of /proc/mounts (via the /etc/mtab symlink). Imagine the use
of "sudo" is something more sneaky:
$ BASE="ovl"
$ MNT="$BASE/mnt"
$ LOW="$BASE/lower"
$ UP="$BASE/upper"
$ WORK="$BASE/work/ 0 0
none /proc fuse.pwn user_id=1000"
$ mkdir -p "$LOW" "$UP" "$WORK"
$ sudo mount -t overlay -o "lowerdir=$LOW,upperdir=$UP,workdir=$WORK" none /mnt
$ cat /proc/mounts
none /root/ovl/mnt overlay rw,relatime,lowerdir=ovl/lower,upperdir=ovl/upper,workdir=ovl/work/ 0 0
none /proc fuse.pwn user_id=1000 0 0
$ fusermount -u /proc
$ cat /proc/mounts
cat: /proc/mounts: No such file or directory
This fixes the problem by adding new seq_show_option and
seq_show_option_n helpers, and updating the vulnerable show_option
handlers to use them as needed. Some, like SELinux, need to be open
coded due to unusual existing escape mechanisms.
[akpm@linux-foundation.org: add lost chunk, per Kees]
[keescook@chromium.org: seq_show_option should be using const parameters]
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Acked-by: Jan Kara <jack@suse.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Cc: J. R. Okajima <hooanon05g@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-09-04 22:44:57 +00:00
|
|
|
seq_show_option_n(seq, "creator", (char *)&sbi->creator, 4);
|
2005-09-06 22:18:48 +00:00
|
|
|
if (sbi->type != HFSPLUS_DEF_CR_TYPE)
|
fs: create and use seq_show_option for escaping
Many file systems that implement the show_options hook fail to correctly
escape their output which could lead to unescaped characters (e.g. new
lines) leaking into /proc/mounts and /proc/[pid]/mountinfo files. This
could lead to confusion, spoofed entries (resulting in things like
systemd issuing false d-bus "mount" notifications), and who knows what
else. This looks like it would only be the root user stepping on
themselves, but it's possible weird things could happen in containers or
in other situations with delegated mount privileges.
Here's an example using overlay with setuid fusermount trusting the
contents of /proc/mounts (via the /etc/mtab symlink). Imagine the use
of "sudo" is something more sneaky:
$ BASE="ovl"
$ MNT="$BASE/mnt"
$ LOW="$BASE/lower"
$ UP="$BASE/upper"
$ WORK="$BASE/work/ 0 0
none /proc fuse.pwn user_id=1000"
$ mkdir -p "$LOW" "$UP" "$WORK"
$ sudo mount -t overlay -o "lowerdir=$LOW,upperdir=$UP,workdir=$WORK" none /mnt
$ cat /proc/mounts
none /root/ovl/mnt overlay rw,relatime,lowerdir=ovl/lower,upperdir=ovl/upper,workdir=ovl/work/ 0 0
none /proc fuse.pwn user_id=1000 0 0
$ fusermount -u /proc
$ cat /proc/mounts
cat: /proc/mounts: No such file or directory
This fixes the problem by adding new seq_show_option and
seq_show_option_n helpers, and updating the vulnerable show_option
handlers to use them as needed. Some, like SELinux, need to be open
coded due to unusual existing escape mechanisms.
[akpm@linux-foundation.org: add lost chunk, per Kees]
[keescook@chromium.org: seq_show_option should be using const parameters]
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Acked-by: Jan Kara <jack@suse.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Cc: J. R. Okajima <hooanon05g@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-09-04 22:44:57 +00:00
|
|
|
seq_show_option_n(seq, "type", (char *)&sbi->type, 4);
|
2010-12-16 16:08:38 +00:00
|
|
|
seq_printf(seq, ",umask=%o,uid=%u,gid=%u", sbi->umask,
|
2012-02-08 00:27:17 +00:00
|
|
|
from_kuid_munged(&init_user_ns, sbi->uid),
|
|
|
|
from_kgid_munged(&init_user_ns, sbi->gid));
|
2005-09-06 22:18:48 +00:00
|
|
|
if (sbi->part >= 0)
|
|
|
|
seq_printf(seq, ",part=%u", sbi->part);
|
|
|
|
if (sbi->session >= 0)
|
|
|
|
seq_printf(seq, ",session=%u", sbi->session);
|
|
|
|
if (sbi->nls)
|
|
|
|
seq_printf(seq, ",nls=%s", sbi->nls->charset);
|
2010-10-01 03:45:20 +00:00
|
|
|
if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags))
|
2014-06-06 21:36:26 +00:00
|
|
|
seq_puts(seq, ",nodecompose");
|
2010-11-23 13:38:21 +00:00
|
|
|
if (test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
|
2014-06-06 21:36:26 +00:00
|
|
|
seq_puts(seq, ",nobarrier");
|
2005-09-06 22:18:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|