mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-28 09:31:14 +00:00
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>
This commit is contained in:
parent
46359295a3
commit
a068acf2ee
15 changed files with 71 additions and 30 deletions
|
@ -149,6 +149,41 @@ static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* seq_show_options - display mount options with appropriate escapes.
|
||||
* @m: the seq_file handle
|
||||
* @name: the mount option name
|
||||
* @value: the mount option name's value, can be NULL
|
||||
*/
|
||||
static inline void seq_show_option(struct seq_file *m, const char *name,
|
||||
const char *value)
|
||||
{
|
||||
seq_putc(m, ',');
|
||||
seq_escape(m, name, ",= \t\n\\");
|
||||
if (value) {
|
||||
seq_putc(m, '=');
|
||||
seq_escape(m, value, ", \t\n\\");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* seq_show_option_n - display mount options with appropriate escapes
|
||||
* where @value must be a specific length.
|
||||
* @m: the seq_file handle
|
||||
* @name: the mount option name
|
||||
* @value: the mount option name's value, cannot be NULL
|
||||
* @length: the length of @value to display
|
||||
*
|
||||
* This is a macro since this uses "length" to define the size of the
|
||||
* stack buffer.
|
||||
*/
|
||||
#define seq_show_option_n(m, name, value, length) { \
|
||||
char val_buf[length + 1]; \
|
||||
strncpy(val_buf, value, length); \
|
||||
val_buf[length] = '\0'; \
|
||||
seq_show_option(m, name, val_buf); \
|
||||
}
|
||||
|
||||
#define SEQ_START_TOKEN ((void *)1)
|
||||
/*
|
||||
* Helpers for iteration over list_head-s in seq_files
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue