033d019ce2
Changes in 4.9.77 dm bufio: fix shrinker scans when (nr_to_scan < retain_target) mac80211: Add RX flag to indicate ICV stripped ath10k: rebuild crypto header in rx data frames KVM: Fix stack-out-of-bounds read in write_mmio can: gs_usb: fix return value of the "set_bittiming" callback IB/srpt: Disable RDMA access by the initiator MIPS: Validate PR_SET_FP_MODE prctl(2) requests against the ABI of the task MIPS: Factor out NT_PRFPREG regset access helpers MIPS: Guard against any partial write attempt with PTRACE_SETREGSET MIPS: Consistently handle buffer counter with PTRACE_SETREGSET MIPS: Fix an FCSR access API regression with NT_PRFPREG and MSA MIPS: Also verify sizeof `elf_fpreg_t' with PTRACE_SETREGSET MIPS: Disallow outsized PTRACE_SETREGSET NT_PRFPREG regset accesses kvm: vmx: Scrub hardware GPRs at VM-exit platform/x86: wmi: Call acpi_wmi_init() later x86/acpi: Handle SCI interrupts above legacy space gracefully ALSA: pcm: Remove incorrect snd_BUG_ON() usages ALSA: pcm: Add missing error checks in OSS emulation plugin builder ALSA: pcm: Abort properly at pending signal in OSS read/write loops ALSA: pcm: Allow aborting mutex lock at OSS read/write loops ALSA: aloop: Release cable upon open error path ALSA: aloop: Fix inconsistent format due to incomplete rule ALSA: aloop: Fix racy hw constraints adjustment x86/acpi: Reduce code duplication in mp_override_legacy_irq() zswap: don't param_set_charp while holding spinlock lan78xx: use skb_cow_head() to deal with cloned skbs sr9700: use skb_cow_head() to deal with cloned skbs smsc75xx: use skb_cow_head() to deal with cloned skbs cx82310_eth: use skb_cow_head() to deal with cloned skbs xhci: Fix ring leak in failure path of xhci_alloc_virt_device() 8021q: fix a memory leak for VLAN 0 device ip6_tunnel: disable dst caching if tunnel is dual-stack net: core: fix module type in sock_diag_bind RDS: Heap OOB write in rds_message_alloc_sgs() RDS: null pointer dereference in rds_atomic_free_op sh_eth: fix TSU resource handling sh_eth: fix SH7757 GEther initialization net: stmmac: enable EEE in MII, GMII or RGMII only ipv6: fix possible mem leaks in ipv6_make_skb() ethtool: do not print warning for applications using legacy API mlxsw: spectrum_router: Fix NULL pointer deref net/sched: Fix update of lastuse in act modules implementing stats_update crypto: algapi - fix NULL dereference in crypto_remove_spawns() rbd: set max_segments to USHRT_MAX x86/microcode/intel: Extend BDW late-loading with a revision check KVM: x86: Add memory barrier on vmcs field lookup drm/vmwgfx: Potential off by one in vmw_view_add() kaiser: Set _PAGE_NX only if supported iscsi-target: Make TASK_REASSIGN use proper se_cmd->cmd_kref target: Avoid early CMD_T_PRE_EXECUTE failures during ABORT_TASK bpf: move fixup_bpf_calls() function bpf: refactor fixup_bpf_calls() bpf: prevent out-of-bounds speculation bpf, array: fix overflow in max_entries and undefined behavior in index_mask USB: serial: cp210x: add IDs for LifeScan OneTouch Verio IQ USB: serial: cp210x: add new device ID ELV ALC 8xxx usb: misc: usb3503: make sure reset is low for at least 100us USB: fix usbmon BUG trigger usbip: remove kernel addresses from usb device and urb debug msgs usbip: fix vudc_rx: harden CMD_SUBMIT path to handle malicious input usbip: vudc_tx: fix v_send_ret_submit() vulnerability to null xfer buffer staging: android: ashmem: fix a race condition in ASHMEM_SET_SIZE ioctl Bluetooth: Prevent stack info leak from the EFS element. uas: ignore UAS for Norelsys NS1068(X) chips e1000e: Fix e1000_check_for_copper_link_ich8lan return value. x86/Documentation: Add PTI description x86/cpu: Factor out application of forced CPU caps x86/cpufeatures: Make CPU bugs sticky x86/cpufeatures: Add X86_BUG_CPU_INSECURE x86/pti: Rename BUG_CPU_INSECURE to BUG_CPU_MELTDOWN x86/cpufeatures: Add X86_BUG_SPECTRE_V[12] x86/cpu: Merge bugs.c and bugs_64.c sysfs/cpu: Add vulnerability folder x86/cpu: Implement CPU vulnerabilites sysfs functions x86/cpu/AMD: Make LFENCE a serializing instruction x86/cpu/AMD: Use LFENCE_RDTSC in preference to MFENCE_RDTSC sysfs/cpu: Fix typos in vulnerability documentation x86/alternatives: Fix optimize_nops() checking x86/alternatives: Add missing '\n' at end of ALTERNATIVE inline asm x86/mm/32: Move setup_clear_cpu_cap(X86_FEATURE_PCID) earlier objtool, modules: Discard objtool annotation sections for modules objtool: Detect jumps to retpoline thunks objtool: Allow alternatives to be ignored x86/asm: Use register variable to get stack pointer value x86/retpoline: Add initial retpoline support x86/spectre: Add boot time option to select Spectre v2 mitigation x86/retpoline/crypto: Convert crypto assembler indirect jumps x86/retpoline/entry: Convert entry assembler indirect jumps x86/retpoline/ftrace: Convert ftrace assembler indirect jumps x86/retpoline/hyperv: Convert assembler indirect jumps x86/retpoline/xen: Convert Xen hypercall indirect jumps x86/retpoline/checksum32: Convert assembler indirect jumps x86/retpoline/irq32: Convert assembler indirect jumps x86/retpoline: Fill return stack buffer on vmexit selftests/x86: Add test_vsyscall x86/retpoline: Remove compile time warning objtool: Fix retpoline support for pre-ORC objtool x86/pti/efi: broken conversion from efi to kernel page table Linux 4.9.77 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
347 lines
8.2 KiB
C
347 lines
8.2 KiB
C
/* License: GPL */
|
|
|
|
#include <linux/mutex.h>
|
|
#include <linux/socket.h>
|
|
#include <linux/skbuff.h>
|
|
#include <net/netlink.h>
|
|
#include <net/net_namespace.h>
|
|
#include <linux/module.h>
|
|
#include <net/sock.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/tcp.h>
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/inet_diag.h>
|
|
#include <linux/sock_diag.h>
|
|
|
|
static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
|
|
static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
|
|
static DEFINE_MUTEX(sock_diag_table_mutex);
|
|
static struct workqueue_struct *broadcast_wq;
|
|
|
|
u64 sock_gen_cookie(struct sock *sk)
|
|
{
|
|
while (1) {
|
|
u64 res = atomic64_read(&sk->sk_cookie);
|
|
|
|
if (res)
|
|
return res;
|
|
res = atomic64_inc_return(&sock_net(sk)->cookie_gen);
|
|
atomic64_cmpxchg(&sk->sk_cookie, 0, res);
|
|
}
|
|
}
|
|
|
|
int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
|
|
{
|
|
u64 res;
|
|
|
|
if (cookie[0] == INET_DIAG_NOCOOKIE && cookie[1] == INET_DIAG_NOCOOKIE)
|
|
return 0;
|
|
|
|
res = sock_gen_cookie(sk);
|
|
if ((u32)res != cookie[0] || (u32)(res >> 32) != cookie[1])
|
|
return -ESTALE;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
|
|
|
|
void sock_diag_save_cookie(struct sock *sk, __u32 *cookie)
|
|
{
|
|
u64 res = sock_gen_cookie(sk);
|
|
|
|
cookie[0] = (u32)res;
|
|
cookie[1] = (u32)(res >> 32);
|
|
}
|
|
EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
|
|
|
|
int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype)
|
|
{
|
|
u32 mem[SK_MEMINFO_VARS];
|
|
|
|
mem[SK_MEMINFO_RMEM_ALLOC] = sk_rmem_alloc_get(sk);
|
|
mem[SK_MEMINFO_RCVBUF] = sk->sk_rcvbuf;
|
|
mem[SK_MEMINFO_WMEM_ALLOC] = sk_wmem_alloc_get(sk);
|
|
mem[SK_MEMINFO_SNDBUF] = sk->sk_sndbuf;
|
|
mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc;
|
|
mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued;
|
|
mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc);
|
|
mem[SK_MEMINFO_BACKLOG] = sk->sk_backlog.len;
|
|
mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops);
|
|
|
|
return nla_put(skb, attrtype, sizeof(mem), &mem);
|
|
}
|
|
EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
|
|
|
|
int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
|
|
struct sk_buff *skb, int attrtype)
|
|
{
|
|
struct sock_fprog_kern *fprog;
|
|
struct sk_filter *filter;
|
|
struct nlattr *attr;
|
|
unsigned int flen;
|
|
int err = 0;
|
|
|
|
if (!may_report_filterinfo) {
|
|
nla_reserve(skb, attrtype, 0);
|
|
return 0;
|
|
}
|
|
|
|
rcu_read_lock();
|
|
filter = rcu_dereference(sk->sk_filter);
|
|
if (!filter)
|
|
goto out;
|
|
|
|
fprog = filter->prog->orig_prog;
|
|
if (!fprog)
|
|
goto out;
|
|
|
|
flen = bpf_classic_proglen(fprog);
|
|
|
|
attr = nla_reserve(skb, attrtype, flen);
|
|
if (attr == NULL) {
|
|
err = -EMSGSIZE;
|
|
goto out;
|
|
}
|
|
|
|
memcpy(nla_data(attr), fprog->filter, flen);
|
|
out:
|
|
rcu_read_unlock();
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(sock_diag_put_filterinfo);
|
|
|
|
struct broadcast_sk {
|
|
struct sock *sk;
|
|
struct work_struct work;
|
|
};
|
|
|
|
static size_t sock_diag_nlmsg_size(void)
|
|
{
|
|
return NLMSG_ALIGN(sizeof(struct inet_diag_msg)
|
|
+ nla_total_size(sizeof(u8)) /* INET_DIAG_PROTOCOL */
|
|
+ nla_total_size_64bit(sizeof(struct tcp_info))); /* INET_DIAG_INFO */
|
|
}
|
|
|
|
static void sock_diag_broadcast_destroy_work(struct work_struct *work)
|
|
{
|
|
struct broadcast_sk *bsk =
|
|
container_of(work, struct broadcast_sk, work);
|
|
struct sock *sk = bsk->sk;
|
|
const struct sock_diag_handler *hndl;
|
|
struct sk_buff *skb;
|
|
const enum sknetlink_groups group = sock_diag_destroy_group(sk);
|
|
int err = -1;
|
|
|
|
WARN_ON(group == SKNLGRP_NONE);
|
|
|
|
skb = nlmsg_new(sock_diag_nlmsg_size(), GFP_KERNEL);
|
|
if (!skb)
|
|
goto out;
|
|
|
|
mutex_lock(&sock_diag_table_mutex);
|
|
hndl = sock_diag_handlers[sk->sk_family];
|
|
if (hndl && hndl->get_info)
|
|
err = hndl->get_info(skb, sk);
|
|
mutex_unlock(&sock_diag_table_mutex);
|
|
|
|
if (!err)
|
|
nlmsg_multicast(sock_net(sk)->diag_nlsk, skb, 0, group,
|
|
GFP_KERNEL);
|
|
else
|
|
kfree_skb(skb);
|
|
out:
|
|
sk_destruct(sk);
|
|
kfree(bsk);
|
|
}
|
|
|
|
void sock_diag_broadcast_destroy(struct sock *sk)
|
|
{
|
|
/* Note, this function is often called from an interrupt context. */
|
|
struct broadcast_sk *bsk =
|
|
kmalloc(sizeof(struct broadcast_sk), GFP_ATOMIC);
|
|
if (!bsk)
|
|
return sk_destruct(sk);
|
|
bsk->sk = sk;
|
|
INIT_WORK(&bsk->work, sock_diag_broadcast_destroy_work);
|
|
queue_work(broadcast_wq, &bsk->work);
|
|
}
|
|
|
|
void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
|
|
{
|
|
mutex_lock(&sock_diag_table_mutex);
|
|
inet_rcv_compat = fn;
|
|
mutex_unlock(&sock_diag_table_mutex);
|
|
}
|
|
EXPORT_SYMBOL_GPL(sock_diag_register_inet_compat);
|
|
|
|
void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
|
|
{
|
|
mutex_lock(&sock_diag_table_mutex);
|
|
inet_rcv_compat = NULL;
|
|
mutex_unlock(&sock_diag_table_mutex);
|
|
}
|
|
EXPORT_SYMBOL_GPL(sock_diag_unregister_inet_compat);
|
|
|
|
int sock_diag_register(const struct sock_diag_handler *hndl)
|
|
{
|
|
int err = 0;
|
|
|
|
if (hndl->family >= AF_MAX)
|
|
return -EINVAL;
|
|
|
|
mutex_lock(&sock_diag_table_mutex);
|
|
if (sock_diag_handlers[hndl->family])
|
|
err = -EBUSY;
|
|
else
|
|
sock_diag_handlers[hndl->family] = hndl;
|
|
mutex_unlock(&sock_diag_table_mutex);
|
|
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(sock_diag_register);
|
|
|
|
void sock_diag_unregister(const struct sock_diag_handler *hnld)
|
|
{
|
|
int family = hnld->family;
|
|
|
|
if (family >= AF_MAX)
|
|
return;
|
|
|
|
mutex_lock(&sock_diag_table_mutex);
|
|
BUG_ON(sock_diag_handlers[family] != hnld);
|
|
sock_diag_handlers[family] = NULL;
|
|
mutex_unlock(&sock_diag_table_mutex);
|
|
}
|
|
EXPORT_SYMBOL_GPL(sock_diag_unregister);
|
|
|
|
static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh)
|
|
{
|
|
int err;
|
|
struct sock_diag_req *req = nlmsg_data(nlh);
|
|
const struct sock_diag_handler *hndl;
|
|
|
|
if (nlmsg_len(nlh) < sizeof(*req))
|
|
return -EINVAL;
|
|
|
|
if (req->sdiag_family >= AF_MAX)
|
|
return -EINVAL;
|
|
|
|
if (sock_diag_handlers[req->sdiag_family] == NULL)
|
|
request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
|
|
NETLINK_SOCK_DIAG, req->sdiag_family);
|
|
|
|
mutex_lock(&sock_diag_table_mutex);
|
|
hndl = sock_diag_handlers[req->sdiag_family];
|
|
if (hndl == NULL)
|
|
err = -ENOENT;
|
|
else if (nlh->nlmsg_type == SOCK_DIAG_BY_FAMILY)
|
|
err = hndl->dump(skb, nlh);
|
|
else if (nlh->nlmsg_type == SOCK_DESTROY && hndl->destroy)
|
|
err = hndl->destroy(skb, nlh);
|
|
else
|
|
err = -EOPNOTSUPP;
|
|
mutex_unlock(&sock_diag_table_mutex);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
|
|
{
|
|
int ret;
|
|
|
|
switch (nlh->nlmsg_type) {
|
|
case TCPDIAG_GETSOCK:
|
|
case DCCPDIAG_GETSOCK:
|
|
if (inet_rcv_compat == NULL)
|
|
request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
|
|
NETLINK_SOCK_DIAG, AF_INET);
|
|
|
|
mutex_lock(&sock_diag_table_mutex);
|
|
if (inet_rcv_compat != NULL)
|
|
ret = inet_rcv_compat(skb, nlh);
|
|
else
|
|
ret = -EOPNOTSUPP;
|
|
mutex_unlock(&sock_diag_table_mutex);
|
|
|
|
return ret;
|
|
case SOCK_DIAG_BY_FAMILY:
|
|
case SOCK_DESTROY:
|
|
return __sock_diag_cmd(skb, nlh);
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
static DEFINE_MUTEX(sock_diag_mutex);
|
|
|
|
static void sock_diag_rcv(struct sk_buff *skb)
|
|
{
|
|
mutex_lock(&sock_diag_mutex);
|
|
netlink_rcv_skb(skb, &sock_diag_rcv_msg);
|
|
mutex_unlock(&sock_diag_mutex);
|
|
}
|
|
|
|
static int sock_diag_bind(struct net *net, int group)
|
|
{
|
|
switch (group) {
|
|
case SKNLGRP_INET_TCP_DESTROY:
|
|
case SKNLGRP_INET_UDP_DESTROY:
|
|
if (!sock_diag_handlers[AF_INET])
|
|
request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
|
|
NETLINK_SOCK_DIAG, AF_INET);
|
|
break;
|
|
case SKNLGRP_INET6_TCP_DESTROY:
|
|
case SKNLGRP_INET6_UDP_DESTROY:
|
|
if (!sock_diag_handlers[AF_INET6])
|
|
request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
|
|
NETLINK_SOCK_DIAG, AF_INET6);
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int sock_diag_destroy(struct sock *sk, int err)
|
|
{
|
|
if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
|
|
return -EPERM;
|
|
|
|
if (!sk->sk_prot->diag_destroy)
|
|
return -EOPNOTSUPP;
|
|
|
|
return sk->sk_prot->diag_destroy(sk, err);
|
|
}
|
|
EXPORT_SYMBOL_GPL(sock_diag_destroy);
|
|
|
|
static int __net_init diag_net_init(struct net *net)
|
|
{
|
|
struct netlink_kernel_cfg cfg = {
|
|
.groups = SKNLGRP_MAX,
|
|
.input = sock_diag_rcv,
|
|
.bind = sock_diag_bind,
|
|
.flags = NL_CFG_F_NONROOT_RECV,
|
|
};
|
|
|
|
net->diag_nlsk = netlink_kernel_create(net, NETLINK_SOCK_DIAG, &cfg);
|
|
return net->diag_nlsk == NULL ? -ENOMEM : 0;
|
|
}
|
|
|
|
static void __net_exit diag_net_exit(struct net *net)
|
|
{
|
|
netlink_kernel_release(net->diag_nlsk);
|
|
net->diag_nlsk = NULL;
|
|
}
|
|
|
|
static struct pernet_operations diag_net_ops = {
|
|
.init = diag_net_init,
|
|
.exit = diag_net_exit,
|
|
};
|
|
|
|
static int __init sock_diag_init(void)
|
|
{
|
|
broadcast_wq = alloc_workqueue("sock_diag_events", 0, 0);
|
|
BUG_ON(!broadcast_wq);
|
|
return register_pernet_subsys(&diag_net_ops);
|
|
}
|
|
device_initcall(sock_diag_init);
|