License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2010-03-23 14:37:36 +00:00
|
|
|
#include <linux/syscalls.h>
|
2011-11-17 04:57:37 +00:00
|
|
|
#include <linux/export.h>
|
2010-03-23 14:37:36 +00:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/file.h>
|
2010-07-07 16:53:25 +00:00
|
|
|
#include <linux/mount.h>
|
2010-03-23 14:37:36 +00:00
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/statfs.h>
|
|
|
|
#include <linux/security.h>
|
|
|
|
#include <linux/uaccess.h>
|
2017-04-08 22:08:15 +00:00
|
|
|
#include <linux/compat.h>
|
2012-01-03 03:28:36 +00:00
|
|
|
#include "internal.h"
|
2010-03-23 14:37:36 +00:00
|
|
|
|
2010-07-07 16:53:25 +00:00
|
|
|
static int flags_by_mnt(int mnt_flags)
|
|
|
|
{
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (mnt_flags & MNT_READONLY)
|
|
|
|
flags |= ST_RDONLY;
|
|
|
|
if (mnt_flags & MNT_NOSUID)
|
|
|
|
flags |= ST_NOSUID;
|
|
|
|
if (mnt_flags & MNT_NODEV)
|
|
|
|
flags |= ST_NODEV;
|
|
|
|
if (mnt_flags & MNT_NOEXEC)
|
|
|
|
flags |= ST_NOEXEC;
|
|
|
|
if (mnt_flags & MNT_NOATIME)
|
|
|
|
flags |= ST_NOATIME;
|
|
|
|
if (mnt_flags & MNT_NODIRATIME)
|
|
|
|
flags |= ST_NODIRATIME;
|
|
|
|
if (mnt_flags & MNT_RELATIME)
|
|
|
|
flags |= ST_RELATIME;
|
2020-08-27 17:09:46 +00:00
|
|
|
if (mnt_flags & MNT_NOSYMFOLLOW)
|
|
|
|
flags |= ST_NOSYMFOLLOW;
|
2010-07-07 16:53:25 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int flags_by_sb(int s_flags)
|
|
|
|
{
|
|
|
|
int flags = 0;
|
2017-11-27 21:05:09 +00:00
|
|
|
if (s_flags & SB_SYNCHRONOUS)
|
2010-07-07 16:53:25 +00:00
|
|
|
flags |= ST_SYNCHRONOUS;
|
2017-11-27 21:05:09 +00:00
|
|
|
if (s_flags & SB_MANDLOCK)
|
2010-07-07 16:53:25 +00:00
|
|
|
flags |= ST_MANDLOCK;
|
2017-11-27 21:05:09 +00:00
|
|
|
if (s_flags & SB_RDONLY)
|
2017-06-29 09:25:40 +00:00
|
|
|
flags |= ST_RDONLY;
|
2010-07-07 16:53:25 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int calculate_f_flags(struct vfsmount *mnt)
|
|
|
|
{
|
|
|
|
return ST_VALID | flags_by_mnt(mnt->mnt_flags) |
|
|
|
|
flags_by_sb(mnt->mnt_sb->s_flags);
|
|
|
|
}
|
|
|
|
|
2012-01-03 03:28:36 +00:00
|
|
|
static int statfs_by_dentry(struct dentry *dentry, struct kstatfs *buf)
|
2010-03-23 14:37:36 +00:00
|
|
|
{
|
2010-07-07 16:53:11 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!dentry->d_sb->s_op->statfs)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(*buf));
|
|
|
|
retval = security_sb_statfs(dentry);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
retval = dentry->d_sb->s_op->statfs(dentry, buf);
|
|
|
|
if (retval == 0 && buf->f_frsize == 0)
|
|
|
|
buf->f_frsize = buf->f_bsize;
|
2010-03-23 14:37:36 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2019-01-10 17:04:38 +00:00
|
|
|
int vfs_get_fsid(struct dentry *dentry, __kernel_fsid_t *fsid)
|
|
|
|
{
|
|
|
|
struct kstatfs st;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = statfs_by_dentry(dentry, &st);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
*fsid = st.f_fsid;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vfs_get_fsid);
|
|
|
|
|
2016-11-21 01:27:12 +00:00
|
|
|
int vfs_statfs(const struct path *path, struct kstatfs *buf)
|
2010-07-07 16:53:11 +00:00
|
|
|
{
|
2010-07-07 16:53:25 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = statfs_by_dentry(path->dentry, buf);
|
|
|
|
if (!error)
|
|
|
|
buf->f_flags = calculate_f_flags(path->mnt);
|
|
|
|
return error;
|
2010-07-07 16:53:11 +00:00
|
|
|
}
|
2010-03-23 14:37:36 +00:00
|
|
|
EXPORT_SYMBOL(vfs_statfs);
|
|
|
|
|
2011-03-12 15:41:39 +00:00
|
|
|
int user_statfs(const char __user *pathname, struct kstatfs *st)
|
2010-03-23 14:37:36 +00:00
|
|
|
{
|
2011-03-12 15:41:39 +00:00
|
|
|
struct path path;
|
2012-12-11 17:10:14 +00:00
|
|
|
int error;
|
|
|
|
unsigned int lookup_flags = LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT;
|
|
|
|
retry:
|
|
|
|
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
|
2011-03-12 15:41:39 +00:00
|
|
|
if (!error) {
|
|
|
|
error = vfs_statfs(&path, st);
|
|
|
|
path_put(&path);
|
2012-12-11 17:10:14 +00:00
|
|
|
if (retry_estale(error, lookup_flags)) {
|
|
|
|
lookup_flags |= LOOKUP_REVAL;
|
|
|
|
goto retry;
|
|
|
|
}
|
2011-03-12 15:41:39 +00:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
2010-03-23 14:37:36 +00:00
|
|
|
|
2011-03-12 15:41:39 +00:00
|
|
|
int fd_statfs(int fd, struct kstatfs *st)
|
|
|
|
{
|
2013-09-30 15:35:10 +00:00
|
|
|
struct fd f = fdget_raw(fd);
|
2011-03-12 15:41:39 +00:00
|
|
|
int error = -EBADF;
|
2012-08-28 16:52:22 +00:00
|
|
|
if (f.file) {
|
|
|
|
error = vfs_statfs(&f.file->f_path, st);
|
|
|
|
fdput(f);
|
2011-03-12 15:41:39 +00:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
2010-03-23 14:37:36 +00:00
|
|
|
|
2011-03-12 15:41:39 +00:00
|
|
|
static int do_statfs_native(struct kstatfs *st, struct statfs __user *p)
|
|
|
|
{
|
|
|
|
struct statfs buf;
|
|
|
|
|
|
|
|
if (sizeof(buf) == sizeof(*st))
|
|
|
|
memcpy(&buf, st, sizeof(*st));
|
2010-03-23 14:37:36 +00:00
|
|
|
else {
|
2023-05-04 14:40:20 +00:00
|
|
|
memset(&buf, 0, sizeof(buf));
|
2011-03-12 15:41:39 +00:00
|
|
|
if (sizeof buf.f_blocks == 4) {
|
|
|
|
if ((st->f_blocks | st->f_bfree | st->f_bavail |
|
|
|
|
st->f_bsize | st->f_frsize) &
|
2010-03-23 14:37:36 +00:00
|
|
|
0xffffffff00000000ULL)
|
|
|
|
return -EOVERFLOW;
|
|
|
|
/*
|
|
|
|
* f_files and f_ffree may be -1; it's okay to stuff
|
|
|
|
* that into 32 bits
|
|
|
|
*/
|
2011-03-12 15:41:39 +00:00
|
|
|
if (st->f_files != -1 &&
|
|
|
|
(st->f_files & 0xffffffff00000000ULL))
|
2010-03-23 14:37:36 +00:00
|
|
|
return -EOVERFLOW;
|
2011-03-12 15:41:39 +00:00
|
|
|
if (st->f_ffree != -1 &&
|
|
|
|
(st->f_ffree & 0xffffffff00000000ULL))
|
2010-03-23 14:37:36 +00:00
|
|
|
return -EOVERFLOW;
|
|
|
|
}
|
|
|
|
|
2011-03-12 15:41:39 +00:00
|
|
|
buf.f_type = st->f_type;
|
|
|
|
buf.f_bsize = st->f_bsize;
|
|
|
|
buf.f_blocks = st->f_blocks;
|
|
|
|
buf.f_bfree = st->f_bfree;
|
|
|
|
buf.f_bavail = st->f_bavail;
|
|
|
|
buf.f_files = st->f_files;
|
|
|
|
buf.f_ffree = st->f_ffree;
|
|
|
|
buf.f_fsid = st->f_fsid;
|
|
|
|
buf.f_namelen = st->f_namelen;
|
|
|
|
buf.f_frsize = st->f_frsize;
|
|
|
|
buf.f_flags = st->f_flags;
|
2010-03-23 14:37:36 +00:00
|
|
|
}
|
2011-03-12 15:41:39 +00:00
|
|
|
if (copy_to_user(p, &buf, sizeof(buf)))
|
|
|
|
return -EFAULT;
|
2010-03-23 14:37:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-12 15:41:39 +00:00
|
|
|
static int do_statfs64(struct kstatfs *st, struct statfs64 __user *p)
|
2010-03-23 14:37:36 +00:00
|
|
|
{
|
2011-03-12 15:41:39 +00:00
|
|
|
struct statfs64 buf;
|
|
|
|
if (sizeof(buf) == sizeof(*st))
|
|
|
|
memcpy(&buf, st, sizeof(*st));
|
2010-03-23 14:37:36 +00:00
|
|
|
else {
|
2023-05-04 14:40:20 +00:00
|
|
|
memset(&buf, 0, sizeof(buf));
|
2011-03-12 15:41:39 +00:00
|
|
|
buf.f_type = st->f_type;
|
|
|
|
buf.f_bsize = st->f_bsize;
|
|
|
|
buf.f_blocks = st->f_blocks;
|
|
|
|
buf.f_bfree = st->f_bfree;
|
|
|
|
buf.f_bavail = st->f_bavail;
|
|
|
|
buf.f_files = st->f_files;
|
|
|
|
buf.f_ffree = st->f_ffree;
|
|
|
|
buf.f_fsid = st->f_fsid;
|
|
|
|
buf.f_namelen = st->f_namelen;
|
|
|
|
buf.f_frsize = st->f_frsize;
|
|
|
|
buf.f_flags = st->f_flags;
|
2010-03-23 14:37:36 +00:00
|
|
|
}
|
2011-03-12 15:41:39 +00:00
|
|
|
if (copy_to_user(p, &buf, sizeof(buf)))
|
|
|
|
return -EFAULT;
|
2010-03-23 14:37:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct statfs __user *, buf)
|
|
|
|
{
|
2011-03-12 15:41:39 +00:00
|
|
|
struct kstatfs st;
|
|
|
|
int error = user_statfs(pathname, &st);
|
|
|
|
if (!error)
|
|
|
|
error = do_statfs_native(&st, buf);
|
2010-03-23 14:37:36 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCALL_DEFINE3(statfs64, const char __user *, pathname, size_t, sz, struct statfs64 __user *, buf)
|
|
|
|
{
|
2011-03-12 15:41:39 +00:00
|
|
|
struct kstatfs st;
|
|
|
|
int error;
|
2010-03-23 14:37:36 +00:00
|
|
|
if (sz != sizeof(*buf))
|
|
|
|
return -EINVAL;
|
2011-03-12 15:41:39 +00:00
|
|
|
error = user_statfs(pathname, &st);
|
|
|
|
if (!error)
|
|
|
|
error = do_statfs64(&st, buf);
|
2010-03-23 14:37:36 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct statfs __user *, buf)
|
|
|
|
{
|
2011-03-12 15:41:39 +00:00
|
|
|
struct kstatfs st;
|
|
|
|
int error = fd_statfs(fd, &st);
|
|
|
|
if (!error)
|
|
|
|
error = do_statfs_native(&st, buf);
|
2010-03-23 14:37:36 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, size_t, sz, struct statfs64 __user *, buf)
|
|
|
|
{
|
2011-03-12 15:41:39 +00:00
|
|
|
struct kstatfs st;
|
2010-03-23 14:37:36 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sz != sizeof(*buf))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-03-12 15:41:39 +00:00
|
|
|
error = fd_statfs(fd, &st);
|
|
|
|
if (!error)
|
|
|
|
error = do_statfs64(&st, buf);
|
2010-03-23 14:37:36 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-10-15 03:00:54 +00:00
|
|
|
static int vfs_ustat(dev_t dev, struct kstatfs *sbuf)
|
2010-03-23 14:37:36 +00:00
|
|
|
{
|
2020-11-23 12:38:40 +00:00
|
|
|
struct super_block *s = user_get_super(dev, false);
|
2010-03-23 14:37:36 +00:00
|
|
|
int err;
|
|
|
|
if (!s)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-01-03 03:28:36 +00:00
|
|
|
err = statfs_by_dentry(s->s_root, sbuf);
|
2010-03-23 14:37:36 +00:00
|
|
|
drop_super(s);
|
2012-01-03 03:28:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf)
|
|
|
|
{
|
|
|
|
struct ustat tmp;
|
|
|
|
struct kstatfs sbuf;
|
|
|
|
int err = vfs_ustat(new_decode_dev(dev), &sbuf);
|
2010-03-23 14:37:36 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
memset(&tmp,0,sizeof(struct ustat));
|
|
|
|
tmp.f_tfree = sbuf.f_bfree;
|
2021-02-10 20:51:02 +00:00
|
|
|
if (IS_ENABLED(CONFIG_ARCH_32BIT_USTAT_F_TINODE))
|
|
|
|
tmp.f_tinode = min_t(u64, sbuf.f_ffree, UINT_MAX);
|
|
|
|
else
|
|
|
|
tmp.f_tinode = sbuf.f_ffree;
|
2010-03-23 14:37:36 +00:00
|
|
|
|
|
|
|
return copy_to_user(ubuf, &tmp, sizeof(struct ustat)) ? -EFAULT : 0;
|
|
|
|
}
|
2017-04-08 22:08:15 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf)
|
|
|
|
{
|
2017-06-04 01:41:51 +00:00
|
|
|
struct compat_statfs buf;
|
2017-04-08 22:08:15 +00:00
|
|
|
if (sizeof ubuf->f_blocks == 4) {
|
|
|
|
if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail |
|
|
|
|
kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
|
|
|
|
return -EOVERFLOW;
|
|
|
|
/* f_files and f_ffree may be -1; it's okay
|
|
|
|
* to stuff that into 32 bits */
|
|
|
|
if (kbuf->f_files != 0xffffffffffffffffULL
|
|
|
|
&& (kbuf->f_files & 0xffffffff00000000ULL))
|
|
|
|
return -EOVERFLOW;
|
|
|
|
if (kbuf->f_ffree != 0xffffffffffffffffULL
|
|
|
|
&& (kbuf->f_ffree & 0xffffffff00000000ULL))
|
|
|
|
return -EOVERFLOW;
|
|
|
|
}
|
2017-06-04 01:41:51 +00:00
|
|
|
memset(&buf, 0, sizeof(struct compat_statfs));
|
|
|
|
buf.f_type = kbuf->f_type;
|
|
|
|
buf.f_bsize = kbuf->f_bsize;
|
|
|
|
buf.f_blocks = kbuf->f_blocks;
|
|
|
|
buf.f_bfree = kbuf->f_bfree;
|
|
|
|
buf.f_bavail = kbuf->f_bavail;
|
|
|
|
buf.f_files = kbuf->f_files;
|
|
|
|
buf.f_ffree = kbuf->f_ffree;
|
|
|
|
buf.f_namelen = kbuf->f_namelen;
|
|
|
|
buf.f_fsid.val[0] = kbuf->f_fsid.val[0];
|
|
|
|
buf.f_fsid.val[1] = kbuf->f_fsid.val[1];
|
|
|
|
buf.f_frsize = kbuf->f_frsize;
|
|
|
|
buf.f_flags = kbuf->f_flags;
|
|
|
|
if (copy_to_user(ubuf, &buf, sizeof(struct compat_statfs)))
|
2017-04-08 22:08:15 +00:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following statfs calls are copies of code from fs/statfs.c and
|
|
|
|
* should be checked against those from time to time
|
|
|
|
*/
|
|
|
|
COMPAT_SYSCALL_DEFINE2(statfs, const char __user *, pathname, struct compat_statfs __user *, buf)
|
|
|
|
{
|
|
|
|
struct kstatfs tmp;
|
|
|
|
int error = user_statfs(pathname, &tmp);
|
|
|
|
if (!error)
|
|
|
|
error = put_compat_statfs(buf, &tmp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *, buf)
|
|
|
|
{
|
|
|
|
struct kstatfs tmp;
|
|
|
|
int error = fd_statfs(fd, &tmp);
|
|
|
|
if (!error)
|
|
|
|
error = put_compat_statfs(buf, &tmp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
|
|
|
|
{
|
2017-06-04 01:41:51 +00:00
|
|
|
struct compat_statfs64 buf;
|
vfs: Fix EOVERFLOW testing in put_compat_statfs64
Today, put_compat_statfs64() disallows nearly any field value over
2^32 if f_bsize is only 32 bits, but that makes no sense.
compat_statfs64 is there for the explicit purpose of providing 64-bit
fields for f_files, f_ffree, etc. And f_bsize is always only 32 bits.
As a result, 32-bit userspace gets -EOVERFLOW for i.e. large file
counts even with -D_FILE_OFFSET_BITS=64 set.
In reality, only f_bsize and f_frsize can legitimately overflow
(fields like f_type and f_namelen should never be large), so test
only those fields.
This bug was discussed at length some time ago, and this is the proposal
Al suggested at https://lkml.org/lkml/2018/8/6/640. It seemed to get
dropped amid the discussion of other related changes, but this
part seems obviously correct on its own, so I've picked it up and
sent it, for expediency.
Fixes: 64d2ab32efe3 ("vfs: fix put_compat_statfs64() does not handle errors")
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-02 21:17:54 +00:00
|
|
|
|
|
|
|
if ((kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
|
|
|
|
return -EOVERFLOW;
|
|
|
|
|
2017-06-04 01:41:51 +00:00
|
|
|
memset(&buf, 0, sizeof(struct compat_statfs64));
|
|
|
|
buf.f_type = kbuf->f_type;
|
|
|
|
buf.f_bsize = kbuf->f_bsize;
|
|
|
|
buf.f_blocks = kbuf->f_blocks;
|
|
|
|
buf.f_bfree = kbuf->f_bfree;
|
|
|
|
buf.f_bavail = kbuf->f_bavail;
|
|
|
|
buf.f_files = kbuf->f_files;
|
|
|
|
buf.f_ffree = kbuf->f_ffree;
|
|
|
|
buf.f_namelen = kbuf->f_namelen;
|
|
|
|
buf.f_fsid.val[0] = kbuf->f_fsid.val[0];
|
|
|
|
buf.f_fsid.val[1] = kbuf->f_fsid.val[1];
|
|
|
|
buf.f_frsize = kbuf->f_frsize;
|
|
|
|
buf.f_flags = kbuf->f_flags;
|
|
|
|
if (copy_to_user(ubuf, &buf, sizeof(struct compat_statfs64)))
|
2017-04-08 22:08:15 +00:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:56:51 +00:00
|
|
|
int kcompat_sys_statfs64(const char __user * pathname, compat_size_t sz, struct compat_statfs64 __user * buf)
|
2017-04-08 22:08:15 +00:00
|
|
|
{
|
|
|
|
struct kstatfs tmp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sz != sizeof(*buf))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
error = user_statfs(pathname, &tmp);
|
|
|
|
if (!error)
|
|
|
|
error = put_compat_statfs64(buf, &tmp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:56:51 +00:00
|
|
|
COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, sz, struct compat_statfs64 __user *, buf)
|
|
|
|
{
|
|
|
|
return kcompat_sys_statfs64(pathname, sz, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kcompat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user * buf)
|
2017-04-08 22:08:15 +00:00
|
|
|
{
|
|
|
|
struct kstatfs tmp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sz != sizeof(*buf))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
error = fd_statfs(fd, &tmp);
|
|
|
|
if (!error)
|
|
|
|
error = put_compat_statfs64(buf, &tmp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:56:51 +00:00
|
|
|
COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct compat_statfs64 __user *, buf)
|
|
|
|
{
|
|
|
|
return kcompat_sys_fstatfs64(fd, sz, buf);
|
|
|
|
}
|
|
|
|
|
2017-04-08 22:08:15 +00:00
|
|
|
/*
|
|
|
|
* This is a copy of sys_ustat, just dealing with a structure layout.
|
|
|
|
* Given how simple this syscall is that apporach is more maintainable
|
|
|
|
* than the various conversion hacks.
|
|
|
|
*/
|
|
|
|
COMPAT_SYSCALL_DEFINE2(ustat, unsigned, dev, struct compat_ustat __user *, u)
|
|
|
|
{
|
|
|
|
struct compat_ustat tmp;
|
|
|
|
struct kstatfs sbuf;
|
|
|
|
int err = vfs_ustat(new_decode_dev(dev), &sbuf);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
memset(&tmp, 0, sizeof(struct compat_ustat));
|
|
|
|
tmp.f_tfree = sbuf.f_bfree;
|
|
|
|
tmp.f_tinode = sbuf.f_ffree;
|
|
|
|
if (copy_to_user(u, &tmp, sizeof(struct compat_ustat)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|