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 17:07:57 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-01-29 16:13:26 +03:00
|
|
|
#include <linux/syscalls.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/exportfs.h>
|
2011-01-29 16:13:26 +03:00
|
|
|
#include <linux/fs_struct.h>
|
|
|
|
#include <linux/fsnotify.h>
|
2011-04-15 02:22:16 +04:00
|
|
|
#include <linux/personality.h>
|
2016-12-24 22:46:01 +03:00
|
|
|
#include <linux/uaccess.h>
|
2017-04-09 01:16:56 +03:00
|
|
|
#include <linux/compat.h>
|
2011-01-29 16:13:26 +03:00
|
|
|
#include "internal.h"
|
2011-11-25 09:50:41 +04:00
|
|
|
#include "mount.h"
|
2011-01-29 16:13:26 +03:00
|
|
|
|
|
|
|
static long do_sys_name_to_handle(struct path *path,
|
|
|
|
struct file_handle __user *ufh,
|
|
|
|
int __user *mnt_id)
|
|
|
|
{
|
|
|
|
long retval;
|
|
|
|
struct file_handle f_handle;
|
|
|
|
int handle_dwords, handle_bytes;
|
|
|
|
struct file_handle *handle = NULL;
|
|
|
|
|
|
|
|
/*
|
2012-09-20 05:48:00 +04:00
|
|
|
* We need to make sure whether the file system
|
2011-01-29 16:13:26 +03:00
|
|
|
* support decoding of the file handle
|
|
|
|
*/
|
2011-12-08 03:16:57 +04:00
|
|
|
if (!path->dentry->d_sb->s_export_op ||
|
|
|
|
!path->dentry->d_sb->s_export_op->fh_to_dentry)
|
2011-01-29 16:13:26 +03:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (f_handle.handle_bytes > MAX_HANDLE_SZ)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2024-01-19 18:39:06 +03:00
|
|
|
handle = kzalloc(sizeof(struct file_handle) + f_handle.handle_bytes,
|
2011-01-29 16:13:26 +03:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!handle)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-09-20 05:48:00 +04:00
|
|
|
/* convert handle size to multiple of sizeof(u32) */
|
2011-01-29 16:13:26 +03:00
|
|
|
handle_dwords = f_handle.handle_bytes >> 2;
|
|
|
|
|
|
|
|
/* we ask for a non connected handle */
|
|
|
|
retval = exportfs_encode_fh(path->dentry,
|
|
|
|
(struct fid *)handle->f_handle,
|
|
|
|
&handle_dwords, 0);
|
|
|
|
handle->handle_type = retval;
|
|
|
|
/* convert handle size to bytes */
|
|
|
|
handle_bytes = handle_dwords * sizeof(u32);
|
|
|
|
handle->handle_bytes = handle_bytes;
|
|
|
|
if ((handle->handle_bytes > f_handle.handle_bytes) ||
|
2012-08-29 18:10:10 +04:00
|
|
|
(retval == FILEID_INVALID) || (retval == -ENOSPC)) {
|
2011-01-29 16:13:26 +03:00
|
|
|
/* As per old exportfs_encode_fh documentation
|
|
|
|
* we could return ENOSPC to indicate overflow
|
|
|
|
* But file system returned 255 always. So handle
|
|
|
|
* both the values
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* set the handle size to zero so we copy only
|
|
|
|
* non variable part of the file_handle
|
|
|
|
*/
|
|
|
|
handle_bytes = 0;
|
|
|
|
retval = -EOVERFLOW;
|
|
|
|
} else
|
|
|
|
retval = 0;
|
|
|
|
/* copy the mount id */
|
2017-06-11 05:50:31 +03:00
|
|
|
if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
|
2011-01-29 16:13:26 +03:00
|
|
|
copy_to_user(ufh, handle,
|
|
|
|
sizeof(struct file_handle) + handle_bytes))
|
|
|
|
retval = -EFAULT;
|
|
|
|
kfree(handle);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sys_name_to_handle_at: convert name to handle
|
|
|
|
* @dfd: directory relative to which name is interpreted if not absolute
|
|
|
|
* @name: name that should be converted to handle.
|
|
|
|
* @handle: resulting file handle
|
|
|
|
* @mnt_id: mount id of the file system containing the file
|
|
|
|
* @flag: flag value to indicate whether to follow symlink or not
|
|
|
|
*
|
|
|
|
* @handle->handle_size indicate the space available to store the
|
|
|
|
* variable part of the file handle in bytes. If there is not
|
|
|
|
* enough space, the field is updated to return the minimum
|
|
|
|
* value required.
|
|
|
|
*/
|
|
|
|
SYSCALL_DEFINE5(name_to_handle_at, int, dfd, const char __user *, name,
|
|
|
|
struct file_handle __user *, handle, int __user *, mnt_id,
|
|
|
|
int, flag)
|
|
|
|
{
|
|
|
|
struct path path;
|
|
|
|
int lookup_flags;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if ((flag & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lookup_flags = (flag & AT_SYMLINK_FOLLOW) ? LOOKUP_FOLLOW : 0;
|
|
|
|
if (flag & AT_EMPTY_PATH)
|
|
|
|
lookup_flags |= LOOKUP_EMPTY;
|
|
|
|
err = user_path_at(dfd, name, lookup_flags, &path);
|
|
|
|
if (!err) {
|
|
|
|
err = do_sys_name_to_handle(&path, handle, mnt_id);
|
|
|
|
path_put(&path);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
2011-01-29 16:13:26 +03:00
|
|
|
|
|
|
|
static struct vfsmount *get_vfsmount_from_fd(int fd)
|
|
|
|
{
|
2012-08-28 20:52:22 +04:00
|
|
|
struct vfsmount *mnt;
|
2011-01-29 16:13:26 +03:00
|
|
|
|
|
|
|
if (fd == AT_FDCWD) {
|
|
|
|
struct fs_struct *fs = current->fs;
|
|
|
|
spin_lock(&fs->lock);
|
2012-08-28 20:52:22 +04:00
|
|
|
mnt = mntget(fs->pwd.mnt);
|
2011-01-29 16:13:26 +03:00
|
|
|
spin_unlock(&fs->lock);
|
|
|
|
} else {
|
2012-08-28 20:52:22 +04:00
|
|
|
struct fd f = fdget(fd);
|
|
|
|
if (!f.file)
|
2011-01-29 16:13:26 +03:00
|
|
|
return ERR_PTR(-EBADF);
|
2012-08-28 20:52:22 +04:00
|
|
|
mnt = mntget(f.file->f_path.mnt);
|
|
|
|
fdput(f);
|
2011-01-29 16:13:26 +03:00
|
|
|
}
|
2012-08-28 20:52:22 +04:00
|
|
|
return mnt;
|
2011-01-29 16:13:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vfs_dentry_acceptable(void *context, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_handle_to_path(int mountdirfd, struct file_handle *handle,
|
|
|
|
struct path *path)
|
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
int handle_dwords;
|
|
|
|
|
|
|
|
path->mnt = get_vfsmount_from_fd(mountdirfd);
|
|
|
|
if (IS_ERR(path->mnt)) {
|
|
|
|
retval = PTR_ERR(path->mnt);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
/* change the handle size to multiple of sizeof(u32) */
|
|
|
|
handle_dwords = handle->handle_bytes >> 2;
|
|
|
|
path->dentry = exportfs_decode_fh(path->mnt,
|
|
|
|
(struct fid *)handle->f_handle,
|
|
|
|
handle_dwords, handle->handle_type,
|
|
|
|
vfs_dentry_acceptable, NULL);
|
|
|
|
if (IS_ERR(path->dentry)) {
|
|
|
|
retval = PTR_ERR(path->dentry);
|
|
|
|
goto out_mnt;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
out_mnt:
|
|
|
|
mntput(path->mnt);
|
|
|
|
out_err:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
|
|
|
|
struct path *path)
|
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
struct file_handle f_handle;
|
|
|
|
struct file_handle *handle = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* With handle we don't look at the execute bit on the
|
2021-02-24 23:00:48 +03:00
|
|
|
* directory. Ideally we would like CAP_DAC_SEARCH.
|
2011-01-29 16:13:26 +03:00
|
|
|
* But we don't have that
|
|
|
|
*/
|
|
|
|
if (!capable(CAP_DAC_READ_SEARCH)) {
|
|
|
|
retval = -EPERM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) {
|
|
|
|
retval = -EFAULT;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
if ((f_handle.handle_bytes > MAX_HANDLE_SZ) ||
|
|
|
|
(f_handle.handle_bytes == 0)) {
|
|
|
|
retval = -EINVAL;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_bytes,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!handle) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
/* copy the full handle */
|
2015-01-28 23:30:43 +03:00
|
|
|
*handle = f_handle;
|
|
|
|
if (copy_from_user(&handle->f_handle,
|
|
|
|
&ufh->f_handle,
|
2011-01-29 16:13:26 +03:00
|
|
|
f_handle.handle_bytes)) {
|
|
|
|
retval = -EFAULT;
|
|
|
|
goto out_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = do_handle_to_path(mountdirfd, handle, path);
|
|
|
|
|
|
|
|
out_handle:
|
|
|
|
kfree(handle);
|
|
|
|
out_err:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2017-10-14 20:18:33 +03:00
|
|
|
static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
|
|
|
|
int open_flag)
|
2011-01-29 16:13:26 +03:00
|
|
|
{
|
|
|
|
long retval = 0;
|
|
|
|
struct path path;
|
|
|
|
struct file *file;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
retval = handle_to_path(mountdirfd, ufh, &path);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
fd = get_unused_fd_flags(open_flag);
|
|
|
|
if (fd < 0) {
|
|
|
|
path_put(&path);
|
|
|
|
return fd;
|
|
|
|
}
|
2021-04-02 02:00:57 +03:00
|
|
|
file = file_open_root(&path, "", open_flag, 0);
|
2011-01-29 16:13:26 +03:00
|
|
|
if (IS_ERR(file)) {
|
|
|
|
put_unused_fd(fd);
|
|
|
|
retval = PTR_ERR(file);
|
|
|
|
} else {
|
|
|
|
retval = fd;
|
|
|
|
fsnotify_open(file);
|
|
|
|
fd_install(fd, file);
|
|
|
|
}
|
|
|
|
path_put(&path);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sys_open_by_handle_at: Open the file handle
|
|
|
|
* @mountdirfd: directory file descriptor
|
|
|
|
* @handle: file handle to be opened
|
2019-08-08 02:22:34 +03:00
|
|
|
* @flags: open flags.
|
2011-01-29 16:13:26 +03:00
|
|
|
*
|
|
|
|
* @mountdirfd indicate the directory file descriptor
|
|
|
|
* of the mount point. file handle is decoded relative
|
|
|
|
* to the vfsmount pointed by the @mountdirfd. @flags
|
|
|
|
* value is same as the open(2) flags.
|
|
|
|
*/
|
|
|
|
SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
|
|
|
|
struct file_handle __user *, handle,
|
|
|
|
int, flags)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
if (force_o_largefile())
|
|
|
|
flags |= O_LARGEFILE;
|
|
|
|
|
|
|
|
ret = do_handle_open(mountdirfd, handle, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-04-09 01:16:56 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
/*
|
|
|
|
* Exactly like fs/open.c:sys_open_by_handle_at(), except that it
|
|
|
|
* doesn't set the O_LARGEFILE flag.
|
|
|
|
*/
|
|
|
|
COMPAT_SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
|
|
|
|
struct file_handle __user *, handle, int, flags)
|
|
|
|
{
|
|
|
|
return do_handle_open(mountdirfd, handle, flags);
|
|
|
|
}
|
|
|
|
#endif
|