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
|
2013-02-16 02:20:46 +04:00
|
|
|
#include <linux/kmod.h>
|
|
|
|
#include <linux/netdevice.h>
|
2021-07-22 17:29:01 +03:00
|
|
|
#include <linux/inetdevice.h>
|
2013-02-16 02:20:46 +04:00
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/net_tstamp.h>
|
|
|
|
#include <linux/wireless.h>
|
2021-07-27 16:45:16 +03:00
|
|
|
#include <linux/if_bridge.h>
|
2020-07-20 06:49:53 +03:00
|
|
|
#include <net/dsa.h>
|
2013-02-16 02:20:46 +04:00
|
|
|
#include <net/wext.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Map an interface index to its name (SIOCGIFNAME)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need this ioctl for efficient implementation of the
|
|
|
|
* if_indextoname() function required by the IPv6 API. Without
|
|
|
|
* it, we would have to search all the interfaces to find a
|
|
|
|
* match. --pb
|
|
|
|
*/
|
|
|
|
|
2017-10-05 19:59:44 +03:00
|
|
|
static int dev_ifname(struct net *net, struct ifreq *ifr)
|
2013-02-16 02:20:46 +04:00
|
|
|
{
|
2017-10-05 19:59:44 +03:00
|
|
|
ifr->ifr_name[IFNAMSIZ-1] = 0;
|
|
|
|
return netdev_get_name(net, ifr->ifr_name, ifr->ifr_ifindex);
|
2013-02-16 02:20:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform a SIOCGIFCONF call. This structure will change
|
|
|
|
* size eventually, and there is nothing I can do about it.
|
|
|
|
* Thus we will need a 'compatibility mode'.
|
|
|
|
*/
|
2021-07-22 17:29:02 +03:00
|
|
|
int dev_ifconf(struct net *net, struct ifconf __user *uifc)
|
2013-02-16 02:20:46 +04:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
2021-07-22 17:29:02 +03:00
|
|
|
void __user *pos;
|
|
|
|
size_t size;
|
|
|
|
int len, total = 0, done;
|
2013-02-16 02:20:46 +04:00
|
|
|
|
2021-07-22 17:29:02 +03:00
|
|
|
/* both the ifconf and the ifreq structures are slightly different */
|
|
|
|
if (in_compat_syscall()) {
|
|
|
|
struct compat_ifconf ifc32;
|
2013-02-16 02:20:46 +04:00
|
|
|
|
2021-07-22 17:29:02 +03:00
|
|
|
if (copy_from_user(&ifc32, uifc, sizeof(struct compat_ifconf)))
|
|
|
|
return -EFAULT;
|
2013-02-16 02:20:46 +04:00
|
|
|
|
2021-07-22 17:29:02 +03:00
|
|
|
pos = compat_ptr(ifc32.ifcbuf);
|
|
|
|
len = ifc32.ifc_len;
|
|
|
|
size = sizeof(struct compat_ifreq);
|
|
|
|
} else {
|
|
|
|
struct ifconf ifc;
|
|
|
|
|
|
|
|
if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
|
|
|
|
return -EFAULT;
|
2013-02-16 02:20:46 +04:00
|
|
|
|
2021-07-22 17:29:02 +03:00
|
|
|
pos = ifc.ifc_buf;
|
|
|
|
len = ifc.ifc_len;
|
|
|
|
size = sizeof(struct ifreq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop over the interfaces, and write an info block for each. */
|
|
|
|
rtnl_lock();
|
2013-02-16 02:20:46 +04:00
|
|
|
for_each_netdev(net, dev) {
|
2021-07-22 17:29:01 +03:00
|
|
|
if (!pos)
|
|
|
|
done = inet_gifconf(dev, NULL, 0, size);
|
|
|
|
else
|
|
|
|
done = inet_gifconf(dev, pos + total,
|
|
|
|
len - total, size);
|
2021-07-22 17:29:02 +03:00
|
|
|
if (done < 0) {
|
|
|
|
rtnl_unlock();
|
2021-07-22 17:29:01 +03:00
|
|
|
return -EFAULT;
|
2021-07-22 17:29:02 +03:00
|
|
|
}
|
2021-07-22 17:29:01 +03:00
|
|
|
total += done;
|
2013-02-16 02:20:46 +04:00
|
|
|
}
|
2021-07-22 17:29:02 +03:00
|
|
|
rtnl_unlock();
|
2013-02-16 02:20:46 +04:00
|
|
|
|
2021-07-22 17:29:02 +03:00
|
|
|
return put_user(total, &uifc->ifc_len);
|
2013-02-16 02:20:46 +04:00
|
|
|
}
|
|
|
|
|
2021-07-22 17:29:00 +03:00
|
|
|
static int dev_getifmap(struct net_device *dev, struct ifreq *ifr)
|
|
|
|
{
|
|
|
|
struct ifmap *ifmap = &ifr->ifr_map;
|
|
|
|
|
|
|
|
if (in_compat_syscall()) {
|
|
|
|
struct compat_ifmap *cifmap = (struct compat_ifmap *)ifmap;
|
|
|
|
|
|
|
|
cifmap->mem_start = dev->mem_start;
|
|
|
|
cifmap->mem_end = dev->mem_end;
|
|
|
|
cifmap->base_addr = dev->base_addr;
|
|
|
|
cifmap->irq = dev->irq;
|
|
|
|
cifmap->dma = dev->dma;
|
|
|
|
cifmap->port = dev->if_port;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifmap->mem_start = dev->mem_start;
|
|
|
|
ifmap->mem_end = dev->mem_end;
|
|
|
|
ifmap->base_addr = dev->base_addr;
|
|
|
|
ifmap->irq = dev->irq;
|
|
|
|
ifmap->dma = dev->dma;
|
|
|
|
ifmap->port = dev->if_port;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dev_setifmap(struct net_device *dev, struct ifreq *ifr)
|
|
|
|
{
|
|
|
|
struct compat_ifmap *cifmap = (struct compat_ifmap *)&ifr->ifr_map;
|
|
|
|
|
|
|
|
if (!dev->netdev_ops->ndo_set_config)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
if (in_compat_syscall()) {
|
|
|
|
struct ifmap ifmap = {
|
|
|
|
.mem_start = cifmap->mem_start,
|
|
|
|
.mem_end = cifmap->mem_end,
|
|
|
|
.base_addr = cifmap->base_addr,
|
|
|
|
.irq = cifmap->irq,
|
|
|
|
.dma = cifmap->dma,
|
|
|
|
.port = cifmap->port,
|
|
|
|
};
|
|
|
|
|
|
|
|
return dev->netdev_ops->ndo_set_config(dev, &ifmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dev->netdev_ops->ndo_set_config(dev, &ifr->ifr_map);
|
|
|
|
}
|
|
|
|
|
2013-02-16 02:20:46 +04:00
|
|
|
/*
|
|
|
|
* Perform the SIOCxIFxxx calls, inside rcu_read_lock()
|
|
|
|
*/
|
|
|
|
static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cmd)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct net_device *dev = dev_get_by_name_rcu(net, ifr->ifr_name);
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCGIFFLAGS: /* Get interface flags */
|
|
|
|
ifr->ifr_flags = (short) dev_get_flags(dev);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SIOCGIFMETRIC: /* Get the metric on the interface
|
|
|
|
(currently unused) */
|
|
|
|
ifr->ifr_metric = 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SIOCGIFMTU: /* Get the MTU of a device */
|
|
|
|
ifr->ifr_mtu = dev->mtu;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SIOCGIFSLAVE:
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFMAP:
|
2021-07-22 17:29:00 +03:00
|
|
|
return dev_getifmap(dev, ifr);
|
2013-02-16 02:20:46 +04:00
|
|
|
|
|
|
|
case SIOCGIFINDEX:
|
|
|
|
ifr->ifr_ifindex = dev->ifindex;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SIOCGIFTXQLEN:
|
|
|
|
ifr->ifr_qlen = dev->tx_queue_len;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* dev_ioctl() should ensure this case
|
|
|
|
* is never reached
|
|
|
|
*/
|
|
|
|
WARN_ON(1);
|
|
|
|
err = -ENOTTY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int net_hwtstamp_validate(struct ifreq *ifr)
|
|
|
|
{
|
|
|
|
struct hwtstamp_config cfg;
|
|
|
|
enum hwtstamp_tx_types tx_type;
|
|
|
|
enum hwtstamp_rx_filters rx_filter;
|
|
|
|
int tx_type_valid = 0;
|
|
|
|
int rx_filter_valid = 0;
|
|
|
|
|
|
|
|
if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (cfg.flags) /* reserved for future extensions */
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
tx_type = cfg.tx_type;
|
|
|
|
rx_filter = cfg.rx_filter;
|
|
|
|
|
|
|
|
switch (tx_type) {
|
|
|
|
case HWTSTAMP_TX_OFF:
|
|
|
|
case HWTSTAMP_TX_ON:
|
|
|
|
case HWTSTAMP_TX_ONESTEP_SYNC:
|
2019-12-26 05:16:19 +03:00
|
|
|
case HWTSTAMP_TX_ONESTEP_P2P:
|
2013-02-16 02:20:46 +04:00
|
|
|
tx_type_valid = 1;
|
|
|
|
break;
|
2020-03-28 02:01:53 +03:00
|
|
|
case __HWTSTAMP_TX_CNT:
|
|
|
|
/* not a real value */
|
|
|
|
break;
|
2013-02-16 02:20:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (rx_filter) {
|
|
|
|
case HWTSTAMP_FILTER_NONE:
|
|
|
|
case HWTSTAMP_FILTER_ALL:
|
|
|
|
case HWTSTAMP_FILTER_SOME:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_EVENT:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_SYNC:
|
|
|
|
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
|
2017-05-19 18:52:35 +03:00
|
|
|
case HWTSTAMP_FILTER_NTP_ALL:
|
2017-05-19 18:52:36 +03:00
|
|
|
rx_filter_valid = 1;
|
2017-05-19 18:52:35 +03:00
|
|
|
break;
|
2020-03-28 02:01:53 +03:00
|
|
|
case __HWTSTAMP_FILTER_CNT:
|
|
|
|
/* not a real value */
|
|
|
|
break;
|
2013-02-16 02:20:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!tx_type_valid || !rx_filter_valid)
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-27 16:45:13 +03:00
|
|
|
static int dev_eth_ioctl(struct net_device *dev,
|
|
|
|
struct ifreq *ifr, unsigned int cmd)
|
2020-07-20 06:49:51 +03:00
|
|
|
{
|
|
|
|
const struct net_device_ops *ops = dev->netdev_ops;
|
2020-11-02 15:16:15 +03:00
|
|
|
int err;
|
2020-07-20 06:49:51 +03:00
|
|
|
|
2021-07-27 16:45:13 +03:00
|
|
|
err = dsa_ndo_eth_ioctl(dev, ifr, cmd);
|
2020-07-20 06:49:53 +03:00
|
|
|
if (err == 0 || err != -EOPNOTSUPP)
|
|
|
|
return err;
|
|
|
|
|
2021-07-27 16:45:13 +03:00
|
|
|
if (ops->ndo_eth_ioctl) {
|
2020-07-20 06:49:51 +03:00
|
|
|
if (netif_device_present(dev))
|
2021-07-27 16:45:13 +03:00
|
|
|
err = ops->ndo_eth_ioctl(dev, ifr, cmd);
|
2020-07-20 06:49:51 +03:00
|
|
|
else
|
|
|
|
err = -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-07-27 16:45:17 +03:00
|
|
|
static int dev_siocbond(struct net_device *dev,
|
2021-07-27 16:45:13 +03:00
|
|
|
struct ifreq *ifr, unsigned int cmd)
|
|
|
|
{
|
|
|
|
const struct net_device_ops *ops = dev->netdev_ops;
|
|
|
|
|
2021-07-27 16:45:17 +03:00
|
|
|
if (ops->ndo_siocbond) {
|
2021-07-27 16:45:13 +03:00
|
|
|
if (netif_device_present(dev))
|
2021-07-27 16:45:17 +03:00
|
|
|
return ops->ndo_siocbond(dev, ifr, cmd);
|
2021-07-27 16:45:13 +03:00
|
|
|
else
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2021-07-27 16:45:12 +03:00
|
|
|
static int dev_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
|
|
|
|
void __user *data, unsigned int cmd)
|
2021-07-27 16:44:47 +03:00
|
|
|
{
|
|
|
|
const struct net_device_ops *ops = dev->netdev_ops;
|
|
|
|
|
|
|
|
if (ops->ndo_siocdevprivate) {
|
|
|
|
if (netif_device_present(dev))
|
|
|
|
return ops->ndo_siocdevprivate(dev, ifr, data, cmd);
|
|
|
|
else
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2021-07-27 16:45:15 +03:00
|
|
|
return -EOPNOTSUPP;
|
2021-07-27 16:44:47 +03:00
|
|
|
}
|
|
|
|
|
2021-07-27 16:45:14 +03:00
|
|
|
static int dev_siocwandev(struct net_device *dev, struct if_settings *ifs)
|
|
|
|
{
|
|
|
|
const struct net_device_ops *ops = dev->netdev_ops;
|
|
|
|
|
|
|
|
if (ops->ndo_siocwandev) {
|
|
|
|
if (netif_device_present(dev))
|
|
|
|
return ops->ndo_siocwandev(dev, ifs);
|
|
|
|
else
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2013-02-16 02:20:46 +04:00
|
|
|
/*
|
|
|
|
* Perform the SIOCxIFxxx calls, inside rtnl_lock()
|
|
|
|
*/
|
2021-07-27 16:45:12 +03:00
|
|
|
static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,
|
|
|
|
unsigned int cmd)
|
2013-02-16 02:20:46 +04:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
|
|
|
|
const struct net_device_ops *ops;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ops = dev->netdev_ops;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFFLAGS: /* Set interface flags */
|
2018-12-06 20:05:42 +03:00
|
|
|
return dev_change_flags(dev, ifr->ifr_flags, NULL);
|
2013-02-16 02:20:46 +04:00
|
|
|
|
|
|
|
case SIOCSIFMETRIC: /* Set the metric on the interface
|
|
|
|
(currently unused) */
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
case SIOCSIFMTU: /* Set the MTU of a device */
|
|
|
|
return dev_set_mtu(dev, ifr->ifr_mtu);
|
|
|
|
|
|
|
|
case SIOCSIFHWADDR:
|
2017-07-27 01:22:06 +03:00
|
|
|
if (dev->addr_len > sizeof(struct sockaddr))
|
|
|
|
return -EINVAL;
|
net: fix dev_ifsioc_locked() race condition
dev_ifsioc_locked() is called with only RCU read lock, so when
there is a parallel writer changing the mac address, it could
get a partially updated mac address, as shown below:
Thread 1 Thread 2
// eth_commit_mac_addr_change()
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
// dev_ifsioc_locked()
memcpy(ifr->ifr_hwaddr.sa_data,
dev->dev_addr,...);
Close this race condition by guarding them with a RW semaphore,
like netdev_get_name(). We can not use seqlock here as it does not
allow blocking. The writers already take RTNL anyway, so this does
not affect the slow path. To avoid bothering existing
dev_set_mac_address() callers in drivers, introduce a new wrapper
just for user-facing callers on ioctl and rtnetlink paths.
Note, bonding also changes slave mac addresses but that requires
a separate patch due to the complexity of bonding code.
Fixes: 3710becf8a58 ("net: RCU locking for simple ioctl()")
Reported-by: "Gong, Sishuai" <sishuai@purdue.edu>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-02-11 22:34:10 +03:00
|
|
|
return dev_set_mac_address_user(dev, &ifr->ifr_hwaddr, NULL);
|
2013-02-16 02:20:46 +04:00
|
|
|
|
|
|
|
case SIOCSIFHWBROADCAST:
|
|
|
|
if (ifr->ifr_hwaddr.sa_family != dev->type)
|
|
|
|
return -EINVAL;
|
|
|
|
memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data,
|
2014-11-18 00:23:17 +03:00
|
|
|
min(sizeof(ifr->ifr_hwaddr.sa_data),
|
|
|
|
(size_t)dev->addr_len));
|
2013-02-16 02:20:46 +04:00
|
|
|
call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SIOCSIFMAP:
|
2021-07-22 17:29:00 +03:00
|
|
|
return dev_setifmap(dev, ifr);
|
2013-02-16 02:20:46 +04:00
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
if (!ops->ndo_set_rx_mode ||
|
|
|
|
ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!netif_device_present(dev))
|
|
|
|
return -ENODEV;
|
|
|
|
return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data);
|
|
|
|
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
if (!ops->ndo_set_rx_mode ||
|
|
|
|
ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!netif_device_present(dev))
|
|
|
|
return -ENODEV;
|
|
|
|
return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data);
|
|
|
|
|
|
|
|
case SIOCSIFTXQLEN:
|
|
|
|
if (ifr->ifr_qlen < 0)
|
|
|
|
return -EINVAL;
|
2018-07-24 13:53:00 +03:00
|
|
|
return dev_change_tx_queue_len(dev, ifr->ifr_qlen);
|
2013-02-16 02:20:46 +04:00
|
|
|
|
|
|
|
case SIOCSIFNAME:
|
|
|
|
ifr->ifr_newname[IFNAMSIZ-1] = '\0';
|
|
|
|
return dev_change_name(dev, ifr->ifr_newname);
|
|
|
|
|
2021-07-27 16:45:14 +03:00
|
|
|
case SIOCWANDEV:
|
|
|
|
return dev_siocwandev(dev, &ifr->ifr_settings);
|
|
|
|
|
2021-07-27 16:45:16 +03:00
|
|
|
case SIOCBRADDIF:
|
|
|
|
case SIOCBRDELIF:
|
|
|
|
if (!netif_device_present(dev))
|
|
|
|
return -ENODEV;
|
2021-08-05 11:29:03 +03:00
|
|
|
if (!netif_is_bridge_master(dev))
|
|
|
|
return -EOPNOTSUPP;
|
2021-08-05 11:29:01 +03:00
|
|
|
dev_hold(dev);
|
|
|
|
rtnl_unlock();
|
|
|
|
err = br_ioctl_call(net, netdev_priv(dev), cmd, ifr, NULL);
|
|
|
|
dev_put(dev);
|
|
|
|
rtnl_lock();
|
|
|
|
return err;
|
2021-07-27 16:45:16 +03:00
|
|
|
|
2013-02-16 02:20:46 +04:00
|
|
|
case SIOCSHWTSTAMP:
|
|
|
|
err = net_hwtstamp_validate(ifr);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2020-08-24 01:36:59 +03:00
|
|
|
fallthrough;
|
2013-02-16 02:20:46 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unknown or private ioctl
|
|
|
|
*/
|
|
|
|
default:
|
2021-07-27 16:44:47 +03:00
|
|
|
if (cmd >= SIOCDEVPRIVATE &&
|
|
|
|
cmd <= SIOCDEVPRIVATE + 15)
|
2021-07-27 16:45:12 +03:00
|
|
|
return dev_siocdevprivate(dev, ifr, data, cmd);
|
2021-07-27 16:44:47 +03:00
|
|
|
|
2021-07-27 16:45:13 +03:00
|
|
|
if (cmd == SIOCGMIIPHY ||
|
|
|
|
cmd == SIOCGMIIREG ||
|
|
|
|
cmd == SIOCSMIIREG ||
|
|
|
|
cmd == SIOCSHWTSTAMP ||
|
|
|
|
cmd == SIOCGHWTSTAMP) {
|
|
|
|
err = dev_eth_ioctl(dev, ifr, cmd);
|
|
|
|
} else if (cmd == SIOCBONDENSLAVE ||
|
2013-02-16 02:20:46 +04:00
|
|
|
cmd == SIOCBONDRELEASE ||
|
|
|
|
cmd == SIOCBONDSETHWADDR ||
|
|
|
|
cmd == SIOCBONDSLAVEINFOQUERY ||
|
|
|
|
cmd == SIOCBONDINFOQUERY ||
|
2021-07-27 16:45:16 +03:00
|
|
|
cmd == SIOCBONDCHANGEACTIVE) {
|
2021-07-27 16:45:17 +03:00
|
|
|
err = dev_siocbond(dev, ifr, cmd);
|
2013-02-16 02:20:46 +04:00
|
|
|
} else
|
|
|
|
err = -EINVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dev_load - load a network module
|
|
|
|
* @net: the applicable net namespace
|
|
|
|
* @name: name of interface
|
|
|
|
*
|
|
|
|
* If a network interface is not present and the process has suitable
|
|
|
|
* privileges this function loads the module. If module loading is not
|
|
|
|
* available in this kernel then it becomes a nop.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void dev_load(struct net *net, const char *name)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
int no_module;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
dev = dev_get_by_name_rcu(net, name);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
no_module = !dev;
|
|
|
|
if (no_module && capable(CAP_NET_ADMIN))
|
|
|
|
no_module = request_module("netdev-%s", name);
|
dev_ioctl: remove dev_load() CAP_SYS_MODULE message
Marcel reported to see the following message when autoloading
is being triggered when adding nlmon device:
Loading kernel module for a network device with
CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias
netdev-nlmon instead.
This false-positive happens despite with having correct
capabilities set, e.g. through issuing `ip link del dev nlmon`
more than once on a valid device with name nlmon, but Marcel
has also seen it on creation time when no nlmon module is
previously compiled-in or loaded as module and the device
name equals a link type name (e.g. nlmon, vxlan, team).
Stephen says:
The netdev module alias is a hold over from the past. For
normal devices, people used to create a alias eth0 to and
point it to the type of network device used, that was back
in the bad old ISA days before real discovery.
Also, the tunnels create module alias for the control device
and ip used to use this to autoload the tunnel device.
The message is bogus and should just be removed, I also see
it in a couple of other cases where tap devices are renamed
for other usese.
As mentioned in 8909c9ad8ff0 ("net: don't allow CAP_NET_ADMIN
to load non-netdev kernel modules"), we nevertheless still
might want to leave the old autoloading behaviour in place
as it could break old scripts, so for now, lets just remove
the log message as Stephen suggests.
Reference: http://thread.gmane.org/gmane.linux.kernel/1105168
Reported-by: Marcel Holtmann <marcel@holtmann.org>
Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Cc: Vasiliy Kulikov <segoon@openwall.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-09-03 01:30:05 +04:00
|
|
|
if (no_module && capable(CAP_SYS_MODULE))
|
|
|
|
request_module("%s", name);
|
2013-02-16 02:20:46 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(dev_load);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function handles all "interface"-type I/O control requests. The actual
|
|
|
|
* 'doing' part of this is dev_ifsioc above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dev_ioctl - network device ioctl
|
|
|
|
* @net: the applicable net namespace
|
|
|
|
* @cmd: command to issue
|
2019-03-25 19:17:20 +03:00
|
|
|
* @ifr: pointer to a struct ifreq in user space
|
|
|
|
* @need_copyout: whether or not copy_to_user() should be called
|
2013-02-16 02:20:46 +04:00
|
|
|
*
|
|
|
|
* Issue ioctl functions to devices. This is normally called by the
|
|
|
|
* user space syscall interfaces but can sometimes be useful for
|
|
|
|
* other purposes. The return value is the return from the syscall if
|
|
|
|
* positive or a negative errno code on error.
|
|
|
|
*/
|
|
|
|
|
2021-07-27 16:45:12 +03:00
|
|
|
int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr,
|
|
|
|
void __user *data, bool *need_copyout)
|
2013-02-16 02:20:46 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char *colon;
|
|
|
|
|
2017-10-05 19:59:44 +03:00
|
|
|
if (need_copyout)
|
|
|
|
*need_copyout = true;
|
2013-02-16 02:20:46 +04:00
|
|
|
if (cmd == SIOCGIFNAME)
|
2017-10-05 19:59:44 +03:00
|
|
|
return dev_ifname(net, ifr);
|
2013-02-16 02:20:46 +04:00
|
|
|
|
2017-10-05 19:59:44 +03:00
|
|
|
ifr->ifr_name[IFNAMSIZ-1] = 0;
|
2013-02-16 02:20:46 +04:00
|
|
|
|
2017-10-05 19:59:44 +03:00
|
|
|
colon = strchr(ifr->ifr_name, ':');
|
2013-02-16 02:20:46 +04:00
|
|
|
if (colon)
|
|
|
|
*colon = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See which interface the caller is talking about.
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (cmd) {
|
net: fix dev_ifsioc_locked() race condition
dev_ifsioc_locked() is called with only RCU read lock, so when
there is a parallel writer changing the mac address, it could
get a partially updated mac address, as shown below:
Thread 1 Thread 2
// eth_commit_mac_addr_change()
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
// dev_ifsioc_locked()
memcpy(ifr->ifr_hwaddr.sa_data,
dev->dev_addr,...);
Close this race condition by guarding them with a RW semaphore,
like netdev_get_name(). We can not use seqlock here as it does not
allow blocking. The writers already take RTNL anyway, so this does
not affect the slow path. To avoid bothering existing
dev_set_mac_address() callers in drivers, introduce a new wrapper
just for user-facing callers on ioctl and rtnetlink paths.
Note, bonding also changes slave mac addresses but that requires
a separate patch due to the complexity of bonding code.
Fixes: 3710becf8a58 ("net: RCU locking for simple ioctl()")
Reported-by: "Gong, Sishuai" <sishuai@purdue.edu>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-02-11 22:34:10 +03:00
|
|
|
case SIOCGIFHWADDR:
|
|
|
|
dev_load(net, ifr->ifr_name);
|
|
|
|
ret = dev_get_mac_address(&ifr->ifr_hwaddr, net, ifr->ifr_name);
|
|
|
|
if (colon)
|
|
|
|
*colon = ':';
|
|
|
|
return ret;
|
2013-02-16 02:20:46 +04:00
|
|
|
/*
|
|
|
|
* These ioctl calls:
|
|
|
|
* - can be done by all.
|
|
|
|
* - atomic and do not require locking.
|
|
|
|
* - return a value
|
|
|
|
*/
|
|
|
|
case SIOCGIFFLAGS:
|
|
|
|
case SIOCGIFMETRIC:
|
|
|
|
case SIOCGIFMTU:
|
|
|
|
case SIOCGIFSLAVE:
|
|
|
|
case SIOCGIFMAP:
|
|
|
|
case SIOCGIFINDEX:
|
|
|
|
case SIOCGIFTXQLEN:
|
2018-03-07 01:27:44 +03:00
|
|
|
dev_load(net, ifr->ifr_name);
|
2013-02-16 02:20:46 +04:00
|
|
|
rcu_read_lock();
|
2017-10-05 19:59:44 +03:00
|
|
|
ret = dev_ifsioc_locked(net, ifr, cmd);
|
2013-02-16 02:20:46 +04:00
|
|
|
rcu_read_unlock();
|
2017-10-05 19:59:44 +03:00
|
|
|
if (colon)
|
|
|
|
*colon = ':';
|
2013-02-16 02:20:46 +04:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
case SIOCETHTOOL:
|
2018-03-07 01:27:44 +03:00
|
|
|
dev_load(net, ifr->ifr_name);
|
2013-02-16 02:20:46 +04:00
|
|
|
rtnl_lock();
|
2021-07-27 16:45:12 +03:00
|
|
|
ret = dev_ethtool(net, ifr, data);
|
2013-02-16 02:20:46 +04:00
|
|
|
rtnl_unlock();
|
2017-10-05 19:59:44 +03:00
|
|
|
if (colon)
|
|
|
|
*colon = ':';
|
2013-02-16 02:20:46 +04:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These ioctl calls:
|
|
|
|
* - require superuser power.
|
|
|
|
* - require strict serialization.
|
|
|
|
* - return a value
|
|
|
|
*/
|
|
|
|
case SIOCGMIIPHY:
|
|
|
|
case SIOCGMIIREG:
|
|
|
|
case SIOCSIFNAME:
|
2018-03-07 01:27:44 +03:00
|
|
|
dev_load(net, ifr->ifr_name);
|
2013-02-16 02:20:46 +04:00
|
|
|
if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
rtnl_lock();
|
2021-07-27 16:45:12 +03:00
|
|
|
ret = dev_ifsioc(net, ifr, data, cmd);
|
2013-02-16 02:20:46 +04:00
|
|
|
rtnl_unlock();
|
2017-10-05 19:59:44 +03:00
|
|
|
if (colon)
|
|
|
|
*colon = ':';
|
2013-02-16 02:20:46 +04:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These ioctl calls:
|
|
|
|
* - require superuser power.
|
|
|
|
* - require strict serialization.
|
|
|
|
* - do not return a value
|
|
|
|
*/
|
|
|
|
case SIOCSIFMAP:
|
|
|
|
case SIOCSIFTXQLEN:
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
2020-08-24 01:36:59 +03:00
|
|
|
fallthrough;
|
2013-02-16 02:20:46 +04:00
|
|
|
/*
|
|
|
|
* These ioctl calls:
|
|
|
|
* - require local superuser power.
|
|
|
|
* - require strict serialization.
|
|
|
|
* - do not return a value
|
|
|
|
*/
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
case SIOCSIFMETRIC:
|
|
|
|
case SIOCSIFMTU:
|
|
|
|
case SIOCSIFHWADDR:
|
|
|
|
case SIOCSIFSLAVE:
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
case SIOCSIFHWBROADCAST:
|
|
|
|
case SIOCSMIIREG:
|
|
|
|
case SIOCBONDENSLAVE:
|
|
|
|
case SIOCBONDRELEASE:
|
|
|
|
case SIOCBONDSETHWADDR:
|
|
|
|
case SIOCBONDCHANGEACTIVE:
|
|
|
|
case SIOCBRADDIF:
|
|
|
|
case SIOCBRDELIF:
|
|
|
|
case SIOCSHWTSTAMP:
|
|
|
|
if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
2020-08-24 01:36:59 +03:00
|
|
|
fallthrough;
|
2013-02-16 02:20:46 +04:00
|
|
|
case SIOCBONDSLAVEINFOQUERY:
|
|
|
|
case SIOCBONDINFOQUERY:
|
2018-03-07 01:27:44 +03:00
|
|
|
dev_load(net, ifr->ifr_name);
|
2013-02-16 02:20:46 +04:00
|
|
|
rtnl_lock();
|
2021-07-27 16:45:12 +03:00
|
|
|
ret = dev_ifsioc(net, ifr, data, cmd);
|
2013-02-16 02:20:46 +04:00
|
|
|
rtnl_unlock();
|
2017-10-05 19:59:44 +03:00
|
|
|
if (need_copyout)
|
|
|
|
*need_copyout = false;
|
2013-02-16 02:20:46 +04:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
case SIOCGIFMEM:
|
|
|
|
/* Get the per device memory space. We can add this but
|
|
|
|
* currently do not support it */
|
|
|
|
case SIOCSIFMEM:
|
|
|
|
/* Set the per device memory buffer space.
|
|
|
|
* Not applicable in our case */
|
|
|
|
case SIOCSIFLINK:
|
|
|
|
return -ENOTTY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unknown or private ioctl.
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
if (cmd == SIOCWANDEV ||
|
2013-11-14 05:19:29 +04:00
|
|
|
cmd == SIOCGHWTSTAMP ||
|
2013-02-16 02:20:46 +04:00
|
|
|
(cmd >= SIOCDEVPRIVATE &&
|
|
|
|
cmd <= SIOCDEVPRIVATE + 15)) {
|
2018-03-07 01:27:44 +03:00
|
|
|
dev_load(net, ifr->ifr_name);
|
2013-02-16 02:20:46 +04:00
|
|
|
rtnl_lock();
|
2021-07-27 16:45:12 +03:00
|
|
|
ret = dev_ifsioc(net, ifr, data, cmd);
|
2013-02-16 02:20:46 +04:00
|
|
|
rtnl_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
}
|