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 22:07:57 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2014-01-22 07:48:14 +08:00
|
|
|
#include <linux/fsnotify_backend.h>
|
|
|
|
#include <linux/path.h>
|
|
|
|
#include <linux/slab.h>
|
2019-01-11 01:04:34 +08:00
|
|
|
#include <linux/exportfs.h>
|
2021-03-04 18:48:25 +08:00
|
|
|
#include <linux/hashtable.h>
|
2014-01-22 07:48:14 +08:00
|
|
|
|
2016-12-22 01:06:12 +08:00
|
|
|
extern struct kmem_cache *fanotify_mark_cache;
|
2020-03-25 00:04:20 +08:00
|
|
|
extern struct kmem_cache *fanotify_fid_event_cachep;
|
|
|
|
extern struct kmem_cache *fanotify_path_event_cachep;
|
2014-04-04 05:46:33 +08:00
|
|
|
extern struct kmem_cache *fanotify_perm_event_cachep;
|
2014-01-22 07:48:14 +08:00
|
|
|
|
2019-01-08 21:02:44 +08:00
|
|
|
/* Possible states of the permission event */
|
|
|
|
enum {
|
|
|
|
FAN_EVENT_INIT,
|
|
|
|
FAN_EVENT_REPORTED,
|
2019-01-08 22:18:02 +08:00
|
|
|
FAN_EVENT_ANSWERED,
|
|
|
|
FAN_EVENT_CANCELED,
|
2019-01-08 21:02:44 +08:00
|
|
|
};
|
|
|
|
|
2019-01-11 01:04:34 +08:00
|
|
|
/*
|
|
|
|
* 3 dwords are sufficient for most local fs (64bit ino, 32bit generation).
|
2020-03-24 23:55:37 +08:00
|
|
|
* fh buf should be dword aligned. On 64bit arch, the ext_buf pointer is
|
|
|
|
* stored in either the first or last 2 dwords.
|
2019-01-11 01:04:34 +08:00
|
|
|
*/
|
|
|
|
#define FANOTIFY_INLINE_FH_LEN (3 << 2)
|
2020-07-16 16:42:17 +08:00
|
|
|
#define FANOTIFY_FH_HDR_LEN offsetof(struct fanotify_fh, buf)
|
2019-01-11 01:04:34 +08:00
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
/* Fixed size struct for file handle */
|
2020-03-24 23:55:37 +08:00
|
|
|
struct fanotify_fh {
|
|
|
|
u8 type;
|
|
|
|
u8 len;
|
2020-07-16 16:42:18 +08:00
|
|
|
#define FANOTIFY_FH_FLAG_EXT_BUF 1
|
|
|
|
u8 flags;
|
|
|
|
u8 pad;
|
|
|
|
unsigned char buf[];
|
2020-07-16 16:42:17 +08:00
|
|
|
} __aligned(4);
|
|
|
|
|
|
|
|
/* Variable size struct for dir file handle + child file handle + name */
|
|
|
|
struct fanotify_info {
|
|
|
|
/* size of dir_fh/file_fh including fanotify_fh hdr size */
|
|
|
|
u8 dir_fh_totlen;
|
2021-11-30 04:15:33 +08:00
|
|
|
u8 dir2_fh_totlen;
|
2020-07-16 16:42:17 +08:00
|
|
|
u8 file_fh_totlen;
|
|
|
|
u8 name_len;
|
2021-11-30 04:15:33 +08:00
|
|
|
u8 name2_len;
|
|
|
|
u8 pad[3];
|
2020-07-16 16:42:17 +08:00
|
|
|
unsigned char buf[];
|
|
|
|
/*
|
|
|
|
* (struct fanotify_fh) dir_fh starts at buf[0]
|
2021-11-30 04:15:33 +08:00
|
|
|
* (optional) dir2_fh starts at buf[dir_fh_totlen]
|
|
|
|
* (optional) file_fh starts at buf[dir_fh_totlen + dir2_fh_totlen]
|
|
|
|
* name starts at buf[dir_fh_totlen + dir2_fh_totlen + file_fh_totlen]
|
|
|
|
* ...
|
2020-07-16 16:42:17 +08:00
|
|
|
*/
|
2021-11-30 04:15:31 +08:00
|
|
|
#define FANOTIFY_DIR_FH_SIZE(info) ((info)->dir_fh_totlen)
|
2021-11-30 04:15:33 +08:00
|
|
|
#define FANOTIFY_DIR2_FH_SIZE(info) ((info)->dir2_fh_totlen)
|
2021-11-30 04:15:31 +08:00
|
|
|
#define FANOTIFY_FILE_FH_SIZE(info) ((info)->file_fh_totlen)
|
|
|
|
#define FANOTIFY_NAME_SIZE(info) ((info)->name_len + 1)
|
2021-11-30 04:15:33 +08:00
|
|
|
#define FANOTIFY_NAME2_SIZE(info) ((info)->name2_len + 1)
|
2021-11-30 04:15:31 +08:00
|
|
|
|
|
|
|
#define FANOTIFY_DIR_FH_OFFSET(info) 0
|
2021-11-30 04:15:33 +08:00
|
|
|
#define FANOTIFY_DIR2_FH_OFFSET(info) \
|
2021-11-30 04:15:31 +08:00
|
|
|
(FANOTIFY_DIR_FH_OFFSET(info) + FANOTIFY_DIR_FH_SIZE(info))
|
2021-11-30 04:15:33 +08:00
|
|
|
#define FANOTIFY_FILE_FH_OFFSET(info) \
|
|
|
|
(FANOTIFY_DIR2_FH_OFFSET(info) + FANOTIFY_DIR2_FH_SIZE(info))
|
2021-11-30 04:15:31 +08:00
|
|
|
#define FANOTIFY_NAME_OFFSET(info) \
|
|
|
|
(FANOTIFY_FILE_FH_OFFSET(info) + FANOTIFY_FILE_FH_SIZE(info))
|
2021-11-30 04:15:33 +08:00
|
|
|
#define FANOTIFY_NAME2_OFFSET(info) \
|
|
|
|
(FANOTIFY_NAME_OFFSET(info) + FANOTIFY_NAME_SIZE(info))
|
2021-11-30 04:15:31 +08:00
|
|
|
|
|
|
|
#define FANOTIFY_DIR_FH_BUF(info) \
|
|
|
|
((info)->buf + FANOTIFY_DIR_FH_OFFSET(info))
|
2021-11-30 04:15:33 +08:00
|
|
|
#define FANOTIFY_DIR2_FH_BUF(info) \
|
|
|
|
((info)->buf + FANOTIFY_DIR2_FH_OFFSET(info))
|
2021-11-30 04:15:31 +08:00
|
|
|
#define FANOTIFY_FILE_FH_BUF(info) \
|
|
|
|
((info)->buf + FANOTIFY_FILE_FH_OFFSET(info))
|
|
|
|
#define FANOTIFY_NAME_BUF(info) \
|
|
|
|
((info)->buf + FANOTIFY_NAME_OFFSET(info))
|
2021-11-30 04:15:33 +08:00
|
|
|
#define FANOTIFY_NAME2_BUF(info) \
|
|
|
|
((info)->buf + FANOTIFY_NAME2_OFFSET(info))
|
2020-03-24 23:55:37 +08:00
|
|
|
} __aligned(4);
|
|
|
|
|
|
|
|
static inline bool fanotify_fh_has_ext_buf(struct fanotify_fh *fh)
|
|
|
|
{
|
2020-07-16 16:42:18 +08:00
|
|
|
return (fh->flags & FANOTIFY_FH_FLAG_EXT_BUF);
|
2020-03-24 23:55:37 +08:00
|
|
|
}
|
2019-01-11 01:04:34 +08:00
|
|
|
|
2020-03-24 23:55:37 +08:00
|
|
|
static inline char **fanotify_fh_ext_buf_ptr(struct fanotify_fh *fh)
|
2019-01-11 01:04:34 +08:00
|
|
|
{
|
2020-07-16 16:42:17 +08:00
|
|
|
BUILD_BUG_ON(FANOTIFY_FH_HDR_LEN % 4);
|
2020-03-24 23:55:37 +08:00
|
|
|
BUILD_BUG_ON(__alignof__(char *) - 4 + sizeof(char *) >
|
|
|
|
FANOTIFY_INLINE_FH_LEN);
|
|
|
|
return (char **)ALIGN((unsigned long)(fh->buf), __alignof__(char *));
|
2019-01-11 01:04:34 +08:00
|
|
|
}
|
|
|
|
|
2020-03-24 23:55:37 +08:00
|
|
|
static inline void *fanotify_fh_ext_buf(struct fanotify_fh *fh)
|
2019-01-11 01:04:34 +08:00
|
|
|
{
|
2020-03-24 23:55:37 +08:00
|
|
|
return *fanotify_fh_ext_buf_ptr(fh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *fanotify_fh_buf(struct fanotify_fh *fh)
|
|
|
|
{
|
|
|
|
return fanotify_fh_has_ext_buf(fh) ? fanotify_fh_ext_buf(fh) : fh->buf;
|
2019-01-11 01:04:34 +08:00
|
|
|
}
|
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
static inline int fanotify_info_dir_fh_len(struct fanotify_info *info)
|
|
|
|
{
|
|
|
|
if (!info->dir_fh_totlen ||
|
|
|
|
WARN_ON_ONCE(info->dir_fh_totlen < FANOTIFY_FH_HDR_LEN))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return info->dir_fh_totlen - FANOTIFY_FH_HDR_LEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct fanotify_fh *fanotify_info_dir_fh(struct fanotify_info *info)
|
|
|
|
{
|
|
|
|
BUILD_BUG_ON(offsetof(struct fanotify_info, buf) % 4);
|
|
|
|
|
2021-11-30 04:15:31 +08:00
|
|
|
return (struct fanotify_fh *)FANOTIFY_DIR_FH_BUF(info);
|
2020-07-16 16:42:17 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:33 +08:00
|
|
|
static inline int fanotify_info_dir2_fh_len(struct fanotify_info *info)
|
|
|
|
{
|
|
|
|
if (!info->dir2_fh_totlen ||
|
|
|
|
WARN_ON_ONCE(info->dir2_fh_totlen < FANOTIFY_FH_HDR_LEN))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return info->dir2_fh_totlen - FANOTIFY_FH_HDR_LEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct fanotify_fh *fanotify_info_dir2_fh(struct fanotify_info *info)
|
|
|
|
{
|
|
|
|
return (struct fanotify_fh *)FANOTIFY_DIR2_FH_BUF(info);
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
static inline int fanotify_info_file_fh_len(struct fanotify_info *info)
|
|
|
|
{
|
|
|
|
if (!info->file_fh_totlen ||
|
|
|
|
WARN_ON_ONCE(info->file_fh_totlen < FANOTIFY_FH_HDR_LEN))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return info->file_fh_totlen - FANOTIFY_FH_HDR_LEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct fanotify_fh *fanotify_info_file_fh(struct fanotify_info *info)
|
|
|
|
{
|
2021-11-30 04:15:31 +08:00
|
|
|
return (struct fanotify_fh *)FANOTIFY_FILE_FH_BUF(info);
|
2020-07-16 16:42:17 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:31 +08:00
|
|
|
static inline char *fanotify_info_name(struct fanotify_info *info)
|
2020-07-16 16:42:17 +08:00
|
|
|
{
|
2021-11-30 04:15:31 +08:00
|
|
|
if (!info->name_len)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return FANOTIFY_NAME_BUF(info);
|
2020-07-16 16:42:17 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:33 +08:00
|
|
|
static inline char *fanotify_info_name2(struct fanotify_info *info)
|
|
|
|
{
|
|
|
|
if (!info->name2_len)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return FANOTIFY_NAME2_BUF(info);
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
static inline void fanotify_info_init(struct fanotify_info *info)
|
|
|
|
{
|
2021-11-30 04:15:31 +08:00
|
|
|
BUILD_BUG_ON(FANOTIFY_FH_HDR_LEN + MAX_HANDLE_SZ > U8_MAX);
|
|
|
|
BUILD_BUG_ON(NAME_MAX > U8_MAX);
|
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
info->dir_fh_totlen = 0;
|
2021-11-30 04:15:33 +08:00
|
|
|
info->dir2_fh_totlen = 0;
|
2020-07-16 16:42:17 +08:00
|
|
|
info->file_fh_totlen = 0;
|
|
|
|
info->name_len = 0;
|
2021-11-30 04:15:33 +08:00
|
|
|
info->name2_len = 0;
|
2020-07-16 16:42:17 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:32 +08:00
|
|
|
/* These set/copy helpers MUST be called by order */
|
|
|
|
static inline void fanotify_info_set_dir_fh(struct fanotify_info *info,
|
|
|
|
unsigned int totlen)
|
|
|
|
{
|
2021-11-30 04:15:33 +08:00
|
|
|
if (WARN_ON_ONCE(info->dir2_fh_totlen > 0) ||
|
|
|
|
WARN_ON_ONCE(info->file_fh_totlen > 0) ||
|
|
|
|
WARN_ON_ONCE(info->name_len > 0) ||
|
|
|
|
WARN_ON_ONCE(info->name2_len > 0))
|
2021-11-30 04:15:32 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
info->dir_fh_totlen = totlen;
|
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:33 +08:00
|
|
|
static inline void fanotify_info_set_dir2_fh(struct fanotify_info *info,
|
|
|
|
unsigned int totlen)
|
|
|
|
{
|
|
|
|
if (WARN_ON_ONCE(info->file_fh_totlen > 0) ||
|
|
|
|
WARN_ON_ONCE(info->name_len > 0) ||
|
|
|
|
WARN_ON_ONCE(info->name2_len > 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
info->dir2_fh_totlen = totlen;
|
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:32 +08:00
|
|
|
static inline void fanotify_info_set_file_fh(struct fanotify_info *info,
|
|
|
|
unsigned int totlen)
|
|
|
|
{
|
2021-11-30 04:15:33 +08:00
|
|
|
if (WARN_ON_ONCE(info->name_len > 0) ||
|
|
|
|
WARN_ON_ONCE(info->name2_len > 0))
|
2021-11-30 04:15:32 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
info->file_fh_totlen = totlen;
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
static inline void fanotify_info_copy_name(struct fanotify_info *info,
|
|
|
|
const struct qstr *name)
|
|
|
|
{
|
2021-11-30 04:15:33 +08:00
|
|
|
if (WARN_ON_ONCE(name->len > NAME_MAX) ||
|
|
|
|
WARN_ON_ONCE(info->name2_len > 0))
|
2021-11-30 04:15:31 +08:00
|
|
|
return;
|
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
info->name_len = name->len;
|
2021-11-30 04:15:31 +08:00
|
|
|
strcpy(fanotify_info_name(info), name->name);
|
2020-07-16 16:42:17 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:33 +08:00
|
|
|
static inline void fanotify_info_copy_name2(struct fanotify_info *info,
|
|
|
|
const struct qstr *name)
|
|
|
|
{
|
|
|
|
if (WARN_ON_ONCE(name->len > NAME_MAX))
|
|
|
|
return;
|
|
|
|
|
|
|
|
info->name2_len = name->len;
|
|
|
|
strcpy(fanotify_info_name2(info), name->name);
|
|
|
|
}
|
|
|
|
|
2014-01-29 04:38:06 +08:00
|
|
|
/*
|
2020-03-25 00:04:20 +08:00
|
|
|
* Common structure for fanotify events. Concrete structs are allocated in
|
2014-04-04 05:46:33 +08:00
|
|
|
* fanotify_handle_event() and freed when the information is retrieved by
|
2020-03-25 00:04:20 +08:00
|
|
|
* userspace. The type of event determines how it was allocated, how it will
|
|
|
|
* be freed and which concrete struct it may be cast to.
|
2014-01-29 04:38:06 +08:00
|
|
|
*/
|
2020-03-25 00:04:20 +08:00
|
|
|
enum fanotify_event_type {
|
2020-03-19 23:10:21 +08:00
|
|
|
FANOTIFY_EVENT_TYPE_FID, /* fixed length */
|
|
|
|
FANOTIFY_EVENT_TYPE_FID_NAME, /* variable length */
|
2020-03-25 00:04:20 +08:00
|
|
|
FANOTIFY_EVENT_TYPE_PATH,
|
|
|
|
FANOTIFY_EVENT_TYPE_PATH_PERM,
|
2020-07-08 19:11:42 +08:00
|
|
|
FANOTIFY_EVENT_TYPE_OVERFLOW, /* struct fanotify_event */
|
2021-10-26 03:27:34 +08:00
|
|
|
FANOTIFY_EVENT_TYPE_FS_ERROR, /* struct fanotify_error_event */
|
2021-03-04 18:48:23 +08:00
|
|
|
__FANOTIFY_EVENT_TYPE_NUM
|
2020-03-25 00:04:20 +08:00
|
|
|
};
|
|
|
|
|
2021-03-04 18:48:23 +08:00
|
|
|
#define FANOTIFY_EVENT_TYPE_BITS \
|
|
|
|
(ilog2(__FANOTIFY_EVENT_TYPE_NUM - 1) + 1)
|
|
|
|
#define FANOTIFY_EVENT_HASH_BITS \
|
|
|
|
(32 - FANOTIFY_EVENT_TYPE_BITS)
|
|
|
|
|
2019-01-11 01:04:32 +08:00
|
|
|
struct fanotify_event {
|
2014-01-22 07:48:14 +08:00
|
|
|
struct fsnotify_event fse;
|
2021-03-04 18:48:25 +08:00
|
|
|
struct hlist_node merge_list; /* List for hashed merge */
|
2019-01-11 01:04:31 +08:00
|
|
|
u32 mask;
|
2021-03-04 18:48:23 +08:00
|
|
|
struct {
|
|
|
|
unsigned int type : FANOTIFY_EVENT_TYPE_BITS;
|
|
|
|
unsigned int hash : FANOTIFY_EVENT_HASH_BITS;
|
|
|
|
};
|
2018-10-04 05:25:38 +08:00
|
|
|
struct pid *pid;
|
2014-04-04 05:46:33 +08:00
|
|
|
};
|
|
|
|
|
2020-07-08 19:11:42 +08:00
|
|
|
static inline void fanotify_init_event(struct fanotify_event *event,
|
2021-03-04 18:48:23 +08:00
|
|
|
unsigned int hash, u32 mask)
|
2020-07-08 19:11:42 +08:00
|
|
|
{
|
2021-03-04 18:48:23 +08:00
|
|
|
fsnotify_init_event(&event->fse);
|
2021-03-04 18:48:25 +08:00
|
|
|
INIT_HLIST_NODE(&event->merge_list);
|
2021-03-04 18:48:23 +08:00
|
|
|
event->hash = hash;
|
2020-07-08 19:11:42 +08:00
|
|
|
event->mask = mask;
|
|
|
|
event->pid = NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:27:37 +08:00
|
|
|
#define FANOTIFY_INLINE_FH(name, size) \
|
|
|
|
struct { \
|
|
|
|
struct fanotify_fh (name); \
|
|
|
|
/* Space for object_fh.buf[] - access with fanotify_fh_buf() */ \
|
|
|
|
unsigned char _inline_fh_buf[(size)]; \
|
|
|
|
}
|
|
|
|
|
2020-03-25 00:04:20 +08:00
|
|
|
struct fanotify_fid_event {
|
|
|
|
struct fanotify_event fae;
|
|
|
|
__kernel_fsid_t fsid;
|
2021-10-26 03:27:37 +08:00
|
|
|
|
|
|
|
FANOTIFY_INLINE_FH(object_fh, FANOTIFY_INLINE_FH_LEN);
|
2020-03-25 00:04:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct fanotify_fid_event *
|
|
|
|
FANOTIFY_FE(struct fanotify_event *event)
|
2019-01-11 01:04:34 +08:00
|
|
|
{
|
2020-03-25 00:04:20 +08:00
|
|
|
return container_of(event, struct fanotify_fid_event, fae);
|
2019-01-11 01:04:34 +08:00
|
|
|
}
|
|
|
|
|
2020-03-19 23:10:21 +08:00
|
|
|
struct fanotify_name_event {
|
|
|
|
struct fanotify_event fae;
|
|
|
|
__kernel_fsid_t fsid;
|
2020-07-16 16:42:17 +08:00
|
|
|
struct fanotify_info info;
|
2020-03-19 23:10:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct fanotify_name_event *
|
|
|
|
FANOTIFY_NE(struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
return container_of(event, struct fanotify_name_event, fae);
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:27:34 +08:00
|
|
|
struct fanotify_error_event {
|
|
|
|
struct fanotify_event fae;
|
2021-10-26 03:27:42 +08:00
|
|
|
s32 error; /* Error reported by the Filesystem. */
|
2021-10-26 03:27:36 +08:00
|
|
|
u32 err_count; /* Suppressed errors count */
|
|
|
|
|
|
|
|
__kernel_fsid_t fsid; /* FSID this error refers to. */
|
2021-10-26 03:27:41 +08:00
|
|
|
|
|
|
|
FANOTIFY_INLINE_FH(object_fh, MAX_HANDLE_SZ);
|
2021-10-26 03:27:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct fanotify_error_event *
|
|
|
|
FANOTIFY_EE(struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
return container_of(event, struct fanotify_error_event, fae);
|
|
|
|
}
|
|
|
|
|
2020-03-24 23:55:37 +08:00
|
|
|
static inline __kernel_fsid_t *fanotify_event_fsid(struct fanotify_event *event)
|
2019-01-11 01:04:34 +08:00
|
|
|
{
|
2020-03-25 00:04:20 +08:00
|
|
|
if (event->type == FANOTIFY_EVENT_TYPE_FID)
|
|
|
|
return &FANOTIFY_FE(event)->fsid;
|
2020-03-19 23:10:21 +08:00
|
|
|
else if (event->type == FANOTIFY_EVENT_TYPE_FID_NAME)
|
|
|
|
return &FANOTIFY_NE(event)->fsid;
|
2021-10-26 03:27:41 +08:00
|
|
|
else if (event->type == FANOTIFY_EVENT_TYPE_FS_ERROR)
|
|
|
|
return &FANOTIFY_EE(event)->fsid;
|
2020-03-24 23:55:37 +08:00
|
|
|
else
|
|
|
|
return NULL;
|
2019-01-11 01:04:34 +08:00
|
|
|
}
|
|
|
|
|
2020-03-24 23:55:37 +08:00
|
|
|
static inline struct fanotify_fh *fanotify_event_object_fh(
|
|
|
|
struct fanotify_event *event)
|
2019-01-11 01:04:35 +08:00
|
|
|
{
|
2020-03-25 00:04:20 +08:00
|
|
|
if (event->type == FANOTIFY_EVENT_TYPE_FID)
|
|
|
|
return &FANOTIFY_FE(event)->object_fh;
|
2020-07-16 16:42:29 +08:00
|
|
|
else if (event->type == FANOTIFY_EVENT_TYPE_FID_NAME)
|
|
|
|
return fanotify_info_file_fh(&FANOTIFY_NE(event)->info);
|
2021-10-26 03:27:41 +08:00
|
|
|
else if (event->type == FANOTIFY_EVENT_TYPE_FS_ERROR)
|
|
|
|
return &FANOTIFY_EE(event)->object_fh;
|
2020-03-24 23:55:37 +08:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
static inline struct fanotify_info *fanotify_event_info(
|
2020-03-19 23:10:21 +08:00
|
|
|
struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
if (event->type == FANOTIFY_EVENT_TYPE_FID_NAME)
|
2020-07-16 16:42:17 +08:00
|
|
|
return &FANOTIFY_NE(event)->info;
|
2020-03-19 23:10:21 +08:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-03-24 23:55:37 +08:00
|
|
|
static inline int fanotify_event_object_fh_len(struct fanotify_event *event)
|
|
|
|
{
|
2020-07-16 16:42:29 +08:00
|
|
|
struct fanotify_info *info = fanotify_event_info(event);
|
2020-03-24 23:55:37 +08:00
|
|
|
struct fanotify_fh *fh = fanotify_event_object_fh(event);
|
|
|
|
|
2020-07-16 16:42:29 +08:00
|
|
|
if (info)
|
|
|
|
return info->file_fh_totlen ? fh->len : 0;
|
|
|
|
else
|
|
|
|
return fh ? fh->len : 0;
|
2019-01-11 01:04:35 +08:00
|
|
|
}
|
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
static inline int fanotify_event_dir_fh_len(struct fanotify_event *event)
|
2020-03-19 23:10:21 +08:00
|
|
|
{
|
2020-07-16 16:42:17 +08:00
|
|
|
struct fanotify_info *info = fanotify_event_info(event);
|
2020-03-19 23:10:21 +08:00
|
|
|
|
2020-07-16 16:42:17 +08:00
|
|
|
return info ? fanotify_info_dir_fh_len(info) : 0;
|
2020-03-19 23:10:21 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:36 +08:00
|
|
|
static inline int fanotify_event_dir2_fh_len(struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
struct fanotify_info *info = fanotify_event_info(event);
|
|
|
|
|
|
|
|
return info ? fanotify_info_dir2_fh_len(info) : 0;
|
|
|
|
}
|
|
|
|
|
2021-10-26 03:27:38 +08:00
|
|
|
static inline bool fanotify_event_has_object_fh(struct fanotify_event *event)
|
|
|
|
{
|
2021-10-26 03:27:41 +08:00
|
|
|
/* For error events, even zeroed fh are reported. */
|
|
|
|
if (event->type == FANOTIFY_EVENT_TYPE_FS_ERROR)
|
|
|
|
return true;
|
2021-10-26 03:27:38 +08:00
|
|
|
return fanotify_event_object_fh_len(event) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool fanotify_event_has_dir_fh(struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
return fanotify_event_dir_fh_len(event) > 0;
|
|
|
|
}
|
|
|
|
|
2021-11-30 04:15:36 +08:00
|
|
|
static inline bool fanotify_event_has_dir2_fh(struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
return fanotify_event_dir2_fh_len(event) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool fanotify_event_has_any_dir_fh(struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
return fanotify_event_has_dir_fh(event) ||
|
|
|
|
fanotify_event_has_dir2_fh(event);
|
|
|
|
}
|
|
|
|
|
2020-03-25 00:04:20 +08:00
|
|
|
struct fanotify_path_event {
|
|
|
|
struct fanotify_event fae;
|
|
|
|
struct path path;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct fanotify_path_event *
|
|
|
|
FANOTIFY_PE(struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
return container_of(event, struct fanotify_path_event, fae);
|
|
|
|
}
|
|
|
|
|
2014-04-04 05:46:33 +08:00
|
|
|
/*
|
|
|
|
* Structure for permission fanotify events. It gets allocated and freed in
|
|
|
|
* fanotify_handle_event() since we wait there for user response. When the
|
|
|
|
* information is retrieved by userspace the structure is moved from
|
|
|
|
* group->notification_list to group->fanotify_data.access_list to wait for
|
|
|
|
* user response.
|
|
|
|
*/
|
2019-01-11 01:04:32 +08:00
|
|
|
struct fanotify_perm_event {
|
|
|
|
struct fanotify_event fae;
|
2020-03-25 00:04:20 +08:00
|
|
|
struct path path;
|
2019-01-08 21:02:44 +08:00
|
|
|
unsigned short response; /* userspace answer to the event */
|
|
|
|
unsigned short state; /* state of the event */
|
2014-04-04 05:46:33 +08:00
|
|
|
int fd; /* fd we passed to userspace for this event */
|
2014-01-22 07:48:14 +08:00
|
|
|
};
|
|
|
|
|
2019-01-11 01:04:32 +08:00
|
|
|
static inline struct fanotify_perm_event *
|
2020-03-25 00:04:20 +08:00
|
|
|
FANOTIFY_PERM(struct fanotify_event *event)
|
2014-04-04 05:46:33 +08:00
|
|
|
{
|
2020-03-25 00:04:20 +08:00
|
|
|
return container_of(event, struct fanotify_perm_event, fae);
|
2014-04-04 05:46:33 +08:00
|
|
|
}
|
2017-10-31 04:14:56 +08:00
|
|
|
|
|
|
|
static inline bool fanotify_is_perm_event(u32 mask)
|
|
|
|
{
|
|
|
|
return IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS) &&
|
2018-10-04 05:25:35 +08:00
|
|
|
mask & FANOTIFY_PERM_EVENTS;
|
2017-10-31 04:14:56 +08:00
|
|
|
}
|
2014-04-04 05:46:33 +08:00
|
|
|
|
2019-01-11 01:04:32 +08:00
|
|
|
static inline struct fanotify_event *FANOTIFY_E(struct fsnotify_event *fse)
|
2014-01-22 07:48:14 +08:00
|
|
|
{
|
2019-01-11 01:04:32 +08:00
|
|
|
return container_of(fse, struct fanotify_event, fse);
|
2014-01-22 07:48:14 +08:00
|
|
|
}
|
2014-04-04 05:46:33 +08:00
|
|
|
|
2021-10-26 03:27:35 +08:00
|
|
|
static inline bool fanotify_is_error_event(u32 mask)
|
|
|
|
{
|
|
|
|
return mask & FAN_FS_ERROR;
|
|
|
|
}
|
|
|
|
|
2022-08-05 00:57:38 +08:00
|
|
|
static inline const struct path *fanotify_event_path(struct fanotify_event *event)
|
2020-03-24 23:55:37 +08:00
|
|
|
{
|
2020-03-25 00:04:20 +08:00
|
|
|
if (event->type == FANOTIFY_EVENT_TYPE_PATH)
|
|
|
|
return &FANOTIFY_PE(event)->path;
|
|
|
|
else if (event->type == FANOTIFY_EVENT_TYPE_PATH_PERM)
|
|
|
|
return &FANOTIFY_PERM(event)->path;
|
2020-03-24 23:55:37 +08:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-03-04 18:48:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use 128 size hash table to speed up events merge.
|
|
|
|
*/
|
|
|
|
#define FANOTIFY_HTABLE_BITS (7)
|
|
|
|
#define FANOTIFY_HTABLE_SIZE (1 << FANOTIFY_HTABLE_BITS)
|
|
|
|
#define FANOTIFY_HTABLE_MASK (FANOTIFY_HTABLE_SIZE - 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Permission events and overflow event do not get merged - don't hash them.
|
|
|
|
*/
|
|
|
|
static inline bool fanotify_is_hashed_event(u32 mask)
|
|
|
|
{
|
2021-10-26 03:27:23 +08:00
|
|
|
return !(fanotify_is_perm_event(mask) ||
|
|
|
|
fsnotify_is_overflow_event(mask));
|
2021-03-04 18:48:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int fanotify_event_hash_bucket(
|
|
|
|
struct fsnotify_group *group,
|
|
|
|
struct fanotify_event *event)
|
|
|
|
{
|
|
|
|
return event->hash & FANOTIFY_HTABLE_MASK;
|
|
|
|
}
|
2022-04-22 20:03:23 +08:00
|
|
|
|
|
|
|
static inline unsigned int fanotify_mark_user_flags(struct fsnotify_mark *mark)
|
|
|
|
{
|
|
|
|
unsigned int mflags = 0;
|
|
|
|
|
|
|
|
if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)
|
|
|
|
mflags |= FAN_MARK_IGNORED_SURV_MODIFY;
|
2022-04-22 20:03:25 +08:00
|
|
|
if (mark->flags & FSNOTIFY_MARK_FLAG_NO_IREF)
|
|
|
|
mflags |= FAN_MARK_EVICTABLE;
|
2022-06-29 22:42:10 +08:00
|
|
|
if (mark->flags & FSNOTIFY_MARK_FLAG_HAS_IGNORE_FLAGS)
|
|
|
|
mflags |= FAN_MARK_IGNORE;
|
2022-04-22 20:03:23 +08:00
|
|
|
|
|
|
|
return mflags;
|
|
|
|
}
|