3.16.60-rc1 review
Subsystems (6)
PATCH 158/366 net: af_packet: fix race in PACKET_{R|T}X_RING
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 5171b37d959641bbc619781caf62e61f7b940871 upstream.
In order to remove the race caught by syzbot [1], we need to lock the socket before using po->tp_version as this could change under us otherwise.
This means lock_sock() and release_sock() must be done by packet_set_ring() callers.
[1] :
BUG: KMSAN: uninit-value in packet_set_ring+0x1254/0x3870 net/packet/af_packet.c:4249 CPU: 0 PID: 20195 Comm: syzkaller707632 Not tainted 4.16.0+ #83 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x185/0x1d0 lib/dump_stack.c:53 kmsan_report+0x142/0x240 mm/kmsan/kmsan.c:1067 __msan_warning_32+0x6c/0xb0 mm/kmsan/kmsan_instr.c:676 packet_set_ring+0x1254/0x3870 net/packet/af_packet.c:4249 packet_setsockopt+0x12c6/0x5a90 net/packet/af_packet.c:3662 SYSC_setsockopt+0x4b8/0x570 net/socket.c:1849 SyS_setsockopt+0x76/0xa0 net/socket.c:1828 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x3d/0xa2 RIP: 0033:0x449099 RSP: 002b:00007f42b5307ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000036 RAX: ffffffffffffffda RBX: 000000000070003c RCX: 0000000000449099 RDX: 0000000000000005 RSI: 0000000000000107 RDI: 0000000000000003 RBP: 0000000000700038 R08: 000000000000001c R09: 0000000000000000 R10: 00000000200000c0 R11: 0000000000000246 R12: 0000000000000000 R13: 000000000080eecf R14: 00007f42b53089c0 R15: 0000000000000001
Local variable description: ----req_u@packet_setsockopt Variable was created at:
packet_setsockopt+0x13f/0x5a90 net/packet/af_packet.c:3612 SYSC_setsockopt+0x4b8/0x570 net/socket.c:1849
[bwh: Backported to 3.16: PACKET_VNET_HDR is incompatible with
PACKET_{TX,RX}_RING; fix up the check for that as well]
---
net/packet/af_packet.c +16 -10
@@ -2651,6 +2651,7 @@ static int packet_release(struct socketpacket_flush_mclist (sk); +lock_sock (sk);if (po->rx_ring.pg_vec) {memset (&req_u,0 ,sizeof (req_u));packet_set_ring (sk, &req_u,1 ,0 );
@@ -2660,6 +2661,7 @@ static int packet_release(struct socketmemset (&req_u,0 ,sizeof (req_u));packet_set_ring (sk, &req_u,1 ,1 ); } +release_sock (sk); f =fanout_release (sk);
@@ -3295,6 +3297,7 @@ packet_setsockopt(struct socket *sock, iunion tpacket_req_u req_u;int len; +lock_sock (sk);switch (po->tp_version) {case TPACKET_V1 :case TPACKET_V2 :
@@ -3305,14 +3308,19 @@ packet_setsockopt(struct socket *sock, i len =sizeof (req_u.req3);break ; } -if (optlen < len) -return -EINVAL ; -if (pkt_sk (sk)->has_vnet_hdr) -return -EINVAL ; -if (copy_from_user (&req_u.req, optval, len)) -return -EFAULT ; -return packet_set_ring (sk, &req_u,0 , - optname ==PACKET_TX_RING ); +if (optlen < len) { + ret = -EINVAL ; + }else if (pkt_sk (sk)->has_vnet_hdr) { + ret = -EINVAL ; + }else { +if (copy_from_user (&req_u.req, optval, len)) + ret = -EFAULT ; +else + ret =packet_set_ring (sk, &req_u,0 , + optname ==PACKET_TX_RING ); + } +release_sock (sk); +return ret; }case PACKET_COPY_THRESH : {
@@ -3820,7 +3828,6 @@ static int packet_set_ring(struct sock */* Added to avoid minimal code churn */ struct tpacket_req *req = &req_u->req; -lock_sock (sk);/* Opening a Tx-ring is NOT supported in TPACKET_V3 */ if (!closing && tx_ring && (po->tp_version >TPACKET_V2 )) {WARN (1 ,"Tx-ring is not supported.\n" );
@@ -3956,7 +3963,6 @@ static int packet_set_ring(struct sock *if (pg_vec)free_pg_vec (pg_vec, order, req->tp_block_nr); out: -release_sock (sk);return err; }
PATCH 159/366 netfilter: nf_tables: can't fail after linking rule into active rule list
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 569ccae68b38654f04b6842b034aa33857f605fe upstream.
rules in nftables a free'd using kfree, but protected by rcu, i.e. we must wait for a grace period to elapse.
Normal removal patch does this, but nf_tables_newrule() doesn't obey this rule during error handling.
It calls nft_trans_rule_add() *after* linking rule, and, if that fails to allocate memory, it unlinks the rule and then kfree() it -- this is unsafe.
Switch order -- first add rule to transaction list, THEN link it to public list.
Note: nft_trans_rule_add() uses GFP_KERNEL; it will not fail so this is not a problem in practice (spotted only during code review).
--- net/netfilter/nf_tables_api.c | 59 +++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 27 deletions(-)
net/netfilter/nf_tables_api.c +32 -27
@@ -1829,41 +1829,46 @@ static int nf_tables_newrule(struct sock }if (nlh->nlmsg_flags &NLM_F_REPLACE ) { -if (nft_rule_is_active_next (net, old_rule)) { - trans =nft_trans_rule_add (&ctx,NFT_MSG_DELRULE , - old_rule); -if (trans ==NULL ) { - err = -ENOMEM ; - goto err2; - } -nft_rule_disactivate_next (net, old_rule); - chain->use--; -list_add_tail_rcu (&rule->list, &old_rule->list); - }else { +if (!nft_rule_is_active_next (net, old_rule)) { err = -ENOENT ; goto err2; } - }else if (nlh->nlmsg_flags &NLM_F_APPEND ) -if (old_rule) -list_add_rcu (&rule->list, &old_rule->list); -else -list_add_tail_rcu (&rule->list, &chain->rules); -else { -if (old_rule) -list_add_tail_rcu (&rule->list, &old_rule->list); -else -list_add_rcu (&rule->list, &chain->rules); - } + trans =nft_trans_rule_add (&ctx,NFT_MSG_DELRULE , + old_rule); +if (trans ==NULL ) { + err = -ENOMEM ; + goto err2; + } +nft_rule_disactivate_next (net, old_rule); + chain->use--; + +if (nft_trans_rule_add (&ctx,NFT_MSG_NEWRULE , rule) ==NULL ) { + err = -ENOMEM ; + goto err2; + } -if (nft_trans_rule_add (&ctx,NFT_MSG_NEWRULE , rule) ==NULL ) { - err = -ENOMEM ; - goto err3; +list_add_tail_rcu (&rule->list, &old_rule->list); + }else { +if (nft_trans_rule_add (&ctx,NFT_MSG_NEWRULE , rule) ==NULL ) { + err = -ENOMEM ; + goto err2; + } + +if (nlh->nlmsg_flags &NLM_F_APPEND ) { +if (old_rule) +list_add_rcu (&rule->list, &old_rule->list); +else +list_add_tail_rcu (&rule->list, &chain->rules); + }else { +if (old_rule) +list_add_tail_rcu (&rule->list, &old_rule->list); +else +list_add_rcu (&rule->list, &chain->rules); + } } chain->use++;return 0 ; -err3: -list_del_rcu (&rule->list); err2:nf_tables_rule_destroy (&ctx, rule); err1:
PATCH 160/366 RDMA/ucma: ucma_context reference leak in error path
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shamir Rabinovitch <[email protected]>
commit ef95a90ae6f4f21990e1f7ced6719784a409e811 upstream.
Validating input parameters should be done before getting the cm_id otherwise it can leak a cm_id reference.
--- drivers/infiniband/core/ucma.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/infiniband/core/ucma.c +3 -3
@@ -1204,13 +1204,13 @@ static ssize_t ucma_set_option(struct ucif (copy_from_user (&cmd, inbuf,sizeof (cmd)))return -EFAULT ; +if (unlikely (cmd.optlen >KMALLOC_MAX_SIZE )) +return -EINVAL ; + ctx =ucma_get_ctx (file, cmd.id);if (IS_ERR (ctx))return PTR_ERR (ctx); -if (unlikely (cmd.optlen >KMALLOC_MAX_SIZE )) -return -EINVAL ; - optval =memdup_user ((void __user *) (unsigned long ) cmd.optval, cmd.optlen);if (IS_ERR (optval)) {
PATCH 161/366 MIPS: memset.S: EVA & fault support for small_memset
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit 8a8158c85e1e774a44fbe81106fa41138580dfd1 upstream.
The MIPS kernel memset / bzero implementation includes a small_memset branch which is used when the region to be set is smaller than a long (4 bytes on 32bit, 8 bytes on 64bit). The current small_memset implementation uses a simple store byte loop to write the destination. There are 2 issues with this implementation:
1. When EVA mode is active, user and kernel address spaces may overlap. Currently the use of the sb instruction means kernel mode addressing is always used and an intended write to userspace may actually overwrite some critical kernel data.
2. If the write triggers a page fault, for example by calling __clear_user(NULL, 2), instead of gracefully handling the fault, an OOPS is triggered.
Fix these issues by replacing the sb instruction with the EX() macro, which will emit EVA compatible instuctions as required. Additionally implement a fault fixup for small_memset which sets a2 to the number of bytes that could not be cleared (as defined by __clear_user).
Patchwork: https://patchwork.linux-mips.org/patch/18975/
--- arch/mips/lib/memset.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/mips/lib/memset.S +6 -1
@@ -178,7 +178,7 @@ 1: PTR_ADDIU a0, 1 /* fill bytewise */ R10KCBARRIER(0(ra)) bne t1, a0, 1b - sb a1, -1(a0) + EX(sb, a1, -1(a0), .Lsmall_fixup\@) 2: jr ra /* done */ move a2, zero
@@ -212,6 +212,11 @@ jr ra andi v1, a2, STORMASK +.Lsmall_fixup\@: + PTR_SUBU a2, t1, a0 + jr ra + PTR_ADDIU a2, 1 + .endm /*
PATCH 162/366 KVM: arm/arm64: Close VMID generation race
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
commit f0cf47d939d0b4b4f660c5aaa4276fa3488f3391 upstream.
Before entering the guest, we check whether our VMID is still part of the current generation. In order to avoid taking a lock, we start with checking that the generation is still current, and only if not current do we take the lock, recheck, and update the generation and VMID.
This leaves open a small race: A vcpu can bump up the global generation number as well as the VM's, but has not updated the VMID itself yet.
At that point another vcpu from the same VM comes in, checks the generation (and finds it not needing anything), and jumps into the guest. At this point, we end-up with two vcpus belonging to the same VM running with two different VMIDs. Eventually, the VMID used by the second vcpu will get reassigned, and things will really go wrong...
A simple solution would be to drop this initial check, and always take the lock. This is likely to cause performance issues. A middle ground is to convert the spinlock to a rwlock, and only take the read lock on the fast path. If the check fails at that point, drop it and acquire the write lock, rechecking the condition.
This ensures that the above scenario doesn't occur.
--- arch/arm/kvm/arm.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
arch/arm/kvm/arm.c +10 -5
@@ -59,7 +59,7 @@ static DEFINE_PER_CPU(struct kvm_vcpu *,/* The VMID used in the VTTBR */ static atomic64_t kvm_vmid_gen =ATOMIC64_INIT (1 );static u8 kvm_next_vmid; -static DEFINE_SPINLOCK (kvm_vmid_lock); +static DEFINE_RWLOCK (kvm_vmid_lock);static bool vgic_present;
@@ -391,11 +391,16 @@ static void update_vttbr(struct kvm *kvm {phys_addr_t pgd_phys;u64 vmid; +bool new_gen; -if (!need_new_vmid_gen (kvm)) +read_lock (&kvm_vmid_lock); + new_gen =need_new_vmid_gen (kvm); +read_unlock (&kvm_vmid_lock); + +if (!new_gen)return ; -spin_lock (&kvm_vmid_lock); +write_lock (&kvm_vmid_lock);/* * We need to re-check the vmid_gen here to ensure that if another vcpu
@@ -403,7 +408,7 @@ static void update_vttbr(struct kvm *kvm* use the same vmid. */ if (!need_new_vmid_gen (kvm)) { -spin_unlock (&kvm_vmid_lock); +write_unlock (&kvm_vmid_lock);return ; }
@@ -436,7 +441,7 @@ static void update_vttbr(struct kvm *kvm vmid = ((u64)(kvm->arch.vmid) <<VTTBR_VMID_SHIFT ) &VTTBR_VMID_MASK ; kvm->arch.vttbr = pgd_phys | vmid; -spin_unlock (&kvm_vmid_lock); +write_unlock (&kvm_vmid_lock); }static int kvm_vcpu_first_run_init (struct kvm_vcpu *vcpu)
PATCH 163/366 x86/tsc: Prevent 32bit truncation in calc_hpet_ref()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xiaoming Gao <[email protected]>
commit d3878e164dcd3925a237a20e879432400e369172 upstream.
The TSC calibration code uses HPET as reference. The conversion normalizes the delta of two HPET timestamps:
hpetref = ((tshpet1 - tshpet2) * HPET_PERIOD) / 1e6
and then divides the normalized delta of the corresponding TSC timestamps by the result to calulate the TSC frequency.
tscfreq = ((tstsc1 - tstsc2 ) * 1e6) / hpetref
This uses do_div() which takes an u32 as the divisor, which worked so far because the HPET frequency was low enough that 'hpetref' never exceeded 32bit.
On Skylake machines the HPET frequency increased so 'hpetref' can exceed 32bit. do_div() truncates the divisor, which causes the calibration to fail.
Use div64_u64() to avoid the problem.
[ tglx: Fixes whitespace mangled patch and rewrote changelog ]
--- arch/x86/kernel/tsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/tsc.c +1 -1
@@ -398,7 +398,7 @@ static unsigned long calc_hpet_ref(u64 d hpet2 -= hpet1; tmp = ((u64 )hpet2 *hpet_readl (HPET_PERIOD ));do_div (tmp,1000000 ); -do_div (deltatsc, tmp); + deltatsc =div64_u64 (deltatsc, tmp);return (unsigned long ) deltatsc; }
PATCH 164/366 x86/acpi: Prevent X2APIC id 0xffffffff from being accounted
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dou Liyang <[email protected]>
commit 10daf10ab154e31237a8c07242be3063fb6a9bf4 upstream.
RongQing reported that there are some X2APIC id 0xffffffff in his machine's ACPI MADT table, which makes the number of possible CPU inaccurate.
The reason is that the ACPI X2APIC parser has no sanity check for APIC ID 0xffffffff, which is an invalid id in all APIC types. See "Intel® 64 Architecture x2APIC Specification", Chapter 2.4.1.
Add a sanity check to acpi_parse_x2apic() which ignores the invalid id.
---
arch/x86/kernel/acpi/boot.c +5 -0
@@ -227,6 +227,11 @@ acpi_parse_x2apic(struct acpi_subtable_h apic_id = processor->local_apic_id; enabled = processor->lapic_flags &ACPI_MADT_ENABLED ; + +/* Ignore invalid ID */ +if (apic_id ==0xffffffff ) +return 0 ; +#ifdef CONFIG_X86_X2APIC /* * We need to register disabled CPU as well to permit
PATCH 165/366 x86/mm: Prevent kernel Oops in PTDUMP code with HIGHPTE=y
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joerg Roedel <[email protected]>
commit d6ef1f194b7569af8b8397876dc9ab07649d63cb upstream.
The walk_pte_level() function just uses __va to get the virtual address of the PTE page, but that breaks when the PTE page is not in the direct mapping with HIGHPTE=y.
The result is an unhandled kernel paging request at some random address when accessing the current_kernel or current_user file.
Use the correct API to access PTE pages.
[bwh: Backported to 3.16:
- Keep using pte_pgprot() to get protection flags
- Adjust context]
---
arch/x86/mm/dump_pagetables.c +6 -4
@@ -16,6 +16,7 @@#include <linux/mm.h> #include <linux/module.h> #include <linux/seq_file.h> +#include <linux/highmem.h> #include <asm/pgtable.h>
@@ -263,15 +264,16 @@ static void walk_pte_level(struct seq_fi unsigned long P) {int i; -pte_t *start; +pte_t *pte; - start = (pte_t *)pmd_page_vaddr (addr);for (i =0 ; i <PTRS_PER_PTE ; i++) { -pgprot_t prot =pte_pgprot (*start); +pgprot_t prot; st->current_address =normalize_addr (P + i *PTE_LEVEL_MULT ); + pte =pte_offset_map (&addr, st->current_address); + prot =pte_pgprot (*pte);note_page (m, st, prot,4 ); - start++; +pte_unmap (pte); } }
PATCH 166/366 MIPS: memset.S: Fix return of __clear_user from Lpartial_fixup
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit daf70d89f80c6e1772233da9e020114b1254e7e0 upstream.
The __clear_user function is defined to return the number of bytes that could not be cleared. From the underlying memset / bzero implementation this means setting register a2 to that number on return. Currently if a page fault is triggered within the memset_partial block, the value loaded into a2 on return is meaningless.
The label .Lpartial_fixup\@ is jumped to on page fault. In order to work out how many bytes failed to copy, the exception handler should find how many bytes left in the partial block (andi a2, STORMASK), add that to the partial block end address (a2), and subtract the faulting address to get the remainder. Currently it incorrectly subtracts the partial block start address (t1), which has additionally been clobbered to generate a jump target in memset_partial. Fix this by adding the block end address instead.
This issue was found with the following test code:
int j, k;
for (j = 0; j < 512; j++) {
if ((k = clear_user(NULL, j)) != j) {
pr_err("clear_user (NULL %d) returned %d\n", j, k);
}
}Which now passes on Creator Ci40 (MIPS32) and Cavium Octeon II (MIPS64).
Patchwork: https://patchwork.linux-mips.org/patch/19108/
--- arch/mips/lib/memset.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/memset.S +1 -1
@@ -204,7 +204,7 @@ PTR_L t0, TI_TASK($28) andi a2, STORMASK LONG_L t0, THREAD_BUADDR(t0) - LONG_ADDU a2, t1 + LONG_ADDU a2, a0 jr ra LONG_SUBU a2, t0
PATCH 167/366 vlan: Fix reading memory beyond skb->tail in skb_vlan_tagged_multi
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Toshiaki Makita <[email protected]>
commit 7ce2367254e84753bceb07327aaf5c953cfce117 upstream.
Syzkaller spotted an old bug which leads to reading skb beyond tail by 4 bytes on vlan tagged packets.
This is caused because skb_vlan_tagged_multi() did not check skb_headlen.
BUG: KMSAN: uninit-value in eth_type_vlan include/linux/if_vlan.h:283 [inline] BUG: KMSAN: uninit-value in skb_vlan_tagged_multi include/linux/if_vlan.h:656 [inline] BUG: KMSAN: uninit-value in vlan_features_check include/linux/if_vlan.h:672 [inline] BUG: KMSAN: uninit-value in dflt_features_check net/core/dev.c:2949 [inline] BUG: KMSAN: uninit-value in netif_skb_features+0xd1b/0xdc0 net/core/dev.c:3009 CPU: 1 PID: 3582 Comm: syzkaller435149 Not tainted 4.16.0+ #82 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x185/0x1d0 lib/dump_stack.c:53 kmsan_report+0x142/0x240 mm/kmsan/kmsan.c:1067 __msan_warning_32+0x6c/0xb0 mm/kmsan/kmsan_instr.c:676 eth_type_vlan include/linux/if_vlan.h:283 [inline] skb_vlan_tagged_multi include/linux/if_vlan.h:656 [inline] vlan_features_check include/linux/if_vlan.h:672 [inline] dflt_features_check net/core/dev.c:2949 [inline] netif_skb_features+0xd1b/0xdc0 net/core/dev.c:3009 validate_xmit_skb+0x89/0x1320 net/core/dev.c:3084 __dev_queue_xmit+0x1cb2/0x2b60 net/core/dev.c:3549 dev_queue_xmit+0x4b/0x60 net/core/dev.c:3590 packet_snd net/packet/af_packet.c:2944 [inline] packet_sendmsg+0x7c57/0x8a10 net/packet/af_packet.c:2969 sock_sendmsg_nosec net/socket.c:630 [inline] sock_sendmsg net/socket.c:640 [inline] sock_write_iter+0x3b9/0x470 net/socket.c:909 do_iter_readv_writev+0x7bb/0x970 include/linux/fs.h:1776 do_iter_write+0x30d/0xd40 fs/read_write.c:932 vfs_writev fs/read_write.c:977 [inline] do_writev+0x3c9/0x830 fs/read_write.c:1012 SYSC_writev+0x9b/0xb0 fs/read_write.c:1085 SyS_writev+0x56/0x80 fs/read_write.c:1082 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x3d/0xa2 RIP: 0033:0x43ffa9 RSP: 002b:00007fff2cff3948 EFLAGS: 00000217 ORIG_RAX: 0000000000000014 RAX: ffffffffffffffda RBX: 00000000004002c8 RCX: 000000000043ffa9 RDX: 0000000000000001 RSI: 0000000020000080 RDI: 0000000000000003 RBP: 00000000006cb018 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000217 R12: 00000000004018d0 R13: 0000000000401960 R14: 0000000000000000 R15: 0000000000000000
Uninit was created at:
kmsan_save_stack_with_flags mm/kmsan/kmsan.c:278 [inline] kmsan_internal_poison_shadow+0xb8/0x1b0 mm/kmsan/kmsan.c:188 kmsan_kmalloc+0x94/0x100 mm/kmsan/kmsan.c:314 kmsan_slab_alloc+0x11/0x20 mm/kmsan/kmsan.c:321 slab_post_alloc_hook mm/slab.h:445 [inline] slab_alloc_node mm/slub.c:2737 [inline] __kmalloc_node_track_caller+0xaed/0x11c0 mm/slub.c:4369 __kmalloc_reserve net/core/skbuff.c:138 [inline] __alloc_skb+0x2cf/0x9f0 net/core/skbuff.c:206 alloc_skb include/linux/skbuff.h:984 [inline] alloc_skb_with_frags+0x1d4/0xb20 net/core/skbuff.c:5234 sock_alloc_send_pskb+0xb56/0x1190 net/core/sock.c:2085 packet_alloc_skb net/packet/af_packet.c:2803 [inline] packet_snd net/packet/af_packet.c:2894 [inline] packet_sendmsg+0x6444/0x8a10 net/packet/af_packet.c:2969 sock_sendmsg_nosec net/socket.c:630 [inline] sock_sendmsg net/socket.c:640 [inline] sock_write_iter+0x3b9/0x470 net/socket.c:909 do_iter_readv_writev+0x7bb/0x970 include/linux/fs.h:1776 do_iter_write+0x30d/0xd40 fs/read_write.c:932 vfs_writev fs/read_write.c:977 [inline] do_writev+0x3c9/0x830 fs/read_write.c:1012 SYSC_writev+0x9b/0xb0 fs/read_write.c:1085 SyS_writev+0x56/0x80 fs/read_write.c:1082 do_syscall_64+0x309/0x430 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x3d/0xa2
---
net/core/dev.c +2 -1
@@ -2608,7 +2608,8 @@ netdev_features_t netif_skb_features(strif (!vlan_tx_tag_present (skb)) {if (unlikely (protocol ==htons (ETH_P_8021Q ) || - protocol ==htons (ETH_P_8021AD ))) { + protocol ==htons (ETH_P_8021AD )) && +likely (pskb_may_pull (skb,VLAN_ETH_HLEN ))) {struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; protocol = veh->h_vlan_encapsulated_proto; }else {
PATCH 168/366 KEYS: DNS: limit the length of option strings
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 9c438d7a3a52dcc2b9ed095cb87d3a5e83cf7e60 upstream.
Adding a dns_resolver key whose payload contains a very long option name resulted in that string being printed in full. This hit the WARN_ONCE() in set_precision() during the printk(), because printk() only supports a precision of up to 32767 bytes:
precision 1000000 too large
WARNING: CPU: 0 PID: 752 at lib/vsprintf.c:2189 vsnprintf+0x4bc/0x5b0Fix it by limiting option strings (combined name + value) to a much more reasonable 128 bytes. The exact limit is arbitrary, but currently the only recognized option is formatted as "dnserror=%lu" which fits well within this limit.
Also ratelimit the printks.
Reproducer:
perl -e 'print "#", "A" x 1000000, "\x00"' | keyctl padd dns_resolver desc @s
This bug was found using syzkaller.
[bwh: Backported to 3.16:
- Also stop logging the key serial number
- Include <linux/ratelimit.h> directly]
---
net/dns_resolver/dns_key.c +6 -8
@@ -29,6 +29,7 @@#include <linux/keyctl.h> #include <linux/err.h> #include <linux/seq_file.h> +#include <linux/ratelimit.h> #include <keys/dns_resolver-type.h> #include <keys/user-type.h> #include "internal.h"
@@ -93,10 +94,9 @@ dns_resolver_instantiate(struct key *key next_opt =memchr (opt,'#' , end - opt) ?: end; opt_len = next_opt - opt; -if (!opt_len) { -printk (KERN_WARNING -"Empty option to dns_resolver key %d\n" , - key->serial); +if (opt_len <=0 || opt_len >128 ) { +pr_warn_ratelimited ("Invalid option length (%d) for dns_resolver key\n" , + opt_len);return -EINVAL ; }
@@ -130,10 +130,8 @@ dns_resolver_instantiate(struct key *key } bad_option_value: -printk (KERN_WARNING -"Option '%*.*s' to dns_resolver key %d:" -" bad/missing value\n" , - opt_nlen, opt_nlen, opt, key->serial); +pr_warn_ratelimited ("Option '%*.*s' to dns_resolver key: bad/missing value\n" , + opt_nlen, opt_nlen, opt);return -EINVAL ; }while (opt = next_opt +1 , opt < end); }
PATCH 169/366 ext4: set h_journal if there is a failure starting a reserved handle
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Theodore Ts'o <[email protected]>
commit b2569260d55228b617bd82aba6d0db2faeeb4116 upstream.
If ext4 tries to start a reserved handle via jbd2_journal_start_reserved(), and the journal has been aborted, this can result in a NULL pointer dereference. This is because the fields h_journal and h_transaction in the handle structure share the same memory, via a union, so jbd2_journal_start_reserved() will clear h_journal before calling start_this_handle(). If this function fails due to an aborted handle, h_journal will still be NULL, and the call to jbd2_journal_free_reserved() will pass a NULL journal to sub_reserve_credits().
This can be reproduced by running "kvm-xfstests -c dioread_nolock generic/475".
--- fs/jbd2/transaction.c | 1 + 1 file changed, 1 insertion(+)
fs/jbd2/transaction.c +1 -0
@@ -515,6 +515,7 @@ int jbd2_journal_start_reserved(handle_t*/ ret =start_this_handle (journal, handle,GFP_NOFS );if (ret <0 ) { + handle->h_journal = journal;jbd2_journal_free_reserved (handle);return ret; }
PATCH 170/366 MIPS: memset.S: Fix clobber of v1 in last_fixup
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit c96eebf07692e53bf4dd5987510d8b550e793598 upstream.
The label .Llast_fixup\@ is jumped to on page fault within the final byte set loop of memset (on < MIPSR6 architectures). For some reason, in this fault handler, the v1 register is randomly set to a2 & STORMASK. This clobbers v1 for the calling function. This can be observed with the following test code:
static int __init __attribute__((optimize("O0"))) test_clear_user(void) {
register int t asm("v1");
char *test;
int j, k;
pr_info("\n\n\nTesting clear_user\n");
test = vmalloc(PAGE_SIZE);
for (j = 256; j < 512; j++) {
t = 0xa5a5a5a5;
if ((k = clear_user(test + PAGE_SIZE - 256, j)) != j - 256) {
pr_err("clear_user (%px %d) returned %d\n", test + PAGE_SIZE - 256, j, k);
}
if (t != 0xa5a5a5a5) {
pr_err("v1 was clobbered to 0x%x!\n", t);
}
} return 0;
}late_initcall(test_clear_user);
Which demonstrates that v1 is indeed clobbered (MIPS64):
Testing clear_user
v1 was clobbered to 0x1!
v1 was clobbered to 0x2!
v1 was clobbered to 0x3!
v1 was clobbered to 0x4!
v1 was clobbered to 0x5!
v1 was clobbered to 0x6!
v1 was clobbered to 0x7!
Since the number of bytes that could not be set is already contained in a2, the andi placing a value in v1 is not necessary and actively harmful in clobbering v1.
Patchwork: https://patchwork.linux-mips.org/patch/19109/
--- arch/mips/lib/memset.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/lib/memset.S +1 -1
@@ -210,7 +210,7 @@ .Llast_fixup\@: jr ra - andi v1, a2, STORMASK + nop .Lsmall_fixup\@: PTR_SUBU a2, t1, a0
PATCH 171/366 MIPS: uaccess: Add micromips clobbers to bzero invocation
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matt Redfearn <[email protected]>
commit b3d7e55c3f886493235bfee08e1e5a4a27cbcce8 upstream.
The micromips implementation of bzero additionally clobbers registers t7 & t8. Specify this in the clobbers list when invoking bzero.
Patchwork: https://patchwork.linux-mips.org/patch/19110/
--- arch/mips/include/asm/uaccess.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/mips/include/asm/uaccess.h +9 -2
@@ -1210,6 +1210,13 @@ __clear_user(void __user *addr, __kernel {__kernel_size_t res; +#ifdef CONFIG_CPU_MICROMIPS +/* micromips memset / bzero also clobbers t7 & t8 */ +#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$15", "$24", "$31" +#else +#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$31" +#endif /* CONFIG_CPU_MICROMIPS */ +if (config_enabled (CONFIG_EVA ) &&segment_eq (get_fs (),get_ds ())) { __asm__ __volatile__( "move\t$4, %1\n\t"
@@ -1219,7 +1226,7 @@ __clear_user(void __user *addr, __kernel "move\t%0, $6" : "=r" (res) : "r" (addr), "r" (size) - : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31"); + : bzero_clobbers); }else {might_fault (); __asm__ __volatile__(
@@ -1230,7 +1237,7 @@ __clear_user(void __user *addr, __kernel "move\t%0, $6" : "=r" (res) : "r" (addr), "r" (size) - : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31"); + : bzero_clobbers); }return res;
PATCH 172/366 powerpc/eeh: Fix enabling bridge MMIO windows
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Michael Neuling <[email protected]>
commit 13a83eac373c49c0a081cbcd137e79210fe78acd upstream.
On boot we save the configuration space of PCIe bridges. We do this so when we get an EEH event and everything gets reset that we can restore them.
Unfortunately we save this state before we've enabled the MMIO space on the bridges. Hence if we have to reset the bridge when we come back MMIO is not enabled and we end up taking an PE freeze when the driver starts accessing again.
This patch forces the memory/MMIO and bus mastering on when restoring bridges on EEH. Ideally we'd do this correctly by saving the configuration space writes later, but that will have to come later in a larger EEH rewrite. For now we have this simple fix.
The original bug can be triggered on a boston machine by doing:
echo 0x8000000000000000 > /sys/kernel/debug/powerpc/PCI0001/err_injct_outbound
On boston, this PHB has a PCIe switch on it. Without this patch, you'll see two EEH events, 1 expected and 1 the failure we are fixing here. The second EEH event causes the anything under the PHB to disappear (i.e. the i40e eth).
With this patch, only 1 EEH event occurs and devices properly recover.
--- arch/powerpc/kernel/eeh_pe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/eeh_pe.c +2 -1
@@ -723,7 +723,8 @@ static void eeh_restore_bridge_bars(stru eeh_ops->write_config (dn,15 *4 ,4 , edev->config_space[15 ]);/* PCI Command: 0x4 */ - eeh_ops->write_config (dn,PCI_COMMAND ,4 , edev->config_space[1 ]); + eeh_ops->write_config (dn,PCI_COMMAND ,4 , edev->config_space[1 ] | +PCI_COMMAND_MEMORY |PCI_COMMAND_MASTER );/* Check the PCIe link is ready */ eeh_bridge_check_link (edev, dn);
PATCH 173/366 scsi: mptsas: Disable WRITE SAME
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Martin K. Petersen" <[email protected]>
commit 94e5395d2403c8bc2504a7cbe4c4caaacb7b8b84 upstream.
First generation MPT Fusion controllers can not translate WRITE SAME when the attached device is a SATA drive. Disable WRITE SAME support.
--- drivers/message/fusion/mptsas.c | 1 + 1 file changed, 1 insertion(+)
drivers/message/fusion/mptsas.c +1 -0
@@ -1996,6 +1996,7 @@ static struct scsi_host_template mptsas_ .cmd_per_lun = 7, .use_clustering = ENABLE_CLUSTERING, .shost_attrs = mptscsih_host_attrs, + .no_write_same = 1, };static int mptsas_get_linkerrors (struct sas_phy *phy)
PATCH 174/366 scsi: sd: Defer spinning up drive while SANITIZE is in progress
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mahesh Rajashekhara <[email protected]>
commit 505aa4b6a8834a2300971c5220c380c3271ebde3 upstream.
A drive being sanitized will return NOT READY / ASC 0x4 / ASCQ 0x1b ("LOGICAL UNIT NOT READY. SANITIZE IN PROGRESS").
Prevent spinning up the drive until this condition clears.
[mkp: tweaked commit message]
--- drivers/scsi/sd.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/sd.c +2 -0
@@ -1832,6 +1832,8 @@ sd_spinup_disk(struct scsi_disk *sdkp)break ;/* standby */ if (sshdr.asc ==4 && sshdr.ascq ==0xc )break ;/* unavailable */ +if (sshdr.asc ==4 && sshdr.ascq ==0x1b ) +break ;/* sanitize in progress */ /* * Issue command to spin up drive when not ready */
PATCH 175/366 drm/msm: fix leak in failed get_pages
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Prakash Kamliya <[email protected]>
commit 62e3a3e342af3c313ab38603811ecdb1fcc79edb upstream.
get_pages doesn't keep a reference of the pages allocated when it fails later in the code path. This can lead to a memory leak. Keep reference of the allocated pages so that it can be freed when msm_gem_free_object gets called later during cleanup.
--- drivers/gpu/drm/msm/msm_gem.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/msm/msm_gem.c +10 -4
@@ -83,14 +83,17 @@ static struct page **get_pages(struct drreturn p; } + msm_obj->pages = p; + msm_obj->sgt =drm_prime_pages_to_sg (p, npages);if (IS_ERR (msm_obj->sgt)) { +void *ptr =ERR_CAST (msm_obj->sgt); +dev_err (dev->dev,"failed to allocate sgt\n" ); -return ERR_CAST (msm_obj->sgt); + msm_obj->sgt =NULL ; +return ptr; } - msm_obj->pages = p; -/* For non-cached buffers, ensure the new pages are clean * because display controller, GPU, etc. are not coherent: */
@@ -113,7 +116,10 @@ static void put_pages(struct drm_gem_objif (msm_obj->flags & (MSM_BO_WC |MSM_BO_UNCACHED ))dma_unmap_sg (obj->dev->dev, msm_obj->sgt->sgl, msm_obj->sgt->nents,DMA_BIDIRECTIONAL ); -sg_free_table (msm_obj->sgt); + +if (msm_obj->sgt) +sg_free_table (msm_obj->sgt); +kfree (msm_obj->sgt);if (iommu_present (&platform_bus_type))
PATCH 176/366 drm/msm: Fix possible null dereference on failure of get_pages()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ben Hutchings <[email protected]>
commit 3976626ea3d2011f8fd3f3a47070a8b792018253 upstream.
Commit 62e3a3e342af changed get_pages() to initialise msm_gem_object::pages before trying to initialise msm_gem_object::sgt, so that put_pages() would properly clean up pages in the failure case.
However, this means that put_pages() now needs to check that msm_gem_object::sgt is not null before trying to clean it up, and this check was only applied to part of the cleanup code. Move it all into the conditional block. (Strictly speaking we don't need to make the kfree() conditional, but since we can't avoid checking for null ourselves we may as well do so.)
--- drivers/gpu/drm/msm/msm_gem.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/msm/msm_gem.c +11 -9
@@ -110,17 +110,19 @@ static void put_pages(struct drm_gem_objstruct msm_gem_object *msm_obj =to_msm_bo (obj);if (msm_obj->pages) { -/* For non-cached buffers, ensure the new pages are clean -* because display controller, GPU, etc. are not coherent: -*/ -if (msm_obj->flags & (MSM_BO_WC |MSM_BO_UNCACHED )) -dma_unmap_sg (obj->dev->dev, msm_obj->sgt->sgl, - msm_obj->sgt->nents,DMA_BIDIRECTIONAL ); +if (msm_obj->sgt) { +/* For non-cached buffers, ensure the new +* pages are clean because display controller, +* GPU, etc. are not coherent: +*/ +if (msm_obj->flags & (MSM_BO_WC |MSM_BO_UNCACHED )) +dma_unmap_sg (obj->dev->dev, msm_obj->sgt->sgl, + msm_obj->sgt->nents, +DMA_BIDIRECTIONAL ); -if (msm_obj->sgt)sg_free_table (msm_obj->sgt); - -kfree (msm_obj->sgt); +kfree (msm_obj->sgt); + }if (iommu_present (&platform_bus_type))drm_gem_put_pages (obj, msm_obj->pages, true, false);
PATCH 177/366 ALSA: rawmidi: Fix missing input substream checks in compat ioctls
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 8a56ef4f3ffba9ebf4967b61ef600b0a7ba10f11 upstream.
Some rawmidi compat ioctls lack of the input substream checks (although they do check only for rfile->output). This many eventually lead to an Oops as NULL substream is passed to the rawmidi core functions.
Fix it by adding the proper checks before each function call.
The bug was spotted by syzkaller.
--- sound/core/rawmidi_compat.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
sound/core/rawmidi_compat.c +12 -6
@@ -36,8 +36,6 @@ static int snd_rawmidi_ioctl_params_compstruct snd_rawmidi_params params;unsigned int val; -if (rfile->output ==NULL ) -return -EINVAL ; if (get_user(params.stream, &src->stream) || get_user(params.buffer_size, &src->buffer_size) || get_user(params.avail_min, &src->avail_min) ||
@@ -46,8 +44,12 @@ static int snd_rawmidi_ioctl_params_comp params.no_active_sensing = val;switch (params.stream) {case SNDRV_RAWMIDI_STREAM_OUTPUT : +if (!rfile->output) +return -EINVAL ;return snd_rawmidi_output_params (rfile->output, ¶ms);case SNDRV_RAWMIDI_STREAM_INPUT : +if (!rfile->input) +return -EINVAL ;return snd_rawmidi_input_params (rfile->input, ¶ms); }return -EINVAL ;
@@ -67,16 +69,18 @@ static int snd_rawmidi_ioctl_status_compint err;struct snd_rawmidi_status status; -if (rfile->output ==NULL ) -return -EINVAL ;if (get_user (status.stream, &src->stream))return -EFAULT ;switch (status.stream) {case SNDRV_RAWMIDI_STREAM_OUTPUT : +if (!rfile->output) +return -EINVAL ; err =snd_rawmidi_output_status (rfile->output, &status);break ;case SNDRV_RAWMIDI_STREAM_INPUT : +if (!rfile->input) +return -EINVAL ; err =snd_rawmidi_input_status (rfile->input, &status);break ;default :
@@ -113,16 +117,18 @@ static int snd_rawmidi_ioctl_status_x32(int err;struct snd_rawmidi_status status; -if (rfile->output ==NULL ) -return -EINVAL ;if (get_user (status.stream, &src->stream))return -EFAULT ;switch (status.stream) {case SNDRV_RAWMIDI_STREAM_OUTPUT : +if (!rfile->output) +return -EINVAL ; err =snd_rawmidi_output_status (rfile->output, &status);break ;case SNDRV_RAWMIDI_STREAM_INPUT : +if (!rfile->input) +return -EINVAL ; err =snd_rawmidi_input_status (rfile->input, &status);break ;default :
PATCH 178/366 Don't leak MNT_INTERNAL away from internal mounts
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit 16a34adb9392b2fe4195267475ab5b472e55292c upstream.
We want it only for the stuff created by SB_KERNMOUNT mounts, *not* for their copies. As it is, creating a deep stack of bindings of /proc/*/ns/* somewhere in a new namespace and exiting yields a stack overflow.
--- fs/namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/namespace.c +2 -1
@@ -903,7 +903,8 @@ static struct mount *clone_mnt(struct mo goto out_free; } - mnt->mnt.mnt_flags = old->mnt.mnt_flags & ~(MNT_WRITE_HOLD |MNT_MARKED ); + mnt->mnt.mnt_flags = old->mnt.mnt_flags; + mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD |MNT_MARKED |MNT_INTERNAL );/* Don't allow unprivileged users to change mount flags */ if (flag &CL_UNPRIVILEGED ) { mnt->mnt.mnt_flags |=MNT_LOCK_ATIME ;
PATCH 179/366 xhci: Fix USB ports for Dell Inspiron 5775
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kai-Heng Feng <[email protected]>
commit 621faf4f6a181b6e012c1d1865213f36f4159b7f upstream.
The Dell Inspiron 5775 is a Raven Ridge. The Enable Slot command timed out when a USB device gets plugged:
[ 212.156326] xhci_hcd 0000:03:00.3: Error while assigning device slot ID [ 212.156340] xhci_hcd 0000:03:00.3: Max number of devices this xHCI host supports is 64. [ 212.156348] usb usb2-port3: couldn't allocate usb_device
AMD suggests that a delay before xHC suspends can fix the issue.
I can confirm it fixes the issue, so use the suspend delay quirk for Raven Ridge's xHC.
--- drivers/usb/host/xhci-pci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-pci.c +4 -1
@@ -124,7 +124,10 @@ static void xhci_pci_quirks(struct devicif (pdev->vendor ==PCI_VENDOR_ID_AMD &&usb_amd_find_chipset_info ()) xhci->quirks |=XHCI_AMD_PLL_FIX ; -if (pdev->vendor ==PCI_VENDOR_ID_AMD && pdev->device ==0x43bb ) +if (pdev->vendor ==PCI_VENDOR_ID_AMD && + (pdev->device ==0x15e0 || + pdev->device ==0x15e1 || + pdev->device ==0x43bb )) xhci->quirks |=XHCI_SUSPEND_DELAY ;if (pdev->vendor ==PCI_VENDOR_ID_AMD )
PATCH 180/366 cifs: do not allow creating sockets except with SMB1 posix exensions
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Steve French <[email protected]>
commit 1d0cffa674cfa7d185a302c8c6850fc50b893bed upstream.
RHBZ: 1453123
Since at least the 3.10 kernel and likely a lot earlier we have not been able to create unix domain sockets in a cifs share when mounted using the SFU mount option (except when mounted with the cifs unix extensions to Samba e.g.)
Trying to create a socket, for example using the af_unix command from xfstests will cause :
BUG: unable to handle kernel NULL pointer dereference at 00000000
00000040
Since no one uses or depends on being able to create unix domains sockets on a cifs share the easiest fix to stop this vulnerability is to simply not allow creation of any other special files than char or block devices when sfu is used.
Added update to Ronnie's patch to handle a tcon link leak, and to address a buf leak noticed by Gustavo and Colin.
--- fs/cifs/dir.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/cifs/dir.c +5 -4
@@ -665,6 +665,9 @@ int cifs_mknod(struct inode *inode, stru goto mknod_out; } +if (!S_ISCHR (mode) && !S_ISBLK (mode)) + goto mknod_out; +if (!(cifs_sb->mnt_cifs_flags &CIFS_MOUNT_UNX_EMUL )) goto mknod_out;
@@ -673,10 +676,8 @@ int cifs_mknod(struct inode *inode, stru buf =kmalloc (sizeof (FILE_ALL_INFO ),GFP_KERNEL );if (buf ==NULL ) { -kfree (full_path); rc = -ENOMEM ; -free_xid (xid); -return rc; + goto mknod_out; }if (backup_cred (cifs_sb))
@@ -718,7 +719,7 @@ int cifs_mknod(struct inode *inode, stru pdev->minor =cpu_to_le64 (MINOR (device_number)); rc =CIFSSMBWrite (xid, &io_parms, &bytes_written, (char *)pdev,NULL ,0 ); - }/* else if (S_ISFIFO) */ + }CIFSSMBClose (xid, tcon, fid.netfid);d_drop (direntry);
PATCH 181/366 autofs: mount point create should honour passed in mode
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ian Kent <[email protected]>
commit 1e6306652ba18723015d1b4967fe9de55f042499 upstream.
The autofs file system mkdir inode operation blindly sets the created directory mode to S_IFDIR | 0555, ingoring the passed in mode, which can cause selinux dac_override denials.
But the function also checks if the caller is the daemon (as no-one else should be able to do anything here) so there's no point in not honouring the passed in mode, allowing the daemon to set appropriate mode when required.
--- fs/autofs4/root.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/autofs4/root.c +1 -1
@@ -721,7 +721,7 @@ static int autofs4_dir_mkdir(struct inodautofs4_del_active (dentry); - inode =autofs4_get_inode (dir->i_sb,S_IFDIR |0555 ); + inode =autofs4_get_inode (dir->i_sb,S_IFDIR | mode);if (!inode)return -ENOMEM ;d_add (dentry, inode);
PATCH 182/366 mm/filemap.c: fix NULL pointer in page_cache_tree_insert()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wilcox <[email protected]>
commit abc1be13fd113ddef5e2d807a466286b864caed3 upstream.
f2fs specifies the __GFP_ZERO flag for allocating some of its pages. Unfortunately, the page cache also uses the mapping's GFP flags for allocating radix tree nodes. It always masked off the __GFP_HIGHMEM flag, and masks off __GFP_ZERO in some paths, but not all. That causes radix tree nodes to be allocated with a NULL list_head, which causes backtraces like:
__list_del_entry+0x30/0xd0 list_lru_del+0xac/0x1ac page_cache_tree_insert+0xd8/0x110
The __GFP_DMA and __GFP_DMA32 flags would also be able to sneak through if they are ever used. Fix them all by using GFP_RECLAIM_MASK at the innermost location, and remove it from earlier in the callchain.
[bwh: Backported to 3.16:
- Drop change in page_cache_read(), which always passes GFP_KERNEL
- Adjust context]
---
mm/filemap.c +3 -4
@@ -529,7 +529,7 @@ int replace_page_cache_page(struct pageVM_BUG_ON_PAGE (!PageLocked (new), new);VM_BUG_ON_PAGE (new->mapping, new); - error =radix_tree_preload (gfp_mask & ~__GFP_HIGHMEM); + error =radix_tree_preload (gfp_mask &GFP_RECLAIM_MASK );if (!error) {struct address_space *mapping = old->mapping;void (*freepage)(struct page *);
@@ -576,7 +576,7 @@ static int __add_to_page_cache_locked(stif (error)return error; - error =radix_tree_maybe_preload (gfp_mask & ~__GFP_HIGHMEM); + error =radix_tree_maybe_preload (gfp_mask &GFP_RECLAIM_MASK );if (error) {mem_cgroup_uncharge_cache_page (page);return error;
@@ -1111,8 +1111,7 @@ no_page:if (fgp_flags &FGP_ACCESSED )init_page_accessed (page); - err =add_to_page_cache_lru (page, mapping, offset, - gfp_mask &GFP_RECLAIM_MASK ); + err =add_to_page_cache_lru (page, mapping, offset, gfp_mask);if (unlikely (err)) {page_cache_release (page); page =NULL ;
PATCH 183/366 USB: Increment wakeup count on remote wakeup.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ravi Chandra Sadineni <[email protected]>
commit 83a62c51ba7b3c0bf45150c4eac7aefc6c785e94 upstream.
On chromebooks we depend on wakeup count to identify the wakeup source. But currently USB devices do not increment the wakeup count when they trigger the remote wake. This patch addresses the same.
Resume condition is reported differently on USB 2.0 and USB 3.0 devices.
On USB 2.0 devices, a wake capable device, if wake enabled, drives resume signal to indicate a remote wake (USB 2.0 spec section 7.1.7.7). The upstream facing port then sets C_PORT_SUSPEND bit and reports a port change event (USB 2.0 spec section 11.24.2.7.2.3). Thus if a port has resumed before driving the resume signal from the host and C_PORT_SUSPEND is set, then the device attached to the given port might be the reason for the last system wakeup. Increment the wakeup count for the same.
On USB 3.0 devices, a function may signal that it wants to exit from device suspend by sending a Function Wake Device Notification to the host (USB3.0 spec section 8.5.6.4) Thus on receiving the Function Wake, increment the wakeup count.
--- drivers/usb/core/hcd.c | 1 + drivers/usb/core/hub.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
drivers/usb/core/hcd.c +1 -0
@@ -2293,6 +2293,7 @@ void usb_hcd_resume_root_hub (struct usbspin_lock_irqsave (&hcd_root_hub_lock, flags);if (hcd->rh_registered) { +pm_wakeup_event (&hcd->self.root_hub->dev,0 );set_bit (HCD_FLAG_WAKEUP_PENDING , &hcd->flags);queue_work (pm_wq, &hcd->wakeup_work); }
drivers/usb/core/hub.c +9 -1
@@ -626,12 +626,17 @@ void usb_wakeup_notification(struct usb_ unsigned int portnum) {struct usb_hub *hub; +struct usb_port *port_dev;if (!hdev)return ; hub =usb_hub_to_struct_hub (hdev);if (hub) { + port_dev = hub->ports[portnum -1 ]; +if (port_dev && port_dev->child) +pm_wakeup_event (&port_dev->child->dev,0 ); +set_bit (portnum, hub->wakeup_bits);kick_khubd (hub); }
@@ -3313,8 +3318,11 @@ int usb_port_resume(struct usb_device *u/* Skip the initial Clear-Suspend step for a remote wakeup */ status =hub_port_status (hub, port1, &portstatus, &portchange); -if (status ==0 && !port_is_suspended (hub, portstatus)) +if (status ==0 && !port_is_suspended (hub, portstatus)) { +if (portchange &USB_PORT_STAT_C_SUSPEND ) +pm_wakeup_event (&udev->dev,0 ); goto SuspendCleared; + }/* see 7.1.7.7; affects power usage, but not budgeting */ if (hub_is_superspeed (hub->hdev))
PATCH 184/366 usbip: vhci_hcd: check rhport before using in vhci_hub_control()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit 5b22f676118ff25049382041da0db8012e57c9e8 upstream.
Validate !rhport < 0 before using it to access port_status array.
[bwh: Backported to 3.16:
- Drop changes to the SetPortFeature USB_PORT_FEAT_{SUSPEND,POWER,BH_PORT_RESET} cases
- Add the "error" label
- Adjust filename, context]
---
drivers/staging/usbip/vhci_hcd.c +7 -1
@@ -266,6 +266,8 @@ static int vhci_hub_control(struct usb_husbip_dbg_vhci_rh (" ClearHubFeature\n" );break ;case ClearPortFeature: +if (rhport <0 ) + goto error;switch (wValue) {case USB_PORT_FEAT_SUSPEND :if (dum->port_status[rhport] &USB_PORT_STAT_SUSPEND ) {
@@ -370,6 +372,8 @@ static int vhci_hub_control(struct usb_hcase USB_PORT_FEAT_RESET :usbip_dbg_vhci_rh (" SetPortFeature: USB_PORT_FEAT_RESET\n" ); +if (rhport <0 ) + goto error;/* if it's already running, disconnect first */ if (dum->port_status[rhport] &USB_PORT_STAT_ENABLE ) { dum->port_status[rhport] &=
@@ -385,6 +389,8 @@ static int vhci_hub_control(struct usb_hdefault :usbip_dbg_vhci_rh (" SetPortFeature: default %d\n" , wValue); +if (rhport <0 ) + goto error; dum->port_status[rhport] |= (1 << wValue);break ; }
@@ -392,7 +398,7 @@ static int vhci_hub_control(struct usb_hdefault :pr_err ("default: no such request\n" ); - +error:/* "protocol stall" on error */ retval = -EPIPE ; }
PATCH 185/366 usbip: vhci_hcd: Fix usb device and sockfd leaks
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Shuah Khan <[email protected]>
commit 9020a7efe537856eb3e826ebebdf38a5d07a7857 upstream.
vhci_hcd fails to do reset to put usb device and sockfd in the module remove/stop paths. Fix the leak.
--- drivers/staging/usbip/usbip_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/usbip/usbip_common.h +1 -1
@@ -248,7 +248,7 @@ enum usbip_side {#define SDEV_EVENT_ERROR_SUBMIT (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)#define SDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) -#define VDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_BYE) +#define VDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE)#define VDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)#define VDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)#define VDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)
PATCH 186/366 usb: core: Add quirk for HP v222w 16GB Mini
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kamil Lulko <[email protected]>
commit 3180dabe08e3653bf0a838553905d88f3773f29c upstream.
Add DELAY_INIT quirk to fix the following problem with HP v222w 16GB Mini:
usb 1-3: unable to read config index 0 descriptor/start: -110 usb 1-3: can't read configurations, error -110
usb 1-3: can't set config #1, error -110
--- drivers/usb/core/quirks.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/core/quirks.c +3 -0
@@ -45,6 +45,9 @@ static const struct usb_device_id usb_qu { USB_DEVICE(0x03f0, 0x0701), .driver_info = USB_QUIRK_STRING_FETCH_255 }, + /* HP v222w 16GB Mini USB Drive */ + { USB_DEVICE(0x03f0, 0x3f40), .driver_info = USB_QUIRK_DELAY_INIT }, + /* Creative SB Audigy 2 NX */ { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME },
PATCH 187/366 s390/qeth: handle failure on workqueue creation
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Julian Wiedmann <[email protected]>
commit a936b1ef37ce1e996533878f4b23944f9444dcdf upstream.
Creating the global workqueue during driver init may fail, deal with it. Also, destroy the created workqueue on any subsequent error.
--- drivers/s390/net/qeth_core_main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/s390/net/qeth_core_main.c +7 -1
@@ -5832,10 +5832,14 @@ static int __init qeth_core_init(void)mutex_init (&qeth_mod_mutex); qeth_wq =create_singlethread_workqueue ("qeth_wq" ); +if (!qeth_wq) { + rc = -ENOMEM ; + goto out_err; + } rc =qeth_register_dbf_views ();if (rc) - goto out_err; + goto dbf_err; qeth_core_root_dev =root_device_register ("qeth" ); rc =PTR_ERR_OR_ZERO (qeth_core_root_dev);if (rc)
@@ -5872,6 +5876,8 @@ slab_err:root_device_unregister (qeth_core_root_dev); register_err:qeth_unregister_dbf_views (); +dbf_err: +destroy_workqueue (qeth_wq); out_err:pr_err ("Initializing the qeth device driver failed\n" );return rc;
PATCH 188/366 l2tp: fix {pppol2tp, l2tp_dfs}_seq_stop() in case of seq_file overflow
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit 5411b6187adf62909e3b998ac782e722904c7487 upstream.
Commit 0e0c3fee3a59 ("l2tp: hold reference on tunnels printed in pppol2tp proc file") assumed that if pppol2tp_seq_stop() was called with non-NULL private data (the 'v' pointer), then pppol2tp_seq_start() would not be called again. It turns out that this isn't guaranteed, and overflowing the seq_file's buffer in pppol2tp_seq_show() is a way to get into this situation.
Therefore, pppol2tp_seq_stop() needs to reset pd->tunnel, so that pppol2tp_seq_start() won't drop a reference again if it gets called. We also have to clear pd->session, because the rest of the code expects a non-NULL tunnel when pd->session is set.
The l2tp_debugfs module has the same issue. Fix it in the same way.
--- net/l2tp/l2tp_debugfs.c | 5 ++++- net/l2tp/l2tp_ppp.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
net/l2tp/l2tp_debugfs.c +4 -1
@@ -106,8 +106,11 @@ static void l2tp_dfs_seq_stop(struct seqreturn ;/* Drop reference taken by last invocation of l2tp_dfs_next_tunnel() */ -if (pd->tunnel) +if (pd->tunnel) {l2tp_tunnel_dec_refcount (pd->tunnel); + pd->tunnel =NULL ; + pd->session =NULL ; + } }static void l2tp_dfs_seq_tunnel_show (struct seq_file *m,void *v)
net/l2tp/l2tp_ppp.c +4 -1
@@ -1650,8 +1650,11 @@ static void pppol2tp_seq_stop(struct seqreturn ;/* Drop reference taken by last invocation of pppol2tp_next_tunnel() */ -if (pd->tunnel) +if (pd->tunnel) {l2tp_tunnel_dec_refcount (pd->tunnel); + pd->tunnel =NULL ; + pd->session =NULL ; + } }static void pppol2tp_seq_tunnel_show (struct seq_file *m,void *v)
PATCH 189/366 llc: hold llc_sap before release_sock()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit f7e43672683b097bb074a8fe7af9bc600a23f231 upstream.
syzbot reported we still access llc->sap in llc_backlog_rcv() after it is freed in llc_sap_remove_socket():
Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1b9/0x294 lib/dump_stack.c:113 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0x242/0x2fe mm/kasan/report.c:412 __asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:430 llc_conn_ac_send_sabme_cmd_p_set_x+0x3a8/0x460 net/llc/llc_c_ac.c:785 llc_exec_conn_trans_actions net/llc/llc_conn.c:475 [inline] llc_conn_service net/llc/llc_conn.c:400 [inline] llc_conn_state_process+0x4e1/0x13a0 net/llc/llc_conn.c:75 llc_backlog_rcv+0x195/0x1e0 net/llc/llc_conn.c:891 sk_backlog_rcv include/net/sock.h:909 [inline] __release_sock+0x12f/0x3a0 net/core/sock.c:2335 release_sock+0xa4/0x2b0 net/core/sock.c:2850 llc_ui_release+0xc8/0x220 net/llc/af_llc.c:204
llc->sap is refcount'ed and llc_sap_remove_socket() is paired with llc_sap_add_socket(). This can be amended by holding its refcount before llc_sap_remove_socket() and releasing it after release_sock().
--- net/llc/af_llc.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/llc/af_llc.c +7 -0
@@ -187,6 +187,7 @@ static int llc_ui_release(struct socket {struct sock *sk = sock->sk;struct llc_sock *llc; +struct llc_sap *sap;if (unlikely (sk ==NULL )) goto out;
@@ -197,9 +198,15 @@ static int llc_ui_release(struct socket llc->laddr.lsap, llc->daddr.lsap);if (!llc_send_disc (sk))llc_ui_wait_for_disc (sk, sk->sk_rcvtimeo); + sap = llc->sap; +/* Hold this for release_sock(), so that llc_backlog_rcv() could still +* use it. +*/ +llc_sap_hold (sap);if (!sock_flag (sk,SOCK_ZAPPED ))llc_sap_remove_socket (llc->sap, sk);release_sock (sk); +llc_sap_put (sap);if (llc->dev)dev_put (llc->dev);sock_put (sk);
PATCH 190/366 llc: fix NULL pointer deref for SOCK_ZAPPED
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit 3a04ce7130a7e5dad4e78d45d50313747f8c830f upstream.
For SOCK_ZAPPED socket, we don't need to care about llc->sap, so we should just skip these refcount functions in this case.
--- net/llc/af_llc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
net/llc/af_llc.c +12 -9
@@ -187,7 +187,6 @@ static int llc_ui_release(struct socket {struct sock *sk = sock->sk;struct llc_sock *llc; -struct llc_sap *sap;if (unlikely (sk ==NULL )) goto out;
@@ -198,15 +197,19 @@ static int llc_ui_release(struct socket llc->laddr.lsap, llc->daddr.lsap);if (!llc_send_disc (sk))llc_ui_wait_for_disc (sk, sk->sk_rcvtimeo); - sap = llc->sap; -/* Hold this for release_sock(), so that llc_backlog_rcv() could still -* use it. -*/ -llc_sap_hold (sap); -if (!sock_flag (sk,SOCK_ZAPPED )) +if (!sock_flag (sk,SOCK_ZAPPED )) { +struct llc_sap *sap = llc->sap; + +/* Hold this for release_sock(), so that llc_backlog_rcv() +* could still use it. +*/ +llc_sap_hold (sap);llc_sap_remove_socket (llc->sap, sk); -release_sock (sk); -llc_sap_put (sap); +release_sock (sk); +llc_sap_put (sap); + }else { +release_sock (sk); + }if (llc->dev)dev_put (llc->dev);sock_put (sk);
PATCH 191/366 s390/cio: update chpid descriptor after resource accessibility event
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Ott <[email protected]>
commit af2e460ade0b0180d0f3812ca4f4f59cc9597f3e upstream.
Channel path descriptors have been seen as something stable (as long as the chpid is configured). Recent tests have shown that the descriptor can also be altered when the link state of a channel path changes. Thus it is necessary to update the descriptor during handling of resource accessibility events.
--- drivers/s390/cio/chsc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/s390/cio/chsc.c +11 -3
@@ -362,6 +362,7 @@ static void chsc_process_sei_link_incidestatic void chsc_process_sei_res_acc (struct chsc_sei_nt0_area *sei_area) { +struct channel_path *chp;struct chp_link link;struct chp_id chpid;int status;
@@ -374,10 +375,17 @@ static void chsc_process_sei_res_acc(str chpid.id = sei_area->rsid;/* allocate a new channel path structure, if needed */ status =chp_get_status (chpid); -if (status <0 ) -chp_new (chpid); -else if (!status) +if (!status)return ; + +if (status <0 ) { +chp_new (chpid); + }else { + chp =chpid_to_chp (chpid); +mutex_lock (&chp->lock); +chp_update_desc (chp); +mutex_unlock (&chp->lock); + }memset (&link,0 ,sizeof (struct chp_link )); link.chpid = chpid;if ((sei_area->vf &0xc0 ) !=0 ) {
PATCH 192/366 s390/dasd: fix IO error for newly defined devices
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Stefan Haberland <[email protected]>
commit 5d27a2bf6e14f5c7d1033ad1e993fcd0eba43e83 upstream.
When a new CKD storage volume is defined at the storage server, Linux may be relying on outdated information about that volume, which leads to the following errors:
1. Command Reject Errors for minidisk on z/VM:
dasd-eckd.b3193d: 0.0.XXXX: An error occurred in the DASD device driver,
reason=09 dasd(eckd): I/O status report for device 0.0.XXXX: dasd(eckd): in req: 00000000XXXXXXXX CC:00 FC:04 AC:00 SC:17 DS:02 CS:00 RC:0
dasd(eckd): device 0.0.2046: Failing CCW: 00000000XXXXXXXX dasd(eckd): Sense(hex) 0- 7: 80 00 00 00 00 00 00 00 dasd(eckd): Sense(hex) 8-15: 00 00 00 00 00 00 00 00 dasd(eckd): Sense(hex) 16-23: 00 00 00 00 e1 00 0f 00 dasd(eckd): Sense(hex) 24-31: 00 00 40 e2 00 00 00 00 dasd(eckd): 24 Byte: 0 MSG 0, no MSGb to SYSOP
2. Equipment Check errors on LPAR or for dedicated devices on z/VM:
dasd(eckd): I/O status report for device 0.0.XXXX:
dasd(eckd): in req: 00000000XXXXXXXX CC:00 FC:04 AC:00 SC:17 DS:0E CS:40
fcxs:01 schxs:00 RC:0
dasd(eckd): device 0.0.9713: Failing TCW: 00000000XXXXXXXX dasd(eckd): Sense(hex) 0- 7: 10 00 00 00 13 58 4d 0f dasd(eckd): Sense(hex) 8-15: 67 00 00 00 00 00 00 04 dasd(eckd): Sense(hex) 16-23: e5 18 05 33 97 01 0f 0f dasd(eckd): Sense(hex) 24-31: 00 00 40 e2 00 04 58 0d dasd(eckd): 24 Byte: 0 MSG f, no MSGb to SYSOP
Fix this problem by using the up-to-date information provided during online processing via the device specific SNEQ to detect the case of outdated LCU data. If there is a difference, perform a re-read of that data.
[bwh: Backported to 3.16:
- Move up assignment of "private"
- Adjust context]
---
drivers/s390/block/dasd_alias.c +12 -4
@@ -608,18 +608,26 @@ static int _schedule_lcu_update(struct aint dasd_alias_add_device (struct dasd_device *device) { -struct dasd_eckd_private *private; -struct alias_lcu *lcu; +struct dasd_eckd_private *private = device->private; +__u8 uaddr = private->uid.real_unit_addr; +struct alias_lcu *lcu = private->lcu;unsigned long flags;int rc; - private = (struct dasd_eckd_private *) device->private; - lcu = private->lcu; rc =0 ;/* need to take cdev lock before lcu lock */ spin_lock_irqsave (get_ccwdev_lock (device->cdev), flags);spin_lock (&lcu->lock); +/* +* Check if device and lcu type differ. If so, the uac data may be +* outdated and needs to be updated. +*/ +if (private->uid.type != lcu->uac->unit[uaddr].ua_type) { + lcu->flags |=UPDATE_PENDING ; +DBF_DEV_EVENT (DBF_WARNING , device,"%s" , +"uid type mismatch - trigger rescan" ); + }if (!(lcu->flags &UPDATE_PENDING )) { rc =_add_device_to_lcu (lcu, device, device);if (rc)
PATCH 193/366 ALSA: core: Report audio_tstamp in snd_pcm_sync_ptr
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: David Henningsson <[email protected]>
commit f853dcaae2f5bbe021161e421bd1576845bae8f6 upstream.
It looks like a simple mistake that this struct member was forgotten.
Audio_tstamp isn't used much, and on some archs (such as x86) this ioctl is not used by default, so that might be the reason why this has slipped for so long.
--- sound/core/pcm_native.c | 1 + 1 file changed, 1 insertion(+)
sound/core/pcm_native.c +1 -0
@@ -2527,6 +2527,7 @@ static int snd_pcm_sync_ptr(struct snd_p sync_ptr.s.status.hw_ptr = status->hw_ptr; sync_ptr.s.status.tstamp = status->tstamp; sync_ptr.s.status.suspended_state = status->suspended_state; + sync_ptr.s.status.audio_tstamp = status->audio_tstamp;snd_pcm_stream_unlock_irq (substream);if (copy_to_user (_sync_ptr, &sync_ptr,sizeof (sync_ptr)))return -EFAULT ;
PATCH 194/366 drivers: tty: Merge alloc_tty_struct and initialize_tty_struct
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Rasmus Villemoes <[email protected]>
commit 2c964a2f4191f2229566895f1a0e85f8339f5dd1 upstream.
The two functions alloc_tty_struct and initialize_tty_struct are always called together. Merge them into alloc_tty_struct, updating its prototype and the only two callers of these functions.
--- drivers/tty/pty.c | 19 +++++++++---------- drivers/tty/tty_io.c | 37 +++++++++++++------------------------ include/linux/tty.h | 4 +--- 3 files changed, 23 insertions(+), 37 deletions(-)
drivers/tty/pty.c +9 -10
@@ -319,7 +319,7 @@ done:* pty_common_install - set up the pty pair * @driver: the pty driver * @tty: the tty being instantiated -* @bool: legacy, true if this is BSD style +* @legacy: true if this is BSD style * * Perform the initial set up for the tty/pty pair. Called from the * tty layer when the port is first opened.
@@ -334,18 +334,17 @@ static int pty_common_install(struct ttyint idx = tty->index;int retval = -ENOMEM ; - o_tty =alloc_tty_struct (); -if (!o_tty) - goto err; ports[0 ] =kmalloc (sizeof **ports,GFP_KERNEL ); ports[1 ] =kmalloc (sizeof **ports,GFP_KERNEL );if (!ports[0 ] || !ports[1 ]) - goto err_free_tty; + goto err;if (!try_module_get (driver->other->owner)) {/* This cannot in fact currently happen */ - goto err_free_tty; + goto err; } -initialize_tty_struct (o_tty, driver->other, idx); + o_tty =alloc_tty_struct (driver->other, idx); +if (!o_tty) + goto err_put_module;if (legacy) {/* We always use new tty termios data so we can do this
@@ -390,12 +389,12 @@ err_free_termios:tty_free_termios (tty); err_deinit_tty:deinitialize_tty_struct (o_tty); +free_tty_struct (o_tty); +err_put_module:module_put (o_tty->driver->owner); -err_free_tty: +err:kfree (ports[0 ]);kfree (ports[1 ]); -free_tty_struct (o_tty); -err:return retval; }
drivers/tty/tty_io.c +13 -24
@@ -157,20 +157,6 @@ static void __proc_set_tty(struct task_sstatic void proc_set_tty (struct task_struct *tsk,struct tty_struct *tty);/** -* alloc_tty_struct - allocate a tty object -* -* Return a new empty tty structure. The data fields have not -* been initialized in any way but has been zeroed -* -* Locking: none -*/ - -struct tty_struct *alloc_tty_struct (void ) -{ -return kzalloc (sizeof (struct tty_struct ),GFP_KERNEL ); -} - -/** * free_tty_struct - free a disused tty * @tty: tty struct to free *
@@ -1455,12 +1441,11 @@ struct tty_struct *tty_init_dev(struct tif (!try_module_get (driver->owner))return ERR_PTR (-ENODEV ); - tty =alloc_tty_struct (); + tty =alloc_tty_struct (driver, idx);if (!tty) { retval = -ENOMEM ; goto err_module_put; } -initialize_tty_struct (tty, driver, idx);tty_lock (tty); retval =tty_driver_install_tty (driver, tty);
@@ -3034,19 +3019,21 @@ static struct device *tty_get_device(str/** -* initialize_tty_struct -* @tty: tty to initialize +* alloc_tty_struct * -* This subroutine initializes a tty structure that has been newly -* allocated. +* This subroutine allocates and initializes a tty structure. * -* Locking: none - tty in question must not be exposed at this point +* Locking: none - tty in question is not exposed at this point */ -void initialize_tty_struct (struct tty_struct *tty, -struct tty_driver *driver,int idx) +struct tty_struct *alloc_tty_struct (struct tty_driver *driver,int idx) { -memset (tty,0 ,sizeof (struct tty_struct )); +struct tty_struct *tty; + + tty =kzalloc (sizeof (*tty),GFP_KERNEL ); +if (!tty) +return NULL ; +kref_init (&tty->kref); tty->magic =TTY_MAGIC ;tty_ldisc_init (tty);
@@ -3070,6 +3057,8 @@ void initialize_tty_struct(struct tty_st tty->index = idx;tty_line_name (driver, idx, tty->name); tty->dev =tty_get_device (tty); + +return tty; }/**
include/linux/tty.h +1 -3
@@ -477,13 +477,11 @@ extern int tty_mode_ioctl(struct tty_str unsigned int cmd, unsigned long arg);extern int tty_perform_flush (struct tty_struct *tty,unsigned long arg);extern void tty_default_fops (struct file_operations *fops); -extern struct tty_struct *alloc_tty_struct (void ); +extern struct tty_struct *alloc_tty_struct (struct tty_driver *driver,int idx);extern int tty_alloc_file (struct file *file);extern void tty_add_file (struct tty_struct *tty,struct file *file);extern void tty_free_file (struct file *file);extern void free_tty_struct (struct tty_struct *tty); -extern void initialize_tty_struct (struct tty_struct *tty, -struct tty_driver *driver,int idx);extern void deinitialize_tty_struct (struct tty_struct *tty);extern struct tty_struct *tty_init_dev (struct tty_driver *driver,int idx);extern int tty_release (struct inode *inode,struct file *filp);
A message that is not in the archive (sent off-list or not yet received): CAKwiHFisgkjvaU9gtTdv=XF+7vhQeQo9TSNLAcNU5_uqALohYQ@mail.gmail.com
Re: [PATCH 3.16 194/366] drivers: tty: Merge alloc_tty_struct and initialize_tty_struct
Quoted 2 lines · Rasmus Villemoes
IIRC, I messed up back then, so you'll need some followup as well, but I'm on my phone ATM.
I guess that's commit 07584d4a356e "drivers: tty: Fix use-after-free in pty_common_install"? I missed that but will add it now.
Quoted 2 lines
I assume you're taking this to make it easier to backport
some actual fix?
This is required as preparation for commit 903f9db10f18 "tty: Don't call panic() at tty_ldisc_init()".
Ben.
Quoted 173 lines · On Sun, Oct 14, 2018, 17:39 Ben Hutchings <[email protected]> wrote:
Quoted 171 lines
3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Rasmus Villemoes <[email protected]>
commit
2c964a2f4191f2229566895f1a0e85f8339f5dd1upstream.The two functions
alloc_tty_structandinitialize_tty_structare always called together. Merge them intoalloc_tty_struct, updating its prototype and the only two callers of these functions.Signed-off-by Rasmus Villemoes <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Signed-off-by Ben Hutchings <[email protected]>--- drivers/tty/pty.c | 19 +++++++++---------- drivers/tty/tty_io.c | 37 +++++++++++++------------------------ include/linux/tty.h | 4 +--- 3 files changed, 23 insertions(+), 37 deletions(-)drivers/tty/pty.c +9
-10@@ -319,7 +319,7 @@ done:* pty_common_install - set up the pty pair * @driver: the pty driver * @tty: the tty being instantiated -* @bool: legacy, true if this is BSD style +* @legacy: true if this is BSD style * * Perform the initial set up for the tty/pty pair. Called from the * tty layer when the port is first opened. @@ -334,18 +334,17 @@ static int pty_common_install(struct ttyint idx = tty->index;int retval = -ENOMEM ; - o_tty =alloc_tty_struct (); -if (!o_tty) - goto err; ports[0 ] =kmalloc (sizeof **ports,GFP_KERNEL ); ports[1 ] =kmalloc (sizeof **ports,GFP_KERNEL );if (!ports[0 ] || !ports[1 ]) - goto err_free_tty; + goto err;if (!try_module_get (driver->other->owner)) {/* This cannot in fact currently happen */ - goto err_free_tty; + goto err; } -initialize_tty_struct (o_tty, driver->other, idx); + o_tty =alloc_tty_struct (driver->other, idx); +if (!o_tty) + goto err_put_module;if (legacy) {/* We always use new tty termios data so we can do this @@ -390,12 +389,12 @@ err_free_termios:tty_free_termios (tty); err_deinit_tty:deinitialize_tty_struct (o_tty); +free_tty_struct (o_tty); +err_put_module:module_put (o_tty->driver->owner); -err_free_tty: +err:kfree (ports[0 ]);kfree (ports[1 ]); -free_tty_struct (o_tty); -err:return retval; }drivers/tty/tty_io.c +13
-24@@ -157,20 +157,6 @@ static void __proc_set_tty(struct task_sstatic void proc_set_tty (struct task_struct *tsk,struct tty_struct *tty);/** -* alloc_tty_struct - allocate a tty object -* -* Return a new empty tty structure. The data fields have not -* been initialized in any way but has been zeroed -* -* Locking: none -*/ - -struct tty_struct *alloc_tty_struct (void ) -{ -return kzalloc (sizeof (struct tty_struct ),GFP_KERNEL ); -} - -/** * free_tty_struct - free a disused tty * @tty: tty struct to free * @@ -1455,12 +1441,11 @@ struct tty_struct *tty_init_dev(struct tif (!try_module_get (driver->owner))return ERR_PTR (-ENODEV ); - tty =alloc_tty_struct (); + tty =alloc_tty_struct (driver, idx);if (!tty) { retval = -ENOMEM ; goto err_module_put; } -initialize_tty_struct (tty, driver, idx);tty_lock (tty); retval =tty_driver_install_tty (driver, tty);@@ -3034,19 +3019,21 @@ static struct device *tty_get_device(str/** -* initialize_tty_struct -* @tty: tty to initialize +* alloc_tty_struct * -* This subroutine initializes a tty structure that has been newly -* allocated. +* This subroutine allocates and initializes a tty structure. * -* Locking: none - tty in question must not be exposed at this point +* Locking: none - tty in question is not exposed at this point */ -void initialize_tty_struct (struct tty_struct *tty, -struct tty_driver *driver,int idx) +struct tty_struct *alloc_tty_struct (struct tty_driver *driver,int idx) { -memset (tty,0 ,sizeof (struct tty_struct )); +struct tty_struct *tty; + + tty =kzalloc (sizeof (*tty),GFP_KERNEL ); +if (!tty) +return NULL ; +kref_init (&tty->kref); tty->magic =TTY_MAGIC ;tty_ldisc_init (tty);@@ -3070,6 +3057,8 @@ void initialize_tty_struct(struct tty_st tty->index = idx;tty_line_name (driver, idx, tty->name); tty->dev =tty_get_device (tty); + +return tty; }/** include/linux/tty.h +1
-3@@ -477,13 +477,11 @@ extern int tty_mode_ioctl(struct tty_str unsigned int cmd, unsigned long arg);extern int tty_perform_flush (struct tty_struct *tty,unsigned long arg);extern void tty_default_fops (struct file_operations *fops); -extern struct tty_struct *alloc_tty_struct (void ); +extern struct tty_struct *alloc_tty_struct (struct tty_driver *driver,int idx);extern int tty_alloc_file (struct file *file);extern void tty_add_file (struct tty_struct *tty,struct file *file);extern void tty_free_file (struct file *file);extern void free_tty_struct (struct tty_struct *tty); -extern void initialize_tty_struct (struct tty_struct *tty, -struct tty_driver *driver,int idx);extern void deinitialize_tty_struct (struct tty_struct *tty); extern struct tty_struct *tty_init_dev(struct tty_driver *driver, intidx);
extern inttty_release(struct inode *inode, struct file *filp);
Signature · 2 lines
Ben Hutchings I haven't lost my mind; it's backed up on tape somewhere.
PATCH 195/366 tty: handle the case where we cannot restore a line discipline
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alan Cox <[email protected]>
commit 8a8dabf2dd68caff842d38057097c23bc514ea6e upstream.
Historically the N_TTY driver could never fail but this has become broken over time. Rather than trying to rewrite half the ldisc layer to fix the breakage introduce a second level of fallback with an N_NULL ldisc which cannot fail, and thus restore the guarantees required by the ldisc layer.
We still try and fail to N_TTY first. It's much more useful to find yourself back in your old ldisc (first attempt) or in N_TTY (second attempt), and while I'm not aware of any code out there that makes those assumptions it's good to drive(r) defensively.
---
drivers/tty/Makefile +2 -1
@@ -1,5 +1,6 @@ obj-$(CONFIG_TTY) += tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o \ - tty_buffer.o tty_port.o tty_mutex.o tty_ldsem.o + tty_buffer.o tty_port.o tty_mutex.o \ + tty_ldsem.o n_null.o obj-$(CONFIG_LEGACY_PTYS) += pty.o obj-$(CONFIG_UNIX98_PTYS) += pty.o obj-$(CONFIG_AUDIT) += tty_audit.o
drivers/tty/n_null.c new file +80 -0
80 lines not on this page · raw message
drivers/tty/tty_ldisc.c +30 -13
61 lines not on this page · raw message
include/uapi/linux/tty.h +1 -0
@@ -34,5 +34,6 @@#define N_TI_WL 22/* for TI's WL BT, FM, GPS combo chips */ #define N_TRACESINK 23/* Trace data routing for MIPI P1149.7 */ #define N_TRACEROUTER 24/* Trace data routing for MIPI P1149.7 */ +#define N_NULL 27/* Null ldisc used for error handling */ #endif /* _UAPI_LINUX_TTY_H */
PATCH 196/366 tty: Avoid possible error pointer dereference at tty_ldisc_restore().
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
commit 598c2d41ff44889dd8eced4f117403e472158d85 upstream.
syzbot is reporting crashes [1] triggered by memory allocation failure at tty_ldisc_get() from tty_ldisc_restore(). While syzbot stops at WARN_ON() due to panic_on_warn == true, panic_on_warn == false will after all trigger an OOPS by dereferencing old->ops->num if IS_ERR(old) == true.
We can simplify tty_ldisc_restore() as three calls (old->ops->num, N_TTY, N_NULL) to tty_ldisc_failto() in addition to avoiding possible error pointer dereference.
If someone reports kernel panic triggered by forcing all memory allocations for tty_ldisc_restore() to fail, we can consider adding __GFP_NOFAIL for tty_ldisc_restore() case.
[1] https://syzkaller.appspot.com/bug?id=6ac359c61e71d22e06db7f8f88243feb11d927e7
--- drivers/tty/tty_ldisc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/tty/tty_ldisc.c +5 -8
@@ -510,19 +510,16 @@ static void tty_ldisc_restore(struct ttychar buf[64 ];/* There is an outstanding reference here so this is safe */ - old =tty_ldisc_get (tty, old->ops->num); -WARN_ON (IS_ERR (old)); - tty->ldisc = old; -tty_set_termios_ldisc (tty, old->ops->num); -if (tty_ldisc_open (tty, old) <0 ) { -tty_ldisc_put (old); +if (tty_ldisc_failto (tty, old->ops->num) <0 ) { +const char *name =tty_name (tty, buf); + +pr_warn ("Falling back ldisc for %s.\n" , name);/* The traditional behaviour is to fall back to N_TTY, we want to avoid falling back to N_NULL unless we have no choice to avoid the risk of breaking anything */ if (tty_ldisc_failto (tty,N_TTY ) <0 &&tty_ldisc_failto (tty,N_NULL ) <0 ) -panic ("Couldn't open N_NULL ldisc for %s." , -tty_name (tty, buf)); +panic ("Couldn't open N_NULL ldisc for %s." , name); } }
PATCH 197/366 tty: Don't call panic() at tty_ldisc_init()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
commit 903f9db10f18f735e62ba447147b6c434b6af003 upstream.
syzbot is reporting kernel panic [1] triggered by memory allocation failure at tty_ldisc_get() from tty_ldisc_init(). But since both tty_ldisc_get() and caller of tty_ldisc_init() can cleanly handle errors, tty_ldisc_init() does not need to call panic() when tty_ldisc_get() failed.
[1] https://syzkaller.appspot.com/bug?id=883431818e036ae6a9981156a64b821110f39187
--- drivers/tty/tty_io.c | 5 ++++- drivers/tty/tty_ldisc.c | 5 +++-- include/linux/tty.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-)
drivers/tty/tty_io.c +4 -1
@@ -3036,7 +3036,10 @@ struct tty_struct *alloc_tty_struct(strukref_init (&tty->kref); tty->magic =TTY_MAGIC ; -tty_ldisc_init (tty); +if (tty_ldisc_init (tty)) { +kfree (tty); +return NULL ; + } tty->session =NULL ; tty->pgrp =NULL ;mutex_init (&tty->legacy_mutex);
drivers/tty/tty_ldisc.c +3 -2
@@ -820,12 +820,13 @@ void tty_ldisc_release(struct tty_struct* the tty structure is not completely set up when this call is made. */ -void tty_ldisc_init (struct tty_struct *tty) +int tty_ldisc_init (struct tty_struct *tty) {struct tty_ldisc *ld =tty_ldisc_get (tty,N_TTY );if (IS_ERR (ld)) -panic ("n_tty: init_tty" ); +return PTR_ERR (ld); tty->ldisc = ld; +return 0 ; }/**
include/linux/tty.h +1 -1
@@ -556,7 +556,7 @@ extern int tty_unregister_ldisc(int discextern int tty_set_ldisc (struct tty_struct *tty,int ldisc);extern int tty_ldisc_setup (struct tty_struct *tty,struct tty_struct *o_tty);extern void tty_ldisc_release (struct tty_struct *tty,struct tty_struct *o_tty); -extern void tty_ldisc_init (struct tty_struct *tty); +extern int __must_check tty_ldisc_init (struct tty_struct *tty);extern void tty_ldisc_deinit (struct tty_struct *tty);extern void tty_ldisc_begin (void );
PATCH 198/366 hwmon: (nct6683) Enable EC access if disabled at boot
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
commit dbac00f0cf634120d77edee10d25e3f6899d7636 upstream.
On Asrock Z370M Pro4, it was observed that EC access was disabled after initially booting the system. As a result, the driver failed to load with
nct6683: EC is disabled
After a suspend/resume cycle, the driver loaded correctly.
nct6683: Found NCT6683D or compatible chip at 0x2e:0xa20 nct6683 nct6683.2592: NCT6683D EC firmware version 1.0 build 07/18/16
Enable EC access after identifying the chip if disabled to fix the problem. Warn the user that the data it reports may be unusable, similar to other drivers for chips from Nuvoton.
--- drivers/hwmon/nct6683.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/nct6683.c +2 -2
@@ -1335,8 +1335,8 @@ static int __init nct6683_find(int sioad/* Activate logical device if needed */ val =superio_inb (sioaddr,SIO_REG_ENABLE );if (!(val &0x01 )) { -pr_err ("EC is disabled\n" ); - goto fail; +pr_warn ("Forcibly enabling EC access. Data may be unusable.\n" ); +superio_outb (sioaddr,SIO_REG_ENABLE , val |0x01 ); }superio_exit (sioaddr);
PATCH 199/366 tcp: don't read out-of-bounds opsize
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
commit 7e5a206ab686f098367b61aca989f5cdfa8114a3 upstream.
The old code reads the "opsize" variable from out-of-bounds memory (first byte behind the segment) if a broken TCP segment ends directly after an opcode that is neither EOL nor NOP.
The result of the read isn't used for anything, so the worst thing that could theoretically happen is a pagefault; and since the physmap is usually mostly contiguous, even that seems pretty unlikely.
The following C reproducer triggers the uninitialized read - however, you can't actually see anything happen unless you put something like a pr_warn() in tcp_parse_md5sig_option() to print the opsize.
====================================
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <net/if.h>
#include <linux/if.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/in.h>
#include <linux/if_tun.h>
#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <assert.h>
void systemf(const char *command, ...) {
char *full_command;
va_list ap;
va_start(ap, command);
if (vasprintf(&full_command, command, ap) == -1)
err(1, "vasprintf");
va_end(ap);
printf("systemf: <<<%s>>>\n", full_command);
system(full_command);
}
char *devname;
int tun_alloc(char *name) {
int fd = open("/dev/net/tun", O_RDWR);
if (fd == -1)
err(1, "open tun dev");
static struct ifreq req = { .ifr_flags = IFF_TUN|IFF_NO_PI };
strcpy(req.ifr_name, name);
if (ioctl(fd, TUNSETIFF, &req))
err(1, "TUNSETIFF"); devname = req.ifr_name;
printf("device name: %s\n", devname);
return fd;
}
#define IPADDR(a,b,c,d) (((a)<<0)+((b)<<8)+((c)<<16)+((d)<<24))
void sum_accumulate(unsigned int *sum, void *data, int len) {
assert((len&2)==0);
for (int i=0; i<len/2; i++) {
*sum += ntohs(((unsigned short *)data)[i]); }
}
unsigned short sum_final(unsigned int sum) {
sum = (sum >> 16) + (sum & 0xffff);
sum = (sum >> 16) + (sum & 0xffff);
return htons(~sum);
}
void fix_ip_sum(struct iphdr *ip) {
unsigned int sum = 0;
sum_accumulate(&sum, ip, sizeof(*ip));
ip->check = sum_final(sum);
}
void fix_tcp_sum(struct iphdr *ip, struct tcphdr *tcp) {
unsigned int sum = 0;
struct {
unsigned int saddr;
unsigned int daddr;
unsigned char pad;
unsigned char proto_num;
unsigned short tcp_len;
} fakehdr = {
.saddr = ip->saddr,
.daddr = ip->daddr,
.proto_num = ip->protocol,
.tcp_len = htons(ntohs(ip->tot_len) - ip->ihl*4) };
sum_accumulate(&sum, &fakehdr, sizeof(fakehdr)); sum_accumulate(&sum, tcp, tcp->doff*4); tcp->check = sum_final(sum);
}
int main(void) {
int tun_fd = tun_alloc("inject_dev%d"); systemf("ip link set %s up", devname); systemf("ip addr add 192.168.42.1/24 dev %s", devname);
struct {
struct iphdr ip;
struct tcphdr tcp;
unsigned char tcp_opts[20];
} __attribute__((packed)) syn_packet = {
.ip = {
.ihl = sizeof(struct iphdr)/4,
.version = 4,
.tot_len = htons(sizeof(syn_packet)),
.ttl = 30,
.protocol = IPPROTO_TCP,
/* FIXUP check */
.saddr = IPADDR(192,168,42,2),
.daddr = IPADDR(192,168,42,1)
},
.tcp = {
.source = htons(1),
.dest = htons(1337),
.seq = 0x12345678,
.doff = (sizeof(syn_packet.tcp)+sizeof(syn_packet.tcp_opts))/4,
.syn = 1,
.window = htons(64),
.check = 0 /*FIXUP*/
},
.tcp_opts = {
/* INVALID: trailing MD5SIG opcode after NOPs */
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 19
}
};
fix_ip_sum(&syn_packet.ip);
fix_tcp_sum(&syn_packet.ip, &syn_packet.tcp);
while (1) {
int write_res = write(tun_fd, &syn_packet, sizeof(syn_packet));
if (write_res != sizeof(syn_packet))
err(1, "packet write failed"); }
}
====================================
--- net/ipv4/tcp_input.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
net/ipv4/tcp_input.c +2 -5
@@ -3675,11 +3675,8 @@ const u8 *tcp_parse_md5sig_option(constint length = (th->doff <<2 ) -sizeof (*th);const u8 *ptr = (const u8 *)(th +1 ); -/* If the TCP option is too short, we can short cut */ -if (length <TCPOLEN_MD5SIG ) -return NULL ; - -while (length >0 ) { +/* If not enough data remaining, we can short cut */ +while (length >=TCPOLEN_MD5SIG ) {int opcode = *ptr++;int opsize;
PATCH 200/366 RDMA/ucma: Introduce safer rdma_addr_size() variants
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Roland Dreier <[email protected]>
commit 84652aefb347297aa08e91e283adf7b18f77c2d5 upstream.
There are several places in the ucma ABI where userspace can pass in a sockaddr but set the address family to AF_IB. When that happens, rdma_addr_size() will return a size bigger than sizeof struct sockaddr_in6, and the ucma kernel code might end up copying past the end of a buffer not sized for a struct sockaddr_ib.
Fix this by introducing new variants
int rdma_addr_size_in6(struct sockaddr_in6 *addr);
int rdma_addr_size_kss(struct __kernel_sockaddr_storage *addr);that are type-safe for the types used in the ucma ABI and return 0 if the size computed is bigger than the size of the type passed in. We can use these new variants to check what size userspace has passed in before copying any addresses.
--- drivers/infiniband/core/addr.c | 16 ++++++++++++++++ drivers/infiniband/core/ucma.c | 34 +++++++++++++++++----------------- include/rdma/ib_addr.h | 2 ++ 3 files changed, 35 insertions(+), 17 deletions(-)
drivers/infiniband/core/addr.c +16 -0
@@ -86,6 +86,22 @@ int rdma_addr_size(struct sockaddr *addr }EXPORT_SYMBOL (rdma_addr_size); +int rdma_addr_size_in6 (struct sockaddr_in6 *addr) +{ +int ret =rdma_addr_size ((struct sockaddr *) addr); + +return ret <=sizeof (*addr) ? ret :0 ; +} +EXPORT_SYMBOL (rdma_addr_size_in6); + +int rdma_addr_size_kss (struct __kernel_sockaddr_storage *addr) +{ +int ret =rdma_addr_size ((struct sockaddr *) addr); + +return ret <=sizeof (*addr) ? ret :0 ; +} +EXPORT_SYMBOL (rdma_addr_size_kss); +static struct rdma_addr_client self;void rdma_addr_register_client (struct rdma_addr_client *client)
drivers/infiniband/core/ucma.c +17 -17
@@ -528,6 +528,9 @@ static ssize_t ucma_bind_ip(struct ucma_if (copy_from_user (&cmd, inbuf,sizeof (cmd)))return -EFAULT ; +if (!rdma_addr_size_in6 (&cmd.addr)) +return -EINVAL ; + ctx =ucma_get_ctx (file, cmd.id);if (IS_ERR (ctx))return PTR_ERR (ctx);
@@ -541,22 +544,21 @@ static ssize_t ucma_bind(struct ucma_fil int in_len, int out_len) {struct rdma_ucm_bind cmd; -struct sockaddr *addr;struct ucma_context *ctx;int ret;if (copy_from_user (&cmd, inbuf,sizeof (cmd)))return -EFAULT ; - addr = (struct sockaddr *) &cmd.addr; -if (cmd.reserved || !cmd.addr_size || (cmd.addr_size !=rdma_addr_size (addr))) +if (cmd.reserved || !cmd.addr_size || + cmd.addr_size !=rdma_addr_size_kss (&cmd.addr))return -EINVAL ; ctx =ucma_get_ctx (file, cmd.id);if (IS_ERR (ctx))return PTR_ERR (ctx); - ret =rdma_bind_addr (ctx->cm_id, addr); + ret =rdma_bind_addr (ctx->cm_id, (struct sockaddr *) &cmd.addr);ucma_put_ctx (ctx);return ret; }
@@ -566,23 +568,22 @@ static ssize_t ucma_resolve_ip(struct uc int in_len, int out_len) {struct rdma_ucm_resolve_ip cmd; -struct sockaddr *src, *dst;struct ucma_context *ctx;int ret;if (copy_from_user (&cmd, inbuf,sizeof (cmd)))return -EFAULT ; - src = (struct sockaddr *) &cmd.src_addr; - dst = (struct sockaddr *) &cmd.dst_addr; -if (!rdma_addr_size (src) || !rdma_addr_size (dst)) +if (!rdma_addr_size_in6 (&cmd.src_addr) || + !rdma_addr_size_in6 (&cmd.dst_addr))return -EINVAL ; ctx =ucma_get_ctx (file, cmd.id);if (IS_ERR (ctx))return PTR_ERR (ctx); - ret =rdma_resolve_addr (ctx->cm_id, src, dst, cmd.timeout_ms); + ret =rdma_resolve_addr (ctx->cm_id, (struct sockaddr *) &cmd.src_addr, + (struct sockaddr *) &cmd.dst_addr, cmd.timeout_ms);ucma_put_ctx (ctx);return ret; }
@@ -592,24 +593,23 @@ static ssize_t ucma_resolve_addr(struct int in_len, int out_len) {struct rdma_ucm_resolve_addr cmd; -struct sockaddr *src, *dst;struct ucma_context *ctx;int ret;if (copy_from_user (&cmd, inbuf,sizeof (cmd)))return -EFAULT ; - src = (struct sockaddr *) &cmd.src_addr; - dst = (struct sockaddr *) &cmd.dst_addr; -if (cmd.reserved || (cmd.src_size && (cmd.src_size !=rdma_addr_size (src))) || - !cmd.dst_size || (cmd.dst_size !=rdma_addr_size (dst))) +if (cmd.reserved || + (cmd.src_size && (cmd.src_size !=rdma_addr_size_kss (&cmd.src_addr))) || + !cmd.dst_size || (cmd.dst_size !=rdma_addr_size_kss (&cmd.dst_addr)))return -EINVAL ; ctx =ucma_get_ctx (file, cmd.id);if (IS_ERR (ctx))return PTR_ERR (ctx); - ret =rdma_resolve_addr (ctx->cm_id, src, dst, cmd.timeout_ms); + ret =rdma_resolve_addr (ctx->cm_id, (struct sockaddr *) &cmd.src_addr, + (struct sockaddr *) &cmd.dst_addr, cmd.timeout_ms);ucma_put_ctx (ctx);return ret; }
@@ -1324,7 +1324,7 @@ static ssize_t ucma_join_ip_multicast(st join_cmd.response = cmd.response; join_cmd.uid = cmd.uid; join_cmd.id = cmd.id; - join_cmd.addr_size =rdma_addr_size ((struct sockaddr *) &cmd.addr); + join_cmd.addr_size =rdma_addr_size_in6 (&cmd.addr);if (!join_cmd.addr_size)return -EINVAL ;
@@ -1343,7 +1343,7 @@ static ssize_t ucma_join_multicast(strucif (copy_from_user (&cmd, inbuf,sizeof (cmd)))return -EFAULT ; -if (!rdma_addr_size ((struct sockaddr *)&cmd.addr)) +if (!rdma_addr_size_kss (&cmd.addr))return -EINVAL ;return ucma_process_join (file, &cmd, out_len);
include/rdma/ib_addr.h +2 -0
@@ -109,6 +109,8 @@ int rdma_copy_addr(struct rdma_dev_addr const unsigned char *dst_dev_addr);int rdma_addr_size (struct sockaddr *addr); +int rdma_addr_size_in6 (struct sockaddr_in6 *addr); +int rdma_addr_size_kss (struct __kernel_sockaddr_storage *addr);int rdma_addr_find_smac_by_sgid (union ib_gid *sgid,u8 *smac,u16 *vlan_id); int rdma_addr_find_dmac_by_grh(union ib_gid *sgid, union ib_gid *dgid, u8 *smac,
PATCH 201/366 RDMA/ucma: Allow resolving address w/o specifying source address
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Roland Dreier <[email protected]>
commit 09abfe7b5b2f442a85f4c4d59ecf582ad76088d7 upstream.
The RDMA CM will select a source device and address by consulting the routing table if no source address is passed into rdma_resolve_address(). Userspace will ask for this by passing an all-zero source address in the RESOLVE_IP command. Unfortunately the new check for non-zero address size rejects this with EINVAL, which breaks valid userspace applications.
Fix this by explicitly allowing a zero address family for the source.
--- drivers/infiniband/core/ucma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/ucma.c +1 -1
@@ -574,7 +574,7 @@ static ssize_t ucma_resolve_ip(struct ucif (copy_from_user (&cmd, inbuf,sizeof (cmd)))return -EFAULT ; -if (!rdma_addr_size_in6 (&cmd.src_addr) || +if ((cmd.src_addr.sin6_family && !rdma_addr_size_in6 (&cmd.src_addr)) || !rdma_addr_size_in6 (&cmd.dst_addr))return -EINVAL ;
PATCH 202/366 bonding: do not set slave_dev npinfo before slave_enable_netpoll in bond_enslave
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit ddea788c63094f7c483783265563dd5b50052e28 upstream.
After Commit 8a8efa22f51b ("bonding: sync netpoll code with bridge"), it would set slave_dev npinfo in slave_enable_netpoll when enslaving a dev if bond->dev->npinfo was set.
However now slave_dev npinfo is set with bond->dev->npinfo before calling slave_enable_netpoll. With slave_dev npinfo set, __netpoll_setup called in slave_enable_netpoll will not call slave dev's .ndo_netpoll_setup(). It causes that the lower dev of this slave dev can't set its npinfo.
One way to reproduce it:
# modprobe bonding # brctl addbr br0 # brctl addif br0 eth1 # ifconfig bond0 192.168.122.1/24 up # ifenslave bond0 eth2 # systemctl restart netconsole # ifenslave bond0 br0 # ifconfig eth2 down # systemctl restart netconsole
The netpoll won't really work.
This patch is to remove that slave_dev npinfo setting in bond_enslave().
--- drivers/net/bonding/bond_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +1 -2
@@ -1535,8 +1535,7 @@ int bond_enslave(struct net_device *bond }/* switch(bond_mode) */ #ifdef CONFIG_NET_POLL_CONTROLLER - slave_dev->npinfo = bond->dev->npinfo; -if (slave_dev->npinfo) { +if (bond->dev->npinfo) {if (slave_enable_netpoll (new_slave)) {pr_info ("Error, %s: master_dev is using netpoll, but new slave device does not support netpoll\n" , bond_dev->name);
PATCH 203/366 ipv6: add RTA_TABLE and RTA_PREFSRC to rtm_ipv6_policy
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit aa8f8778493c85fff480cdf8b349b1e1dcb5f243 upstream.
KMSAN reported use of uninit-value that I tracked to lack of proper size check on RTA_TABLE attribute.
I also believe RTA_PREFSRC lacks a similar check.
--- net/ipv6/route.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/route.c +2 -0
@@ -2344,11 +2344,13 @@ void rt6_mtu_change(struct net_device *dstatic const struct nla_policy rtm_ipv6_policy[RTA_MAX +1 ] = { [RTA_GATEWAY ] = { .len =sizeof (struct in6_addr ) }, + [RTA_PREFSRC ] = { .len =sizeof (struct in6_addr ) }, [RTA_OIF ] = { .type =NLA_U32 }, [RTA_IIF ] = { .type =NLA_U32 }, [RTA_PRIORITY ] = { .type =NLA_U32 }, [RTA_METRICS ] = { .type =NLA_NESTED }, [RTA_MULTIPATH ] = { .len =sizeof (struct rtnexthop ) }, + [RTA_TABLE ] = { .type =NLA_U32 }, }; static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
PATCH 204/366 l2tp: check sockaddr length in pppol2tp_connect()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit eb1c28c05894a4b1f6b56c5bf072205e64cfa280 upstream.
Check sockaddr_len before dereferencing sp->sa_protocol, to ensure that it actually points to valid data.
--- net/l2tp/l2tp_ppp.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/l2tp/l2tp_ppp.c +7 -0
@@ -641,6 +641,13 @@ static int pppol2tp_connect(struct sockelock_sock (sk); error = -EINVAL ; + +if (sockaddr_len !=sizeof (struct sockaddr_pppol2tp ) && + sockaddr_len !=sizeof (struct sockaddr_pppol2tpv3 ) && + sockaddr_len !=sizeof (struct sockaddr_pppol2tpin6 ) && + sockaddr_len !=sizeof (struct sockaddr_pppol2tpv3in6 )) + goto end; +if (sp->sa_protocol !=PX_PROTO_OL2TP ) goto end;
PATCH 205/366 pppoe: check sockaddr length in pppoe_connect()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Guillaume Nault <[email protected]>
commit a49e2f5d5fb141884452ddb428f551b123d436b5 upstream.
We must validate sockaddr_len, otherwise userspace can pass fewer data than we expect and we end up accessing invalid data.
--- drivers/net/ppp/pppoe.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ppp/pppoe.c +4 -0
@@ -615,6 +615,10 @@ static int pppoe_connect(struct socket *lock_sock (sk); error = -EINVAL ; + +if (sockaddr_len !=sizeof (struct sockaddr_pppox )) + goto end; +if (sp->sa_protocol !=PX_PROTO_OE ) goto end;
PATCH 206/366 ALSA: usb-audio: Skip broken EU on Dell dock USB-audio
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 1d8d6428d1da642ddd75b0be2d1bb1123ff8e017 upstream.
The Dell Dock USB-audio device with 0bda:4014 is behaving notoriously bad, and we have already applied some workaround to avoid the firmware hiccup. Yet we still need to skip one thing, the Extension Unit at ID 4, which doesn't react correctly to the mixer ctl access.
Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1090658
--- sound/usb/mixer_maps.c | 3 +++ 1 file changed, 3 insertions(+)
sound/usb/mixer_maps.c +3 -0
@@ -346,8 +346,11 @@ static struct usbmix_name_map bose_compa/* * Dell usb dock with ALC4020 codec had a firmware problem where it got * screwed up when zero volume is passed; just skip it as a workaround +* +* Also the extension unit gives an access error, so skip it as well. */ static const struct usbmix_name_map dell_alc4020_map[] = { + {4 ,NULL },/* extension unit */ {16 ,NULL }, {19 ,NULL }, {0 }
PATCH 207/366 team: fix netconsole setup over team
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit 9cf2f437ca5b39828984064fad213e68fc17ef11 upstream.
The same fix in Commit dbe173079ab5 ("bridge: fix netconsole setup over bridge") is also needed for team driver.
While at it, remove the unnecessary parameter *team from team_port_enable_netpoll().
v1->v2:
- fix it in a better way, as does bridge.
--- drivers/net/team/team.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/net/team/team.c +12 -7
@@ -1052,14 +1052,11 @@ static void team_port_leave(struct team }#ifdef CONFIG_NET_POLL_CONTROLLER -static int team_port_enable_netpoll (struct team *team,struct team_port *port) +static int __team_port_enable_netpoll (struct team_port *port) {struct netpoll *np;int err; -if (!team->dev->npinfo) -return 0 ; - np =kzalloc (sizeof (*np),GFP_KERNEL );if (!np)return -ENOMEM ;
@@ -1073,6 +1070,14 @@ static int team_port_enable_netpoll(strureturn err; } +static int team_port_enable_netpoll (struct team_port *port) +{ +if (!port->team->dev->npinfo) +return 0 ; + +return __team_port_enable_netpoll (port); +} +static void team_port_disable_netpoll (struct team_port *port) {struct netpoll *np = port->np;
@@ -1087,7 +1092,7 @@ static void team_port_disable_netpoll(st kfree(np); }#else -static int team_port_enable_netpoll (struct team *team,struct team_port *port) +static int team_port_enable_netpoll (struct team_port *port) {return 0 ; }
@@ -1175,7 +1180,7 @@ static int team_port_add(struct team *te goto err_vids_add; } - err =team_port_enable_netpoll (team, port); + err =team_port_enable_netpoll (port);if (err) {netdev_err (dev,"Failed to enable netpoll on device %s\n" , portname);
@@ -1880,7 +1885,7 @@ static int team_netpoll_setup(struct netmutex_lock (&team->lock);list_for_each_entry (port, &team->port_list, list) { - err =team_port_enable_netpoll (team, port); + err =__team_port_enable_netpoll (port);if (err) {__team_netpoll_cleanup (team);break ;
PATCH 208/366 mtd: cfi: cmdset_0001: Do not allow read/write to suspend erase block.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joakim Tjernlund <[email protected]>
commit 6510bbc88e3258631831ade49033537081950605 upstream.
Currently it is possible to read and/or write to suspend EB's. Writing /dev/mtdX or /dev/mtdblockX from several processes may break the flash state machine.
--- drivers/mtd/chips/cfi_cmdset_0001.c | 16 +++++++++++----- include/linux/mtd/flashchip.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-)
drivers/mtd/chips/cfi_cmdset_0001.c +11 -5
@@ -825,21 +825,25 @@ static int chip_ready (struct map_info * (mode == FL_WRITING && (cfip->SuspendCmdSupport & 1)))) goto sleep; +/* Do not allow suspend iff read/write to EB address */ +if ((adr & chip->in_progress_block_mask) == + chip->in_progress_block_addr) + goto sleep;/* Erase suspend */ -map_write (map,CMD (0xB0 ), adr); +map_write (map,CMD (0xB0 ), chip->in_progress_block_addr);/* If the flash has finished erasing, then 'erase suspend' * appears to make some (28F320) flash devices switch to * 'read' mode. Make sure that we switch to 'read status' * mode so we get the right data. --rmk */ -map_write (map,CMD (0x70 ), adr); +map_write (map,CMD (0x70 ), chip->in_progress_block_addr); chip->oldstate =FL_ERASING ; chip->state =FL_ERASE_SUSPENDING ; chip->erase_suspended =1 ;for (;;) { - status =map_read (map, adr); + status =map_read (map, chip->in_progress_block_addr);if (map_word_andequal (map, status, status_OK, status_OK))break ;
@@ -1035,8 +1039,8 @@ static void put_chip(struct map_info *masending the 0x70 (Read Status) command to an erasing chip and expecting it to be ignored, that's what we do. */ -map_write (map,CMD (0xd0 ), adr); -map_write (map,CMD (0x70 ), adr); +map_write (map,CMD (0xd0 ), chip->in_progress_block_addr); +map_write (map,CMD (0x70 ), chip->in_progress_block_addr); chip->oldstate =FL_READY ; chip->state =FL_ERASING ;break ;
@@ -1927,6 +1931,8 @@ static int __xipram do_erase_oneblock(stmap_write (map,CMD (0xD0 ), adr); chip->state =FL_ERASING ; chip->erase_suspended =0 ; + chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(len -1 ); ret = INVAL_CACHE_AND_WAIT(map, chip, adr, adr, len,
include/linux/mtd/flashchip.h +1 -0
@@ -85,6 +85,7 @@ struct flchip { unsigned int write_suspended:1; unsigned int erase_suspended:1;unsigned long in_progress_block_addr; +unsigned long in_progress_block_mask;struct mutex mutex;wait_queue_head_t wq;/* Wait on here when we're waiting for the chip
PATCH 209/366 mtd: cfi: cmdset_0001: Workaround Micron Erase suspend bug.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joakim Tjernlund <[email protected]>
commit 46a16a2283f9e678a4e26829175e0c37a5191860 upstream.
Some Micron chips does not work well wrt Erase suspend for boot blocks. This avoids the issue by not allowing Erase suspend for the boot blocks for the 28F00AP30(1GBit) chip.
--- drivers/mtd/chips/cfi_cmdset_0001.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/mtd/chips/cfi_cmdset_0001.c +17 -0
@@ -45,6 +45,7 @@#define I82802AB 0x00ad#define I82802AC 0x00ac#define PF38F4476 0x881c +#define M28F00AP30 0x8963/* STMicroelectronics chips */ #define M50LPW080 0x002F#define M50FLW080A 0x0080
@@ -375,6 +376,17 @@ static void cfi_fixup_major_minor(struct extp->MinorVersion ='1' ; } +static int cfi_is_micron_28F00AP30 (struct cfi_private *cfi,struct flchip *chip) +{ +/* +* Micron(was Numonyx) 1Gbit bottom boot are buggy w.r.t +* Erase Supend for their small Erase Blocks(0x8000) +*/ +if (cfi->mfr ==CFI_MFR_INTEL && cfi->id ==M28F00AP30 ) +return 1 ; +return 0 ; +} +static inline struct cfi_pri_intelext *read_pri_intelext (struct map_info *map,__u16 adr) {
@@ -830,6 +842,11 @@ static int chip_ready (struct map_info * chip->in_progress_block_addr) goto sleep; +/* do not suspend small EBs, buggy Micron Chips */ +if (cfi_is_micron_28F00AP30 (cfi, chip) && + (chip->in_progress_block_mask == ~(0x8000 -1 ))) + goto sleep; +/* Erase suspend */ map_write (map,CMD (0xB0 ), chip->in_progress_block_addr);
PATCH 210/366 mtd: cfi: cmdset_0002: Do not allow read/write to suspend erase block.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Joakim Tjernlund <[email protected]>
commit 7b70eb14392a7cf505f9b358d06c33b5af73d1e7 upstream.
Currently it is possible to read and/or write to suspend EB's. Writing /dev/mtdX or /dev/mtdblockX from several processes may break the flash state machine.
Taken from cfi_cmdset_0001 driver.
--- drivers/mtd/chips/cfi_cmdset_0002.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/mtd/chips/cfi_cmdset_0002.c +6 -3
@@ -780,9 +780,10 @@ static int get_chip(struct map_info *map (mode == FL_WRITING && (cfip->EraseSuspend & 0x2)))) goto sleep; -/* We could check to see if we're trying to access the sector -* that is currently being erased. However, no user will try -* anything like that so we just wait for the timeout. */ +/* Do not allow suspend iff read/write to EB address */ +if ((adr & chip->in_progress_block_mask) == + chip->in_progress_block_addr) + goto sleep;/* Erase suspend */ /* It's harmless to issue the Erase-Suspend and Erase-Resume
@@ -1926,6 +1927,7 @@ static int __xipram do_erase_chip(struct chip->state =FL_ERASING ; chip->erase_suspended =0 ; chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(map->size -1 ); INVALIDATE_CACHE_UDELAY(map, chip, adr, map->size,
@@ -2015,6 +2017,7 @@ static int __xipram do_erase_oneblock(st chip->state =FL_ERASING ; chip->erase_suspended =0 ; chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(len -1 ); INVALIDATE_CACHE_UDELAY(map, chip, adr, len,
PATCH 211/366 packet: fix bitfield update race
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Willem de Bruijn <[email protected]>
commit a6361f0ca4b25460f2cdf3235ebe8115f622901e upstream.
Updates to the bitfields in struct packet_sock are not atomic. Serialize these read-modify-write cycles.
Move po->running into a separate variable. Its writes are protected by po->bind_lock (except for one startup case at packet_create). Also replace a textual precondition warning with lockdep annotation.
All others are set only in packet_setsockopt. Serialize these updates by holding the socket lock. Analogous to other field updates, also hold the lock when testing whether a ring is active (pg_vec).
--- net/packet/af_packet.c | 60 +++++++++++++++++++++++++++++++----------- net/packet/internal.h | 10 +++---- 2 files changed, 49 insertions(+), 21 deletions(-)
net/packet/af_packet.c +44 -16
@@ -343,11 +343,11 @@ static void packet_pick_tx_queue(structskb_set_queue_mapping (skb, queue_index); } -/* register_prot_hook must be invoked with the po->bind_lock held, +/* __register_prot_hook must be invoked through register_prot_hook * or from a context in which asynchronous accesses to the packet * socket is not possible (packet_create()). */ -static void register_prot_hook (struct sock *sk) +static void __register_prot_hook (struct sock *sk) {struct packet_sock *po =pkt_sk (sk);
@@ -362,8 +362,13 @@ static void register_prot_hook(struct so } } -/* {,__}unregister_prot_hook() must be invoked with the po->bind_lock -* held. If the sync parameter is true, we will temporarily drop +static void register_prot_hook (struct sock *sk) +{ +lockdep_assert_held_once (&pkt_sk (sk)->bind_lock); +__register_prot_hook (sk); +} + +/* If the sync parameter is true, we will temporarily drop * the po->bind_lock and do a synchronize_net to make sure no * asynchronous packet processing paths still refer to the elements * of po->prot_hook. If the sync parameter is false, it is the
@@ -373,6 +378,8 @@ static void __unregister_prot_hook(struc {struct packet_sock *po =pkt_sk (sk); +lockdep_assert_held_once (&po->bind_lock); + po->running =0 ;if (po->fanout)
@@ -2887,7 +2894,7 @@ static int packet_create(struct net *netif (proto) { po->prot_hook.type = proto; -register_prot_hook (sk); +__register_prot_hook (sk); }mutex_lock (&net->packet.sklist_lock);
@@ -3386,12 +3393,18 @@ packet_setsockopt(struct socket *sock, iif (optlen !=sizeof (val))return -EINVAL ; -if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) -return -EBUSY ;if (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; - po->tp_loss = !!val; -return 0 ; + +lock_sock (sk); +if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) { + ret = -EBUSY ; + }else { + po->tp_loss = !!val; + ret =0 ; + } +release_sock (sk); +return ret; }case PACKET_AUXDATA : {
@@ -3402,7 +3415,9 @@ packet_setsockopt(struct socket *sock, iif (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; +lock_sock (sk); po->auxdata = !!val; +release_sock (sk);return 0 ; }case PACKET_ORIGDEV :
@@ -3414,7 +3429,9 @@ packet_setsockopt(struct socket *sock, iif (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; +lock_sock (sk); po->origdev = !!val; +release_sock (sk);return 0 ; }case PACKET_VNET_HDR :
@@ -3423,15 +3440,20 @@ packet_setsockopt(struct socket *sock, iif (sock->type !=SOCK_RAW )return -EINVAL ; -if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) -return -EBUSY ;if (optlen <sizeof (val))return -EINVAL ;if (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; - po->has_vnet_hdr = !!val; -return 0 ; +lock_sock (sk); +if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) { + ret = -EBUSY ; + }else { + po->has_vnet_hdr = !!val; + ret =0 ; + } +release_sock (sk); +return ret; }case PACKET_TIMESTAMP : {
@@ -3462,11 +3484,17 @@ packet_setsockopt(struct socket *sock, iif (optlen !=sizeof (val))return -EINVAL ; -if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) -return -EBUSY ;if (copy_from_user (&val, optval,sizeof (val)))return -EFAULT ; - po->tp_tx_has_off = !!val; + +lock_sock (sk); +if (po->rx_ring.pg_vec || po->tx_ring.pg_vec) { + ret = -EBUSY ; + }else { + po->tp_tx_has_off = !!val; + ret =0 ; + } +release_sock (sk);return 0 ; }case PACKET_QDISC_BYPASS :
net/packet/internal.h +5 -5
@@ -100,10 +100,12 @@ struct packet_sock {int copy_thresh;spinlock_t bind_lock;struct mutex pg_vec_lock; - unsigned int running:1, /* prot_hook is attached*/ - auxdata:1, +unsigned int running;/* bind_lock must be held */ + unsigned int auxdata:1, /* writer must hold sock lock */ origdev:1, - has_vnet_hdr:1; + has_vnet_hdr:1, + tp_loss:1, + tp_tx_has_off:1;int ifindex;/* bound device */ __be16 num;struct packet_mclist *mclist;
@@ -111,8 +113,6 @@ struct packet_sock {enum tpacket_versions tp_version;unsigned int tp_hdrlen;unsigned int tp_reserve; - unsigned int tp_loss:1; - unsigned int tp_tx_has_off:1;unsigned int tp_tstamp;struct net_device __rcu *cached_dev;int (*xmit)(struct sk_buff *skb);
PATCH 212/366 ALSA: seq: oss: Fix unbalanced use lock for synth MIDI device
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f5e94b4c6ebdabe0f602d796e0430180927521a0 upstream.
When get_synthdev() is called for a MIDI device, it returns the fixed midi_synth_dev without the use refcounting. OTOH, the caller is supposed to unreference unconditionally after the usage, so this would lead to unbalanced refcount.
This patch corrects the behavior and keep up the refcount balance also for the MIDI synth device.
--- sound/core/seq/oss/seq_oss_synth.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
sound/core/seq/oss/seq_oss_synth.c +8 -4
@@ -363,10 +363,14 @@ get_synthdev(struct seq_oss_devinfo *dp,return NULL ;if (! dp->synths[dev].opened)return NULL ; -if (dp->synths[dev].is_midi) -return &midi_synth_dev; -if ((rec =get_sdev (dev)) ==NULL ) -return NULL ; +if (dp->synths[dev].is_midi) { + rec = &midi_synth_dev; +snd_use_lock_use (&rec->use_lock); + }else { + rec =get_sdev (dev); +if (!rec) +return NULL ; + }if (! rec->opened) {snd_use_lock_free (&rec->use_lock);return NULL ;
PATCH 213/366 ALSA: seq: oss: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 8d218dd8116695ecda7164f97631c069938aa22e upstream.
As Smatch recently suggested, a few places in OSS sequencer codes may expand the array directly from the user-space value with speculation, namely there are a significant amount of references to either info->ch[] or dp->synths[] array:
sound/core/seq/oss/seq_oss_event.c:315 note_on_event() warn: potential spectre issue 'info->ch' (local cap) sound/core/seq/oss/seq_oss_event.c:362 note_off_event() warn: potential spectre issue 'info->ch' (local cap) sound/core/seq/oss/seq_oss_synth.c:470 snd_seq_oss_synth_load_patch() warn: potential spectre issue 'dp->synths' (local cap) sound/core/seq/oss/seq_oss_event.c:293 note_on_event() warn: potential spectre issue 'dp->synths' sound/core/seq/oss/seq_oss_event.c:353 note_off_event() warn: potential spectre issue 'dp->synths' sound/core/seq/oss/seq_oss_synth.c:506 snd_seq_oss_synth_sysex() warn: potential spectre issue 'dp->synths' sound/core/seq/oss/seq_oss_synth.c:580 snd_seq_oss_synth_ioctl() warn: potential spectre issue 'dp->synths'
Although all these seem doing only the first load without further reference, we may want to stay in a safer side, so hardening with array_index_nospec() would still make sense.
We may put array_index_nospec() at each place, but here we take a different approach:
- For dp->synths[], change the helpers to retrieve seq_oss_synthinfo pointer directly instead of the array expansion at each place
- For info->ch[], harden in a normal way, as there are only a couple of places
As a result, the existing helper, snd_seq_oss_synth_is_valid() is replaced with snd_seq_oss_synth_info(). Also, we cover MIDI device where a similar array expansion is done, too, although it wasn't reported by Smatch.
--- sound/core/seq/oss/seq_oss_event.c | 15 +++--- sound/core/seq/oss/seq_oss_midi.c | 2 + sound/core/seq/oss/seq_oss_synth.c | 75 +++++++++++++++++------------- sound/core/seq/oss/seq_oss_synth.h | 3 +- 4 files changed, 55 insertions(+), 40 deletions(-)
sound/core/seq/oss/seq_oss_event.c +9 -6
@@ -26,6 +26,7 @@#include <sound/seq_oss_legacy.h> #include "seq_oss_readq.h" #include "seq_oss_writeq.h" +#include <linux/nospec.h> /*
@@ -287,10 +288,10 @@ note_on_event(struct seq_oss_devinfo *dp {struct seq_oss_synthinfo *info; -if (!snd_seq_oss_synth_is_valid (dp, dev)) + info =snd_seq_oss_synth_info (dp, dev); +if (!info)return -ENXIO ; - info = &dp->synths[dev];switch (info->arg.event_passing) {case SNDRV_SEQ_OSS_PROCESS_EVENTS :if (! info->ch || ch <0 || ch >= info->nr_voices) {
@@ -298,6 +299,7 @@ note_on_event(struct seq_oss_devinfo *dpreturn set_note_event (dp, dev,SNDRV_SEQ_EVENT_NOTEON , ch, note, vel, ev); } + ch =array_index_nospec (ch, info->nr_voices);if (note ==255 && info->ch[ch].note >=0 ) {/* volume control */ int type;
@@ -347,10 +349,10 @@ note_off_event(struct seq_oss_devinfo *d {struct seq_oss_synthinfo *info; -if (!snd_seq_oss_synth_is_valid (dp, dev)) + info =snd_seq_oss_synth_info (dp, dev); +if (!info)return -ENXIO ; - info = &dp->synths[dev];switch (info->arg.event_passing) {case SNDRV_SEQ_OSS_PROCESS_EVENTS :if (! info->ch || ch <0 || ch >= info->nr_voices) {
@@ -358,6 +360,7 @@ note_off_event(struct seq_oss_devinfo *dreturn set_note_event (dp, dev,SNDRV_SEQ_EVENT_NOTEON , ch, note, vel, ev); } + ch =array_index_nospec (ch, info->nr_voices);if (info->ch[ch].note >=0 ) { note = info->ch[ch].note; info->ch[ch].vel =0 ;
@@ -381,7 +384,7 @@ note_off_event(struct seq_oss_devinfo *dstatic int set_note_event (struct seq_oss_devinfo *dp,int dev,int type,int ch,int note,int vel,struct snd_seq_event *ev) { -if (!snd_seq_oss_synth_is_valid (dp, dev)) +if (!snd_seq_oss_synth_info (dp, dev))return -ENXIO ; ev->type = type;
@@ -399,7 +402,7 @@ set_note_event(struct seq_oss_devinfo *dstatic int set_control_event (struct seq_oss_devinfo *dp,int dev,int type,int ch,int param,int val,struct snd_seq_event *ev) { -if (!snd_seq_oss_synth_is_valid (dp, dev)) +if (!snd_seq_oss_synth_info (dp, dev))return -ENXIO ; ev->type = type;
sound/core/seq/oss/seq_oss_midi.c +2 -0
@@ -29,6 +29,7 @@#include "../seq_lock.h" #include <linux/init.h> #include <linux/slab.h> +#include <linux/nospec.h> /*
@@ -318,6 +319,7 @@ get_mididev(struct seq_oss_devinfo *dp, {if (dev <0 || dev >= dp->max_mididev)return NULL ; + dev =array_index_nospec (dev, dp->max_mididev);return get_mdev (dev); }
sound/core/seq/oss/seq_oss_synth.c +42 -33
171 lines not on this page · raw message
sound/core/seq/oss/seq_oss_synth.h +2 -1
@@ -37,7 +37,8 @@ void snd_seq_oss_synth_cleanup(struct sevoid snd_seq_oss_synth_reset (struct seq_oss_devinfo *dp,int dev);int snd_seq_oss_synth_load_patch (struct seq_oss_devinfo *dp,int dev,int fmt,const char __user *buf,int p,int c); -int snd_seq_oss_synth_is_valid (struct seq_oss_devinfo *dp,int dev); +struct seq_oss_synthinfo *snd_seq_oss_synth_info (struct seq_oss_devinfo *dp, +int dev);int snd_seq_oss_synth_sysex (struct seq_oss_devinfo *dp,int dev,unsigned char *buf,struct snd_seq_event *ev);int snd_seq_oss_synth_addr (struct seq_oss_devinfo *dp,int dev,struct snd_seq_event *ev);
PATCH 214/366 ALSA: control: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 088e861edffb84879cf0c0d1b02eda078c3a0ffe upstream.
As recently Smatch suggested, a few places in ALSA control core codes may expand the array directly from the user-space value with speculation:
sound/core/control.c:1003 snd_ctl_elem_lock() warn: potential spectre issue 'kctl->vd' sound/core/control.c:1031 snd_ctl_elem_unlock() warn: potential spectre issue 'kctl->vd' sound/core/control.c:844 snd_ctl_elem_info() warn: potential spectre issue 'kctl->vd' sound/core/control.c:891 snd_ctl_elem_read() warn: potential spectre issue 'kctl->vd' sound/core/control.c:939 snd_ctl_elem_write() warn: potential spectre issue 'kctl->vd'
Although all these seem doing only the first load without further reference, we may want to stay in a safer side, so hardening with array_index_nospec() would still make sense.
In this patch, we put array_index_nospec() to the common snd_ctl_get_ioff*() helpers instead of each caller. These helpers are also referred from some drivers, too, and basically all usages are to calculate the array index from the user-space value, hence it's better to cover there.
--- include/sound/control.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/sound/control.h +5 -2
@@ -22,6 +22,7 @@* */ +#include <linux/nospec.h> #include <sound/asound.h> #define snd_kcontrol_chip (kcontrol) ((kcontrol)->private_data)
@@ -135,12 +136,14 @@ int snd_ctl_unregister_ioctl_compat(snd_static inline unsigned int snd_ctl_get_ioffnum (struct snd_kcontrol *kctl,struct snd_ctl_elem_id *id) { -return id->numid - kctl->id.numid; +unsigned int ioff = id->numid - kctl->id.numid; +return array_index_nospec (ioff, kctl->count); }static inline unsigned int snd_ctl_get_ioffidx (struct snd_kcontrol *kctl,struct snd_ctl_elem_id *id) { -return id->index - kctl->id.index; +unsigned int ioff = id->index - kctl->id.index; +return array_index_nospec (ioff, kctl->count); }static inline unsigned int snd_ctl_get_ioff (struct snd_kcontrol *kctl,struct snd_ctl_elem_id *id)
PATCH 215/366 ALSA: hda: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 69fa6f19b95597618ab30438a27b67ad93daa7c7 upstream.
As recently Smatch suggested, one place in HD-audio hwdep ioctl codes
may expand the array directly from the user-space value with
speculation:
sound/pci/hda/hda_local.h:467 get_wcaps() warn: potential spectre issue 'codec->wcaps'
As get_wcaps() itself is a fairly frequently called inline function, and there is only one single call with a user-space value, we replace only the latter one to open-code locally with array_index_nospec() hardening in this patch.
--- sound/pci/hda/hda_hwdep.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
sound/pci/hda/hda_hwdep.c +11 -1
@@ -21,6 +21,7 @@#include <linux/init.h> #include <linux/slab.h> #include <linux/compat.h> +#include <linux/nospec.h> #include <sound/core.h> #include "hda_codec.h" #include "hda_local.h"
@@ -51,7 +52,16 @@ static int get_wcap_ioctl(struct hda_codif (get_user (verb, &arg->verb))return -EFAULT ; - res =get_wcaps (codec, verb >>24 ); +/* open-code get_wcaps(verb>>24) with nospec */ + verb >>=24 ; +if (verb < codec->start_nid || + verb >= codec->start_nid + codec->num_nodes) { + res =0 ; + }else { + verb -= codec->start_nid; + verb =array_index_nospec (verb, codec->num_nodes); + res = codec->wcaps[verb]; + }if (put_user (res, &arg->res))return -EFAULT ;return 0 ;
PATCH 216/366 ALSA: opl3: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 7f054a5bee0987f1e2d4e59daea462421c76f2cb upstream.
As recently Smatch suggested, one place in OPL3 driver may expand the
array directly from the user-space value with speculation:
sound/drivers/opl3/opl3_synth.c:476 snd_opl3_set_voice() warn: potential spectre issue 'snd_opl3_regmap'
This patch puts array_index_nospec() for hardening against it.
--- sound/drivers/opl3/opl3_synth.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
sound/drivers/opl3/opl3_synth.c +5 -2
@@ -21,6 +21,7 @@#include <linux/slab.h> #include <linux/export.h> +#include <linux/nospec.h> #include <sound/opl3.h> #include <sound/asound_fm.h>
@@ -448,7 +449,7 @@ static int snd_opl3_set_voice(struct snd {unsigned short reg_side;unsigned char op_offset; -unsigned char voice_offset; +unsigned char voice_offset, voice_op;unsigned short opl3_reg;unsigned char reg_val;
@@ -473,7 +474,9 @@ static int snd_opl3_set_voice(struct snd voice_offset = voice->voice -MAX_OPL2_VOICES ; }/* Get register offset of operator */ - op_offset = snd_opl3_regmap[voice_offset][voice->op]; + voice_offset =array_index_nospec (voice_offset,MAX_OPL2_VOICES ); + voice_op =array_index_nospec (voice->op,4 ); + op_offset = snd_opl3_regmap[voice_offset][voice_op]; reg_val =0x00 ;/* Set amplitude modulation (tremolo) effect */
PATCH 217/366 ALSA: asihpi: used parts of message/response are zeroed before use
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eliot Blennerhassett <[email protected]>
commit 51e6f47dd2e3463dac6f37128fd7b7cb40c500de upstream.
--- sound/pci/asihpi/hpimsginit.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
sound/pci/asihpi/hpimsginit.c +20 -10
@@ -1,7 +1,7 @@/****************************************************************************** AudioScience HPI driver -Copyright (C) 1997-2011 AudioScience Inc. <[email protected]> +Copyright (C) 1997-2014 AudioScience Inc. <[email protected]> This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as
@@ -37,11 +37,15 @@ static u16 gwSSX2_bypass;static void hpi_init_message (struct hpi_message *phm,u16 object,u16 function) { -memset (phm,0 ,sizeof (*phm)); +u16 size; +if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) - phm->size = msg_size[object]; + size = msg_size[object];else - phm->size =sizeof (*phm); + size =sizeof (*phm); + +memset (phm,0 , size); + phm->size = size;if (gwSSX2_bypass) phm->type =HPI_TYPE_SSX2BYPASS_MESSAGE ;
@@ -60,12 +64,16 @@ static void hpi_init_message(struct hpi_void hpi_init_response (struct hpi_response *phr,u16 object,u16 function,u16 error) { -memset (phr,0 ,sizeof (*phr)); - phr->type =HPI_TYPE_RESPONSE ; +u16 size; +if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) - phr->size = res_size[object]; + size = res_size[object];else - phr->size =sizeof (*phr); + size =sizeof (*phr); + +memset (phr,0 ,sizeof (*phr)); + phr->size = size; + phr->type =HPI_TYPE_RESPONSE ; phr->object = object; phr->function = function; phr->error = error;
@@ -86,7 +94,7 @@ void hpi_init_message_response(struct hpstatic void hpi_init_messageV1 (struct hpi_message_header *phm,u16 size,u16 object,u16 function) { -memset (phm,0 ,sizeof (*phm)); +memset (phm,0 , size);if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) { phm->size = size; phm->type =HPI_TYPE_REQUEST ;
@@ -100,7 +108,9 @@ static void hpi_init_messageV1(struct hpvoid hpi_init_responseV1 (struct hpi_response_header *phr,u16 size,u16 object,u16 function) { -memset (phr,0 ,sizeof (*phr)); + (void )object; + (void )function; +memset (phr,0 , size); phr->size = size; phr->version =1 ; phr->type =HPI_TYPE_RESPONSE ;
PATCH 218/366 ALSA: asihpi: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f9d94b57e30fd1575b4935045b32d738668aa74b upstream.
As recently Smatch suggested, a couple of places in ASIHPI driver may
expand the array directly from the user-space value with speculation:
sound/pci/asihpi/hpimsginit.c:70 hpi_init_response() warn: potential spectre issue 'res_size' (local cap) sound/pci/asihpi/hpioctl.c:189 asihpi_hpi_ioctl() warn: potential spectre issue 'adapters'
This patch puts array_index_nospec() for hardening against them.
--- sound/pci/asihpi/hpimsginit.c | 13 +++++++++---- sound/pci/asihpi/hpioctl.c | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-)
sound/pci/asihpi/hpimsginit.c +9 -4
@@ -23,6 +23,7 @@#include "hpi_internal.h" #include "hpimsginit.h" +#include <linux/nospec.h> /* The actual message size for each object type */ static u16 msg_size[HPI_OBJ_MAXINDEX +1 ] =HPI_MESSAGE_SIZE_BY_OBJECT ;
@@ -39,10 +40,12 @@ static void hpi_init_message(struct hpi_ {u16 size; -if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) +if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) { + object =array_index_nospec (object,HPI_OBJ_MAXINDEX +1 ); size = msg_size[object]; -else + }else { size =sizeof (*phm); + }memset (phm,0 , size); phm->size = size;
@@ -66,10 +69,12 @@ void hpi_init_response(struct hpi_respon {u16 size; -if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) +if ((object >0 ) && (object <=HPI_OBJ_MAXINDEX )) { + object =array_index_nospec (object,HPI_OBJ_MAXINDEX +1 ); size = res_size[object]; -else + }else { size =sizeof (*phr); + }memset (phr,0 ,sizeof (*phr)); phr->size = size;
sound/pci/asihpi/hpioctl.c +3 -1
@@ -35,6 +35,7 @@ Common Linux HPI ioctl and module probe/#include <linux/pci.h> #include <linux/stringify.h> #include <linux/module.h> +#include <linux/nospec.h> #ifdef MODULE_FIRMWARE MODULE_FIRMWARE ("asihpi/dsp5000.bin" );
@@ -182,7 +183,8 @@ long asihpi_hpi_ioctl(struct file *file,struct hpi_adapter *pa =NULL ;if (hm->h.adapter_index <ARRAY_SIZE (adapters)) - pa = &adapters[hm->h.adapter_index]; + pa = &adapters[array_index_nospec (hm->h.adapter_index, +ARRAY_SIZE (adapters))];if (!pa || !pa->adapter || !pa->adapter->type) { hpi_init_response(&hr->r0, hm->h.object,
PATCH 219/366 ALSA: hdspm: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 10513142a7114d251670361ad40cba2c61403406 upstream.
As recently Smatch suggested, a couple of places in HDSP MADI driver
may expand the array directly from the user-space value with
speculation:
sound/pci/rme9652/hdspm.c:5717 snd_hdspm_channel_info() warn: potential spectre issue 'hdspm->channel_map_out' (local cap) sound/pci/rme9652/hdspm.c:5734 snd_hdspm_channel_info() warn: potential spectre issue 'hdspm->channel_map_in' (local cap)
This patch puts array_index_nospec() for hardening against them.
--- sound/pci/rme9652/hdspm.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
sound/pci/rme9652/hdspm.c +14 -10
@@ -137,6 +137,7 @@#include <linux/pci.h> #include <linux/math64.h> #include <asm/io.h> +#include <linux/nospec.h> #include <sound/core.h> #include <sound/control.h>
@@ -5724,40 +5725,43 @@ static int snd_hdspm_channel_info(struct struct snd_pcm_channel_info *info) {struct hdspm *hdspm =snd_pcm_substream_chip (substream); +unsigned int channel = info->channel;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { -if (snd_BUG_ON (info->channel >= hdspm->max_channels_out)) { +if (snd_BUG_ON (channel >= hdspm->max_channels_out)) {dev_info (hdspm->card->dev,"snd_hdspm_channel_info: output channel out of range (%d)\n" , - info->channel); + channel);return -EINVAL ; } -if (hdspm->channel_map_out[info->channel] <0 ) { + channel =array_index_nospec (channel, hdspm->max_channels_out); +if (hdspm->channel_map_out[channel] <0 ) {dev_info (hdspm->card->dev,"snd_hdspm_channel_info: output channel %d mapped out\n" , - info->channel); + channel);return -EINVAL ; } - info->offset = hdspm->channel_map_out[info->channel] * + info->offset = hdspm->channel_map_out[channel] *HDSPM_CHANNEL_BUFFER_BYTES ; }else { -if (snd_BUG_ON (info->channel >= hdspm->max_channels_in)) { +if (snd_BUG_ON (channel >= hdspm->max_channels_in)) {dev_info (hdspm->card->dev,"snd_hdspm_channel_info: input channel out of range (%d)\n" , - info->channel); + channel);return -EINVAL ; } -if (hdspm->channel_map_in[info->channel] <0 ) { + channel =array_index_nospec (channel, hdspm->max_channels_in); +if (hdspm->channel_map_in[channel] <0 ) {dev_info (hdspm->card->dev,"snd_hdspm_channel_info: input channel %d mapped out\n" , - info->channel); + channel);return -EINVAL ; } - info->offset = hdspm->channel_map_in[info->channel] * + info->offset = hdspm->channel_map_in[channel] *HDSPM_CHANNEL_BUFFER_BYTES ; }
PATCH 220/366 ALSA: rme9652: Hardening for potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f526afcd8f71945c23ce581d7864ace93de8a4f7 upstream.
As recently Smatch suggested, one place in RME9652 driver may expand
the array directly from the user-space value with speculation:
sound/pci/rme9652/rme9652.c:2074 snd_rme9652_channel_info() warn: potential spectre issue 'rme9652->channel_map' (local cap)
This patch puts array_index_nospec() for hardening against it.
--- sound/pci/rme9652/rme9652.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/pci/rme9652/rme9652.c +4 -2
@@ -35,6 +35,7 @@#include <asm/current.h> #include <asm/io.h> +#include <linux/nospec.h> static int index[SNDRV_CARDS ] =SNDRV_DEFAULT_IDX ;/* Index 0-MAX */ static char *id[SNDRV_CARDS ] =SNDRV_DEFAULT_STR ;/* ID for this card */
@@ -2059,9 +2060,10 @@ static int snd_rme9652_channel_info(struif (snd_BUG_ON (info->channel >=RME9652_NCHANNELS ))return -EINVAL ; -if ((chn = rme9652->channel_map[info->channel]) <0 ) { + chn = rme9652->channel_map[array_index_nospec (info->channel, +RME9652_NCHANNELS )]; +if (chn <0 )return -EINVAL ; - } info->offset = chn *RME9652_CHANNEL_BUFFER_BYTES ; info->first =0 ;
PATCH 221/366 tty: Use __GFP_NOFAIL for tty_ldisc_get()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
commit bcdd0ca8cb8730573afebcaae4138f8f4c8eaa20 upstream.
syzbot is reporting crashes triggered by memory allocation fault injection at tty_ldisc_get() [1]. As an attempt to handle OOM in a graceful way, we have tried commit 5362544bebe85071 ("tty: don't panic on OOM in tty_set_ldisc()"). But we reverted that attempt by commit a8983d01f9b7d600 ("Revert "tty: don't panic on OOM in tty_set_ldisc()"") due to reproducible crash. We should spend resource for finding and fixing race condition bugs rather than complicate error paths for 2 * sizeof(void *) bytes allocation failure.
[1] https://syzkaller.appspot.com/bug?id=489d33fa386453859ead58ff5171d43772b13aa3
--- drivers/tty/tty_ldisc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/tty/tty_ldisc.c +5 -6
@@ -171,12 +171,11 @@ static struct tty_ldisc *tty_ldisc_get(sreturn ERR_CAST (ldops); } - ld =kmalloc (sizeof (struct tty_ldisc ),GFP_KERNEL ); -if (ld ==NULL ) { -put_ldops (ldops); -return ERR_PTR (-ENOMEM ); - } - +/* +* There is no way to handle allocation failure of only 16 bytes. +* Let's simplify error handling and save more memory. +*/ + ld =kmalloc (sizeof (struct tty_ldisc ),GFP_KERNEL | __GFP_NOFAIL); ld->ops = ldops; ld->tty = tty;
PATCH 222/366 virtio_console: don't tie bufs to a vq
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael S. Tsirkin" <[email protected]>
commit 2855b33514d290c51d52d94e25d3ef942cd4d578 upstream.
an allocated buffer doesn't need to be tied to a vq - only vq->vdev is ever used. Pass the function the just what it needs - the vdev.
--- drivers/char/virtio_console.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/char/virtio_console.c +7 -7
@@ -417,7 +417,7 @@ static void reclaim_dma_bufs(void) } } -static struct port_buffer *alloc_buf (struct virtqueue *vq,size_t buf_size, +static struct port_buffer *alloc_buf (struct virtio_device *vdev,size_t buf_size,int pages) {struct port_buffer *buf;
@@ -440,7 +440,7 @@ static struct port_buffer *alloc_buf(strreturn buf; } -if (is_rproc_serial (vq->vdev)) { +if (is_rproc_serial (vdev)) {/* * Allocate DMA memory from ancestor. When a virtio * device is created by remoteproc, the DMA memory is
@@ -450,9 +450,9 @@ static struct port_buffer *alloc_buf(str* DMA_MEMORY_INCLUDES_CHILDREN had been supported * in dma-coherent.c */ -if (!vq->vdev->dev.parent || !vq->vdev->dev.parent->parent) +if (!vdev->dev.parent || !vdev->dev.parent->parent) goto free_buf; - buf->dev = vq->vdev->dev.parent->parent; + buf->dev = vdev->dev.parent->parent;/* Increase device refcnt to avoid freeing it */ get_device (buf->dev);
@@ -834,7 +834,7 @@ static ssize_t port_fops_write(struct fi count =min ((size_t )(32 *1024 ), count); - buf =alloc_buf (port->out_vq, count,0 ); + buf =alloc_buf (port->portdev->vdev, count,0 );if (!buf)return -ENOMEM ;
@@ -953,7 +953,7 @@ static ssize_t port_fops_splice_write(stif (ret <0 ) goto error_out; - buf =alloc_buf (port->out_vq,0 , pipe->nrbufs); + buf =alloc_buf (port->portdev->vdev,0 , pipe->nrbufs);if (!buf) { ret = -ENOMEM ; goto error_out;
@@ -1370,7 +1370,7 @@ static unsigned int fill_queue(struct vi nr_added_bufs =0 ; do { - buf = alloc_buf(vq, PAGE_SIZE, 0); + buf = alloc_buf(vq->vdev, PAGE_SIZE, 0); if (!buf) break;
PATCH 223/366 virtio: add ability to iterate over vqs
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael S. Tsirkin" <[email protected]>
commit 24a7e4d20783c0514850f24a5c41ede46ab058f0 upstream.
For cleanup it's helpful to be able to simply scan all vqs and discard all data. Add an iterator to do that.
--- include/linux/virtio.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/virtio.h +3 -0
@@ -108,6 +108,9 @@ void unregister_virtio_device(struct virvoid virtio_break_device (struct virtio_device *dev); +#define virtio_device_for_each_vq (vdev, vq) \ + list_for_each_entry(vq, &vdev->vqs, list) +/** * virtio_driver - operations for a virtio I/O driver * @driver: underlying device driver (populate name and owner).
PATCH 224/366 virtio_console: free buffers after reset
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael S. Tsirkin" <[email protected]>
commit a7a69ec0d8e4a58be7db88d33cbfa2912807bb2b upstream.
Console driver is out of spec. The spec says:
A driver MUST NOT decrement the available idx on a live virtqueue (ie. there is no way to “unexpose” buffers).
and it does exactly that by trying to detach unused buffers without doing a device reset first.
Defer detaching the buffers until device unplug.
Of course this means we might get an interrupt for a vq without an attached port now. Handle that by discarding the consumed buffer.
--- drivers/char/virtio_console.c | 49 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 25 deletions(-)
drivers/char/virtio_console.c +24 -25
@@ -1398,7 +1398,6 @@ static int add_port(struct ports_device {char debugfs_name[16 ];struct port *port; -struct port_buffer *buf;dev_t devt;unsigned int nr_added_bufs;int err;
@@ -1509,8 +1508,6 @@ static int add_port(struct ports_devicereturn 0 ; free_inbufs: -while ((buf =virtqueue_detach_unused_buf (port->in_vq))) -free_buf (buf, true); free_device:device_destroy (pdrvdata.class, port->dev->devt); free_cdev:
@@ -1535,34 +1532,14 @@ static void remove_port(struct kref *krestatic void remove_port_data (struct port *port) { -struct port_buffer *buf; -spin_lock_irq (&port->inbuf_lock);/* Remove unused data this port might have received. */ discard_port_data (port);spin_unlock_irq (&port->inbuf_lock); -/* Remove buffers we queued up for the Host to send us data in. */ -do { -spin_lock_irq (&port->inbuf_lock); - buf =virtqueue_detach_unused_buf (port->in_vq); -spin_unlock_irq (&port->inbuf_lock); -if (buf) -free_buf (buf, true); - }while (buf); -spin_lock_irq (&port->outvq_lock);reclaim_consumed_buffers (port);spin_unlock_irq (&port->outvq_lock); - -/* Free pending buffers from the out-queue. */ -do { -spin_lock_irq (&port->outvq_lock); - buf =virtqueue_detach_unused_buf (port->out_vq); -spin_unlock_irq (&port->outvq_lock); -if (buf) -free_buf (buf, true); - }while (buf); }/*
@@ -1783,13 +1760,24 @@ static void control_work_handler(structspin_unlock (&portdev->c_ivq_lock); } +static void flush_bufs (struct virtqueue *vq,bool can_sleep) +{ +struct port_buffer *buf; +unsigned int len; + +while ((buf =virtqueue_get_buf (vq, &len))) +free_buf (buf, can_sleep); +} +static void out_intr (struct virtqueue *vq) {struct port *port; port =find_port_by_vq (vq->vdev->priv, vq); -if (!port) +if (!port) { +flush_bufs (vq, false);return ; + }wake_up_interruptible (&port->waitqueue); }
@@ -1800,8 +1788,10 @@ static void in_intr(struct virtqueue *vqunsigned long flags; port =find_port_by_vq (vq->vdev->priv, vq); -if (!port) +if (!port) { +flush_bufs (vq, false);return ; + }spin_lock_irqsave (&port->inbuf_lock, flags); port->inbuf =get_inbuf (port);
@@ -1976,6 +1966,15 @@ static const struct file_operations portstatic void remove_vqs (struct ports_device *portdev) { +struct virtqueue *vq; + +virtio_device_for_each_vq (portdev->vdev, vq) { +struct port_buffer *buf; + +flush_bufs (vq, true); +while ((buf =virtqueue_detach_unused_buf (vq))) +free_buf (buf, true); + } portdev->vdev->config->del_vqs (portdev->vdev);kfree (portdev->in_vqs);kfree (portdev->out_vqs);
PATCH 225/366 virtio_console: drop custom control queue cleanup
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael S. Tsirkin" <[email protected]>
commit 61a8950c5c5708cf2068b29ffde94e454e528208 upstream.
We now cleanup all VQs on device removal - no need to handle the control VQ specially.
--- drivers/char/virtio_console.c | 17 ----------------- 1 file changed, 17 deletions(-)
drivers/char/virtio_console.c +0 -17
@@ -1980,21 +1980,6 @@ static void remove_vqs(struct ports_devikfree (portdev->out_vqs); } -static void remove_controlq_data (struct ports_device *portdev) -{ -struct port_buffer *buf; -unsigned int len; - -if (!use_multiport (portdev)) -return ; - -while ((buf =virtqueue_get_buf (portdev->c_ivq, &len))) -free_buf (buf, true); - -while ((buf =virtqueue_detach_unused_buf (portdev->c_ivq))) -free_buf (buf, true); -} -/* * Once we're further in boot, we get probed like any other virtio * device.
@@ -2144,7 +2129,6 @@ static void virtcons_remove(struct virti* have to just stop using the port, as the vqs are going * away. */ -remove_controlq_data (portdev);remove_vqs (portdev);kfree (portdev); }
@@ -2189,7 +2173,6 @@ static int virtcons_freeze(struct virtio*/ if (use_multiport (portdev))virtqueue_disable_cb (portdev->c_ivq); -remove_controlq_data (portdev);list_for_each_entry (port, &portdev->ports, list) {virtqueue_disable_cb (port->in_vq);
PATCH 226/366 virtio_console: move removal code
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael S. Tsirkin" <[email protected]>
commit aa44ec867030a72e8aa127977e37dec551d8df19 upstream.
Will make it reusable for error handling.
--- drivers/char/virtio_console.c | 72 +++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-)
drivers/char/virtio_console.c +36 -36
@@ -1980,6 +1980,42 @@ static void remove_vqs(struct ports_devikfree (portdev->out_vqs); } +static void virtcons_remove (struct virtio_device *vdev) +{ +struct ports_device *portdev; +struct port *port, *port2; + + portdev = vdev->priv; + +spin_lock_irq (&pdrvdata_lock); +list_del (&portdev->list); +spin_unlock_irq (&pdrvdata_lock); + +/* Disable interrupts for vqs */ + vdev->config->reset (vdev); +/* Finish up work that's lined up */ +if (use_multiport (portdev)) +cancel_work_sync (&portdev->control_work); +else +cancel_work_sync (&portdev->config_work); + +list_for_each_entry_safe (port, port2, &portdev->ports, list) +unplug_port (port); + +unregister_chrdev (portdev->chr_major,"virtio-portsdev" ); + +/* +* When yanking out a device, we immediately lose the +* (device-side) queues. So there's no point in keeping the +* guest side around till we drop our final reference. This +* also means that any ports which are in an open state will +* have to just stop using the port, as the vqs are going +* away. +*/ +remove_vqs (portdev); +kfree (portdev); +} +/* * Once we're further in boot, we get probed like any other virtio * device.
@@ -2097,42 +2133,6 @@ fail:return err; } -static void virtcons_remove (struct virtio_device *vdev) -{ -struct ports_device *portdev; -struct port *port, *port2; - - portdev = vdev->priv; - -spin_lock_irq (&pdrvdata_lock); -list_del (&portdev->list); -spin_unlock_irq (&pdrvdata_lock); - -/* Disable interrupts for vqs */ - vdev->config->reset (vdev); -/* Finish up work that's lined up */ -if (use_multiport (portdev)) -cancel_work_sync (&portdev->control_work); -else -cancel_work_sync (&portdev->config_work); - -list_for_each_entry_safe (port, port2, &portdev->ports, list) -unplug_port (port); - -unregister_chrdev (portdev->chr_major,"virtio-portsdev" ); - -/* -* When yanking out a device, we immediately lose the -* (device-side) queues. So there's no point in keeping the -* guest side around till we drop our final reference. This -* also means that any ports which are in an open state will -* have to just stop using the port, as the vqs are going -* away. -*/ -remove_vqs (portdev); -kfree (portdev); -} -static struct virtio_device_id id_table[] = { {VIRTIO_ID_CONSOLE ,VIRTIO_DEV_ANY_ID }, {0 },
PATCH 227/366 virtio_console: reset on out of memory
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Michael S. Tsirkin" <[email protected]>
commit 5c60300d68da32ca77f7f978039dc72bfc78b06b upstream.
When out of memory and we can't add ctrl vq buffers, probe fails. Unfortunately the error handling is out of spec: it calls del_vqs without bothering to reset the device first.
To fix, call the full cleanup function in this case.
--- drivers/char/virtio_console.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/char/virtio_console.c +10 -7
@@ -2073,6 +2073,7 @@ static int virtcons_probe(struct virtio_spin_lock_init (&portdev->ports_lock);INIT_LIST_HEAD (&portdev->ports); +INIT_LIST_HEAD (&portdev->list);INIT_WORK (&portdev->config_work, &config_work_handler);INIT_WORK (&portdev->control_work, &control_work_handler);
@@ -2088,8 +2089,15 @@ static int virtcons_probe(struct virtio_if (!nr_added_bufs) {dev_err (&vdev->dev,"Error allocating buffers for control queue\n" ); - err = -ENOMEM ; - goto free_vqs; +/* +* The host might want to notify mgmt sw about device +* add failure. +*/ +__send_control_msg (portdev,VIRTIO_CONSOLE_BAD_ID , +VIRTIO_CONSOLE_DEVICE_READY ,0 ); +/* Device was functional: we need full cleanup. */ +virtcons_remove (vdev); +return -ENOMEM ; } }else {/*
@@ -2120,11 +2128,6 @@ static int virtcons_probe(struct virtio_return 0 ; -free_vqs: -/* The host might want to notify mgmt sw about device add failure */ -__send_control_msg (portdev,VIRTIO_CONSOLE_BAD_ID , -VIRTIO_CONSOLE_DEVICE_READY ,0 ); -remove_vqs (portdev); free_chrdev:unregister_chrdev (portdev->chr_major,"virtio-portsdev" ); free:
PATCH 228/366 x86/smpboot: Don't use mwait_play_dead() on AMD systems
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Yazen Ghannam <[email protected]>
commit da6fa7ef67f07108a1b0cb9fd9e7fcaabd39c051 upstream.
Recent AMD systems support using MWAIT for C1 state. However, MWAIT will not allow deeper cstates than C1 on current systems.
play_dead() expects to use the deepest state available. The deepest state available on AMD systems is reached through SystemIO or HALT. If MWAIT is available, it is preferred over the other methods, so the CPU never reaches the deepest possible state.
Don't try to use MWAIT to play_dead() on AMD systems. Instead, use CPUIDLE to enter the deepest state advertised by firmware. If CPUIDLE is not available then fallback to HALT.
--- arch/x86/kernel/smpboot.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kernel/smpboot.c +2 -0
@@ -1397,6 +1397,8 @@ static inline void mwait_play_dead(void)void *mwait_ptr;int i; +if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) +return ;if (!this_cpu_has (X86_FEATURE_MWAIT ))return ;if (!this_cpu_has (X86_FEATURE_CLFLUSH ))
PATCH 229/366 libceph: validate con->state at the top of try_write()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Dryomov <[email protected]>
commit 9c55ad1c214d9f8c4594ac2c3fa392c1c32431a7 upstream.
ceph_con_workfn() validates con->state before calling try_read() and then try_write(). However, try_read() temporarily releases con->mutex, notably in process_message() and ceph_con_in_msg_alloc(), opening the window for ceph_con_close() to sneak in, close the connection and release con->sock. When try_write() is called on the assumption that con->state is still valid (i.e. not STANDBY or CLOSED), a NULL sock gets passed to the networking stack:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000020 IP: selinux_socket_sendmsg+0x5/0x20
Make sure con->state is valid at the top of try_write() and add an explicit BUG_ON for this, similar to try_read().
--- net/ceph/messenger.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/ceph/messenger.c +7 -0
@@ -2453,6 +2453,11 @@ static int try_write(struct ceph_connectint ret =1 ;dout ("try_write start %p state %lu\n" , con, con->state); +if (con->state !=CON_STATE_PREOPEN && + con->state !=CON_STATE_CONNECTING && + con->state !=CON_STATE_NEGOTIATING && + con->state !=CON_STATE_OPEN ) +return 0 ; more:dout ("try_write out_kvec_bytes %d\n" , con->out_kvec_bytes);
@@ -2478,6 +2483,8 @@ more: } more_kvec: +BUG_ON (!con->sock); +/* kvec data queued? */ if (con->out_skip) { ret =write_partial_skip (con);
PATCH 230/366 tracing/uprobe: Drop isdigit() check in create_trace_uprobe
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Safonov <[email protected]>
commit 5ba8a4a96f6eaa6af88e24c7794f142217aa3b6f upstream.
It's useless. Before:
[tracing]# echo 'p:test /a:0x0' >> uprobe_events [tracing]# echo 'p:test a:0x0' >> uprobe_events -bash: echo: write error: No such file or directory [tracing]# echo 'p:test 1:0x0' >> uprobe_events -bash: echo: write error: Invalid argument
After:
[tracing]# echo 'p:test 1:0x0' >> uprobe_events -bash: echo: write error: No such file or directory
--- kernel/trace/trace_uprobe.c | 4 ---- 1 file changed, 4 deletions(-)
kernel/trace/trace_uprobe.c +0 -4
@@ -430,10 +430,6 @@ static int create_trace_uprobe(int argc,pr_info ("Probe point is not specified.\n" );return -EINVAL ; } -if (isdigit (argv[1 ][0 ])) { -pr_info ("probe point must be have a filename.\n" ); -return -EINVAL ; - } arg =strchr (argv[1 ],':' );if (!arg) { ret = -EINVAL ;
PATCH 231/366 uprobe: Find last occurrence of ':' when parsing uprobe PATH:OFFSET
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Kenny Yu <[email protected]>
commit 6496bb72bf20c1c7e4d6be44dfa663163e709116 upstream.
Previously, create_trace_uprobe found the *first* occurence of the ':' character when parsing PATH:OFFSET for a uprobe. However, if the path contains a ':' character, then the function would parse the path incorrectly. Even worse, if the path does not exist, the subsequent call to kern_path() would set ret to ENOENT, leading to very cryptic errno values in user space.
The fix is to find the *last* occurence of ':'.
How to repro:: The write fails with "No such file or directory", suggesting incorrectly that the uprobe_events file does not exist.
$ mkdir testing && cd testing $ cp /bin/bash . $ cp /bin/bash ./bash:with:colon $ echo "p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x6" > /sys/kernel/debug/tracing/uprobe_events # this works $ echo "p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x6" >> /sys/kernel/debug/tracing/uprobe_events # this doesn't -bash: echo: write error: No such file or directory
With the patch:
$ echo "p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x6" > /sys/kernel/debug/tracing/uprobe_events # this still works $ echo "p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x6" >> /sys/kernel/debug/tracing/uprobe_events # this works now too! $ cat /sys/kernel/debug/tracing/uprobe_events p:uprobes/p__root_testing_bash_0x6 /root/testing/bash:0x0000000000000006 p:uprobes/p__root_testing_bash_with_colon_0x6 /root/testing/bash:with:colon:0x0000000000000006
--- kernel/trace/trace_uprobe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/trace_uprobe.c +2 -1
@@ -430,7 +430,8 @@ static int create_trace_uprobe(int argc,pr_info ("Probe point is not specified.\n" );return -EINVAL ; } - arg =strchr (argv[1 ],':' ); +/* Find the last occurrence, in case the path contains ':' too. */ + arg =strrchr (argv[1 ],':' );if (!arg) { ret = -EINVAL ; goto fail_address_parse;
PATCH 232/366 tracing: Deletion of an unnecessary check before iput()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Markus Elfring <[email protected]>
commit 16a8ef2751801346f1f76a18685b2beb63cd170f upstream.
The iput() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.
This issue was detected by using the Coccinelle software.
--- kernel/trace/trace_uprobe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/trace/trace_uprobe.c +1 -2
@@ -552,8 +552,7 @@ error:return ret; fail_address_parse: -if (inode) -iput (inode); +iput (inode);pr_info ("Failed to parse address or file.\n" );
Re: [PATCH 3.16 232/366] tracing: Deletion of an unnecessary check before iput()
Quoted 1 line · Ben Hutchings
3.16.60-rc1 review patch. If anyone has any objections, please let me know.
I believe that no stable or backport kernel needs to apply patches like this unless it's needed for other real patches to be applied more easily.
Quoted 33 lines
------------------
From: Markus Elfring <[email protected]>
commit
16a8ef2751801346f1f76a18685b2beb63cd170fupstream.The
iput()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>Signed-off-by Steven Rostedt <[email protected]>Signed-off-by Ben Hutchings <[email protected]>--- kernel/trace/trace_uprobe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/trace/trace_uprobe.c +1
-2@@ -552,8 +552,7 @@ error:return ret; fail_address_parse: -if (inode) -iput (inode); +iput (inode);pr_info ("Failed to parse address or file.\n" );
Re: [PATCH 3.16 232/366] tracing: Deletion of an unnecessary check before iput()
Quoted 6 lines · Joe Perches
Quoted 1 line · Ben Hutchings
3.16.60-rc1 review patch. If anyone has any objections, please let me know.
I believe that no stable or backport kernel needs to apply patches like this unless it's needed for other real patches to be applied more easily.
This is only included so I could apply commit 0c92c7a3c5d4 "tracing:
Fix bad use of igrab in trace_uprobe.c" with fewer changes.
Ben.
Quoted 33 lines
Quoted 33 lines
------------------
From: Markus Elfring <[email protected]>
commit
16a8ef2751801346f1f76a18685b2beb63cd170fupstream.The
iput()function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>Signed-off-by Steven Rostedt <[email protected]>Signed-off-by Ben Hutchings <[email protected]>--- kernel/trace/trace_uprobe.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/trace/trace_uprobe.c +1
-2@@ -552,8 +552,7 @@ error:return ret; fail_address_parse: -if (inode) -iput (inode); +iput (inode);pr_info ("Failed to parse address or file.\n" );
Signature · 2 lines
Ben Hutchings I haven't lost my mind; it's backed up on tape somewhere.
PATCH 233/366 tracing: Fix bad use of igrab in trace_uprobe.c
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Song Liu <[email protected]>
commit 0c92c7a3c5d416f47b32c5f20a611dfeca5d5f2e upstream.
As Miklos reported and suggested:
This pattern repeats two times in trace_uprobe.c and in kernel/events/core.c as well:
ret = kern_path(filename, LOOKUP_FOLLOW, &path);
if (ret)
goto fail_address_parse;
inode = igrab(d_inode(path.dentry));
path_put(&path); And it's wrong. You can only hold a reference to the inode if you have an active ref to the superblock as well (which is normally through path.mnt) or holding s_umount.
This way unmounting the containing filesystem while the tracepoint is active will give you the "VFS: Busy inodes after unmount..." message and a crash when the inode is finally put.
Solution: store path instead of inode.
This patch fixes two instances in trace_uprobe.c. struct path is added to struct trace_uprobe to keep the inode and containing mount point referenced.
[bwh: Backported to 3.16:
- Open-code d_real_inode(), d_is_reg()
- Drop changes in create_local_trace_uprobe()]
--- kernel/trace/trace_uprobe.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-)
kernel/trace/trace_uprobe.c +10 -14
@@ -53,6 +53,7 @@ struct trace_uprobe {struct list_head list;struct trace_uprobe_filter filter;struct uprobe_consumer consumer; +struct path path;struct inode *inode;char *filename;unsigned long offset;
@@ -284,7 +285,7 @@ static void free_trace_uprobe(struct trafor (i =0 ; i < tu->tp.nr_args; i++)traceprobe_free_probe_arg (&tu->tp.args[i]); -iput (tu->inode); +path_put (&tu->path);kfree (tu->tp.call.class->system);kfree (tu->tp.call.name);kfree (tu->filename);
@@ -358,7 +359,6 @@ end:static int create_trace_uprobe (int argc,char **argv) {struct trace_uprobe *tu; -struct inode *inode;char *arg, *event, *group, *filename;char buf[MAX_EVENT_NAME_LEN ];struct path path;
@@ -366,7 +366,6 @@ static int create_trace_uprobe(int argc,bool is_delete, is_return;int i, ret; - inode =NULL ; ret =0 ; is_delete = false; is_return = false;
@@ -432,21 +431,16 @@ static int create_trace_uprobe(int argc, }/* Find the last occurrence, in case the path contains ':' too. */ arg =strrchr (argv[1 ],':' ); -if (!arg) { - ret = -EINVAL ; - goto fail_address_parse; - } +if (!arg) +return -EINVAL ; *arg++ ='\0' ; filename = argv[1 ]; ret =kern_path (filename,LOOKUP_FOLLOW , &path);if (ret) - goto fail_address_parse; - - inode =igrab (path.dentry->d_inode); -path_put (&path); +return ret; -if (!inode || !S_ISREG (inode->i_mode)) { +if (!S_ISREG (path.dentry->d_inode->i_mode)) { ret = -EINVAL ; goto fail_address_parse; }
@@ -485,7 +479,7 @@ static int create_trace_uprobe(int argc, goto fail_address_parse; } tu->offset = offset; - tu->inode = inode; + tu->path = path; tu->filename =kstrdup (filename,GFP_KERNEL );if (!tu->filename) {
@@ -552,7 +546,7 @@ error:return ret; fail_address_parse: -iput (inode); +path_put (&path);pr_info ("Failed to parse address or file.\n" );
@@ -919,6 +913,7 @@ probe_event_enable(struct trace_uprobe * goto err_flags; tu->consumer.filter = filter; + tu->inode = tu->path.dentry->d_inode; ret =uprobe_register (tu->inode, tu->offset, &tu->consumer);if (ret) goto err_buffer;
@@ -964,6 +959,7 @@ probe_event_disable(struct trace_uprobeWARN_ON (!uprobe_filter_is_empty (&tu->filter));uprobe_unregister (tu->inode, tu->offset, &tu->consumer); + tu->inode =NULL ; tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE ;uprobe_buffer_disable ();
PATCH 234/366 libata: Apply NOLPM quirk for SanDisk SD7UB3Q*G1001 SSDs
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit 184add2ca23ce5edcac0ab9c3b9be13f91e7b567 upstream.
Richard Jones has reported that using med_power_with_dipm on a T450s with a Sandisk SD7UB3Q256G1001 SSD (firmware version X2180501) is causing the machine to hang.
Switching the LPM to max_performance fixes this, so it seems that this Sandisk SSD does not handle LPM well.
Note in the past there have been bug-reports about the following Sandisk models not working with min_power, so we may need to extend the quirk list in the future: name - firmware
Sandisk SD6SB2M512G1022I - X210400
Sandisk SD6PP4M-256G-1006 - A200906
--- drivers/ata/libata-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/ata/libata-core.c +3 -0
@@ -4239,6 +4239,9 @@ static const struct ata_blacklist_entry {"Crucial_CT960M500*" ,NULL ,ATA_HORKAGE_NO_NCQ_TRIM | ATA_HORKAGE_NOLPM, }, + /* Sandisk devices which are known to not handle LPM well */ + { "SanDisk SD7UB3Q*G1001", NULL, ATA_HORKAGE_NOLPM, }, + /* devices that don't properly handle queued TRIM commands */ { "Micron_M500_*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, }, { "Crucial_CT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
PATCH 235/366 RDMA/mlx5: Protect from shift operand overflow
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
commit 002bf2282b2d7318e444dca9ffcb994afc5d5f15 upstream.
Ensure that user didn't supply values too large that can cause overflow.
UBSAN: Undefined behaviour in drivers/infiniband/hw/mlx5/qp.c:263:23 shift exponent -2147483648 is negative CPU: 0 PID: 292 Comm: syzkaller612609 Not tainted 4.16.0-rc1+ #131 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.11.0-0-g63451fca13-prebuilt.qemu-project.org 04/01/2014 Call Trace: dump_stack+0xde/0x164 ubsan_epilogue+0xe/0x81 set_rq_size+0x7c2/0xa90 create_qp_common+0xc18/0x43c0 mlx5_ib_create_qp+0x379/0x1ca0 create_qp.isra.5+0xc94/0x2260 ib_uverbs_create_qp+0x21b/0x2a0 ib_uverbs_write+0xc2c/0x1010 vfs_write+0x1b0/0x550 SyS_write+0xc7/0x1a0 do_syscall_64+0x1aa/0x740 entry_SYSCALL_64_after_hwframe+0x26/0x9b RIP: 0033:0x433569 RSP: 002b:00007ffc6e62f448 EFLAGS: 00000217 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 00000000004002f8 RCX: 0000000000433569 RDX: 0000000000000070 RSI: 00000000200042c0 RDI: 0000000000000003 RBP: 00000000006d5018 R08: 00000000004002f8 R09: 00000000004002f8 R10: 00000000004002f8 R11: 0000000000000217 R12: 0000000000000000 R13: 000000000040c9f0 R14: 000000000040ca80 R15: 0000000000000006
--- drivers/infiniband/hw/mlx5/qp.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/hw/mlx5/qp.c +4 -0
@@ -174,7 +174,11 @@ static int set_rq_size(struct mlx5_ib_de }else {if (ucmd) { qp->rq.wqe_cnt = ucmd->rq_wqe_count; +if (ucmd->rq_wqe_shift >BITS_PER_BYTE *sizeof (ucmd->rq_wqe_shift)) +return -EINVAL ; qp->rq.wqe_shift = ucmd->rq_wqe_shift; +if ((1 << qp->rq.wqe_shift) /sizeof (struct mlx5_wqe_data_seg ) < qp->wq_sig) +return -EINVAL ; qp->rq.max_gs = (1 << qp->rq.wqe_shift) /sizeof (struct mlx5_wqe_data_seg ) - qp->wq_sig; qp->rq.max_post = qp->rq.wqe_cnt; }else {
PATCH 236/366 IB/mlx5: Use unlimited rate when static rate is not supported
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Danit Goldberg <[email protected]>
commit 4f32ac2e452c2180cd2df581cbadac183e27ecd0 upstream.
Before the change, if the user passed a static rate value different than zero and the FW doesn't support static rate,
it would end up configuring rate of 2.5 GBps.
Fix this by using rate 0; unlimited, in cases where FW doesn't support static rate configuration.
--- drivers/infiniband/hw/mlx5/qp.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +9 -9
@@ -1285,18 +1285,18 @@ enum {static int ib_rate_to_mlx5 (struct mlx5_ib_dev *dev,u8 rate) { -if (rate ==IB_RATE_PORT_CURRENT ) { +if (rate ==IB_RATE_PORT_CURRENT )return 0 ; - }else if (rate <IB_RATE_2_5_GBPS || rate >IB_RATE_300_GBPS ) { + +if (rate <IB_RATE_2_5_GBPS || rate >IB_RATE_300_GBPS )return -EINVAL ; - }else { -while (rate !=IB_RATE_2_5_GBPS && - !(1 << (rate +MLX5_STAT_RATE_OFFSET ) & - dev->mdev.caps.stat_rate_support)) - --rate; - } -return rate +MLX5_STAT_RATE_OFFSET ; +while (rate !=IB_RATE_PORT_CURRENT && + !(1 << (rate +MLX5_STAT_RATE_OFFSET ) & + dev->mdev.caps.stat_rate_support)) + --rate; + +return rate ? rate +MLX5_STAT_RATE_OFFSET : rate; } static int mlx5_set_path(struct mlx5_ib_dev *dev, const struct ib_ah_attr *ah,
PATCH 237/366 ALSA: seq: Fix races at MIDI encoding in snd_virmidi_output_trigger()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 8f22e52528cc372b218b5f100457469615c733ce upstream.
The sequencer virmidi code has an open race at its output trigger
callback: namely, virmidi keeps only one event packet for processing while it doesn't protect for concurrent output trigger calls.
snd_virmidi_output_trigger() tries to process the previously unfinished event before starting encoding the given MIDI stream, but this is done without any lock. Meanwhile, if another rawmidi stream starts the output trigger, this proceeds further, and overwrites the event package that is being processed in another thread. This eventually corrupts and may lead to the invalid memory access if the event type is like SYSEX.
The fix is just to move the spinlock to cover both the pending event and the new stream.
The bug was spotted by a new fuzzer, RaceFuzzer.
--- sound/core/seq/seq_virmidi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/seq/seq_virmidi.c +2 -2
@@ -174,12 +174,12 @@ static void snd_virmidi_output_trigger(s }return ; } +spin_lock_irqsave (&substream->runtime->lock, flags);if (vmidi->event.type !=SNDRV_SEQ_EVENT_NONE ) {if (snd_seq_kernel_client_dispatch (vmidi->client, &vmidi->event,in_atomic (),0 ) <0 ) -return ; + goto out; vmidi->event.type =SNDRV_SEQ_EVENT_NONE ; } -spin_lock_irqsave (&substream->runtime->lock, flags);while (1 ) { count =__snd_rawmidi_transmit_peek (substream, buf,sizeof (buf));if (count <=0 )
PATCH 238/366 sctp: handle two v4 addrs comparison in sctp_inet6_cmp_addr
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit d625329b06e46bd20baf9ee40847d11982569204 upstream.
Since sctp ipv6 socket also supports v4 addrs, it's possible to compare two v4 addrs in pf v6 .cmp_addr, sctp_inet6_cmp_addr.
However after Commit 1071ec9d453a ("sctp: do not check port in sctp_inet6_cmp_addr"), it no longer calls af1->cmp_addr, which in this case is sctp_v4_cmp_addr, but calls __sctp_v6_cmp_addr where it handles them as two v6 addrs. It would cause a out of bounds crash.
syzbot found this crash when trying to bind two v4 addrs to a v6 socket.
This patch fixes it by adding the process for two v4 addrs in sctp_inet6_cmp_addr.
--- net/sctp/ipv6.c | 3 +++ 1 file changed, 3 insertions(+)
net/sctp/ipv6.c +3 -0
@@ -840,6 +840,9 @@ static int sctp_inet6_cmp_addr(const uniif (sctp_is_any (sk, addr1) ||sctp_is_any (sk, addr2))return 1 ; +if (addr1->sa.sa_family ==AF_INET && addr2->sa.sa_family ==AF_INET ) +return addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr; +return __sctp_v6_cmp_addr (addr1, addr2); }
PATCH 239/366 NET: usb: qmi_wwan: add support for ublox R410M PID 0x90b2
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: SZ Lin (林上智)
<[email protected]>
commit 9306b38e42cb266f98bff6f6f4c1c652aa79ba45 upstream.
This patch adds support for PID 0x90b2 of ublox R410M.
qmicli -d /dev/cdc-wdm0 --dms-get-manufacturer [/dev/cdc-wdm0] Device manufacturer retrieved:
Manufacturer: 'u-blox'
qmicli -d /dev/cdc-wdm0 --dms-get-model
[/dev/cdc-wdm0] Device model retrieved:
Model: 'SARA-R410M-02B'
--- drivers/net/usb/qmi_wwan.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/usb/qmi_wwan.c +1 -0
@@ -677,6 +677,7 @@ static const struct usb_device_id produc {QMI_FIXED_INTF(0x05c6, 0x9080, 8)}, {QMI_FIXED_INTF(0x05c6, 0x9083, 3)}, {QMI_FIXED_INTF(0x05c6, 0x9084, 4)}, + {QMI_FIXED_INTF(0x05c6, 0x90b2, 3)}, /* ublox R410M */ {QMI_FIXED_INTF(0x05c6, 0x920d, 0)}, {QMI_FIXED_INTF(0x05c6, 0x920d, 5)}, {QMI_FIXED_INTF(0x0846, 0x68a2, 8)},
PATCH 240/366 RDMA/cxgb4: release hw resources on device removal
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Raju Rangoju <[email protected]>
commit 26bff1bd74a4f7417509a83295614e9dab995b2a upstream.
The c4iw_rdev_close() logic was not releasing all the hw resources (PBL and RQT memory) during the device removal event (driver unload / system reboot). This can cause panic in gen_pool_destroy().
The module remove function will wait for all the hw resources to be released during the device removal event.
Fixes c12a67fe(iw_cxgb4: free EQ queue memory on last deref)
---
drivers/infiniband/hw/cxgb4/device.c +8 -0
@@ -698,6 +698,12 @@ static int c4iw_rdev_open(struct c4iw_rd goto err4; } rdev->status_page->db_off =0 ; + +init_completion (&rdev->rqt_compl); +init_completion (&rdev->pbl_compl); +kref_init (&rdev->rqt_kref); +kref_init (&rdev->pbl_kref); +return 0 ; err4:c4iw_rqtpool_destroy (rdev);
@@ -714,6 +720,8 @@ static void c4iw_rdev_close(struct c4iw_free_page ((unsigned long )rdev->status_page);c4iw_pblpool_destroy (rdev);c4iw_rqtpool_destroy (rdev); +wait_for_completion (&rdev->pbl_compl); +wait_for_completion (&rdev->rqt_compl);c4iw_destroy_resource (&rdev->resource); }
drivers/infiniband/hw/cxgb4/iw_cxgb4.h +4 -0
@@ -157,6 +157,10 @@ struct c4iw_rdev {void __iomem *oc_mw_kva;struct c4iw_stats stats;struct t4_dev_status_page *status_page; +struct completion rqt_compl; +struct completion pbl_compl; +struct kref rqt_kref; +struct kref pbl_kref; };static inline int c4iw_fatal_error (struct c4iw_rdev *rdev)
drivers/infiniband/hw/cxgb4/resource.c +24 -2
@@ -260,12 +260,22 @@ u32 c4iw_pblpool_alloc(struct c4iw_rdev rdev->stats.pbl.cur +=roundup (size,1 <<MIN_PBL_SHIFT );if (rdev->stats.pbl.cur > rdev->stats.pbl.max) rdev->stats.pbl.max = rdev->stats.pbl.cur; +kref_get (&rdev->pbl_kref); }else rdev->stats.pbl.fail++;mutex_unlock (&rdev->stats.lock);return (u32 )addr; } +static void destroy_pblpool (struct kref *kref) +{ +struct c4iw_rdev *rdev; + + rdev = container_of(kref, struct c4iw_rdev, pbl_kref); +gen_pool_destroy (rdev->pbl_pool); +complete (&rdev->pbl_compl); +} +void c4iw_pblpool_free (struct c4iw_rdev *rdev,u32 addr,int size) {PDBG ("%s addr 0x%x size %d\n" , __func__, addr, size);
@@ -273,6 +283,7 @@ void c4iw_pblpool_free(struct c4iw_rdev rdev->stats.pbl.cur -=roundup (size,1 <<MIN_PBL_SHIFT );mutex_unlock (&rdev->stats.lock);gen_pool_free (rdev->pbl_pool, (unsigned long )addr, size); +kref_put (&rdev->pbl_kref, destroy_pblpool); }int c4iw_pblpool_create (struct c4iw_rdev *rdev)
@@ -312,7 +323,7 @@ int c4iw_pblpool_create(struct c4iw_rdevvoid c4iw_pblpool_destroy (struct c4iw_rdev *rdev) { -gen_pool_destroy (rdev->pbl_pool); +kref_put (&rdev->pbl_kref, destroy_pblpool); }/*
@@ -333,12 +344,22 @@ u32 c4iw_rqtpool_alloc(struct c4iw_rdev rdev->stats.rqt.cur +=roundup (size <<6 ,1 <<MIN_RQT_SHIFT );if (rdev->stats.rqt.cur > rdev->stats.rqt.max) rdev->stats.rqt.max = rdev->stats.rqt.cur; +kref_get (&rdev->rqt_kref); }else rdev->stats.rqt.fail++;mutex_unlock (&rdev->stats.lock);return (u32 )addr; } +static void destroy_rqtpool (struct kref *kref) +{ +struct c4iw_rdev *rdev; + + rdev = container_of(kref, struct c4iw_rdev, rqt_kref); +gen_pool_destroy (rdev->rqt_pool); +complete (&rdev->rqt_compl); +} +void c4iw_rqtpool_free (struct c4iw_rdev *rdev,u32 addr,int size) {PDBG ("%s addr 0x%x size %d\n" , __func__, addr, size <<6 );
@@ -346,6 +367,7 @@ void c4iw_rqtpool_free(struct c4iw_rdev rdev->stats.rqt.cur -=roundup (size <<6 ,1 <<MIN_RQT_SHIFT );mutex_unlock (&rdev->stats.lock);gen_pool_free (rdev->rqt_pool, (unsigned long )addr, size <<6 ); +kref_put (&rdev->rqt_kref, destroy_rqtpool); }int c4iw_rqtpool_create (struct c4iw_rdev *rdev)
@@ -383,7 +405,7 @@ int c4iw_rqtpool_create(struct c4iw_rdevvoid c4iw_rqtpool_destroy (struct c4iw_rdev *rdev) { -gen_pool_destroy (rdev->rqt_pool); +kref_put (&rdev->rqt_kref, destroy_rqtpool); }/*
PATCH 241/366 RDMA/iwpm: fix memory leak on map_info
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Colin Ian King <[email protected]>
commit f96416cea7bce9afe619c15e87fced70f93f9098 upstream.
In the cases where iwpm_hash_bucket is NULL and where function get_mapinfo_hash_bucket returns NULL then the map_info is never added to hash_bucket_head and hence there is a leak of map_info. Fix this by nullifying hash_bucket_head and if that is null we know that that map_info was not added to hash_bucket_head and hence map_info should be free'd.
Detected by CoverityScan, CID#1222481 ("Resource Leak")
--- drivers/infiniband/core/iwpm_util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/core/iwpm_util.c +4 -1
@@ -96,7 +96,7 @@ int iwpm_create_mapinfo(struct sockaddr_ struct sockaddr_storage *mapped_sockaddr, u8 nl_client) { -struct hlist_head *hash_bucket_head; +struct hlist_head *hash_bucket_head =NULL ;struct iwpm_mapping_info *map_info;unsigned long flags;
@@ -121,6 +121,9 @@ int iwpm_create_mapinfo(struct sockaddr_hlist_add_head (&map_info->hlist_node, hash_bucket_head); }spin_unlock_irqrestore (&iwpm_mapinfo_lock, flags); + +if (!hash_bucket_head) +kfree (map_info);return 0 ; }EXPORT_SYMBOL (iwpm_create_mapinfo);
PATCH 242/366 iw_cxgb4: Atomically flush per QP HW CQEs
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Bharat Potnuri <[email protected]>
commit 2df19e19ae90d94fd8724083f161f368a2797537 upstream.
When a CQ is shared by multiple QPs, c4iw_flush_hw_cq() needs to acquire corresponding QP lock before moving the CQEs into its corresponding SW queue and accessing the SQ contents for completing a WR. Ignore CQEs if corresponding QP is already flushed.
--- drivers/infiniband/hw/cxgb4/cq.c | 11 ++++++++++- drivers/infiniband/hw/cxgb4/iw_cxgb4.h | 2 +- drivers/infiniband/hw/cxgb4/qp.c | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-)
drivers/infiniband/hw/cxgb4/cq.c +10 -1
@@ -331,7 +331,7 @@ static void advance_oldest_read(struct t* Deal with out-of-order and/or completions that complete * prior unsignalled WRs. */ -void c4iw_flush_hw_cq (struct c4iw_cq *chp) +void c4iw_flush_hw_cq (struct c4iw_cq *chp,struct c4iw_qp *flush_qhp) {struct t4_cqe *hw_cqe, *swcqe, read_cqe;struct c4iw_qp *qhp;
@@ -355,6 +355,13 @@ void c4iw_flush_hw_cq(struct c4iw_cq *chif (qhp ==NULL ) goto next_cqe; +if (flush_qhp != qhp) { +spin_lock (&qhp->lock); + +if (qhp->wq.flushed ==1 ) + goto next_cqe; + } +if (CQE_OPCODE (hw_cqe) ==FW_RI_TERMINATE ) goto next_cqe;
@@ -406,6 +413,8 @@ void c4iw_flush_hw_cq(struct c4iw_cq *ch next_cqe:t4_hwcq_consume (&chp->cq); ret =t4_next_hw_cqe (&chp->cq, &hw_cqe); +if (qhp && flush_qhp != qhp) +spin_unlock (&qhp->lock); } }
drivers/infiniband/hw/cxgb4/iw_cxgb4.h +1 -1
@@ -977,7 +977,7 @@ void c4iw_pblpool_free(struct c4iw_rdevu32 c4iw_ocqp_pool_alloc (struct c4iw_rdev *rdev,int size);void c4iw_ocqp_pool_free (struct c4iw_rdev *rdev,u32 addr,int size);int c4iw_ofld_send (struct c4iw_rdev *rdev,struct sk_buff *skb); -void c4iw_flush_hw_cq (struct c4iw_cq *chp); +void c4iw_flush_hw_cq (struct c4iw_cq *chp,struct c4iw_qp *flush_qhp);void c4iw_count_rcqes (struct t4_cq *cq,struct t4_wq *wq,int *count);int c4iw_ep_disconnect (struct c4iw_ep *ep,int abrupt,gfp_t gfp);int c4iw_flush_rq (struct t4_wq *wq,struct t4_cq *cq,int count);
drivers/infiniband/hw/cxgb4/qp.c +2 -2
@@ -1082,7 +1082,7 @@ static void __flush_qp(struct c4iw_qp *q } qhp->wq.flushed =1 ; -c4iw_flush_hw_cq (rchp); +c4iw_flush_hw_cq (rchp, qhp);c4iw_count_rcqes (&rchp->cq, &qhp->wq, &count); flushed =c4iw_flush_rq (&qhp->wq, &rchp->cq, count);spin_unlock (&qhp->lock);
@@ -1097,7 +1097,7 @@ static void __flush_qp(struct c4iw_qp *qspin_lock_irqsave (&schp->lock, flag);spin_lock (&qhp->lock);if (schp != rchp) -c4iw_flush_hw_cq (schp); +c4iw_flush_hw_cq (schp, qhp); flushed =c4iw_flush_sq (qhp);spin_unlock (&qhp->lock);spin_unlock_irqrestore (&schp->lock, flag);
PATCH 243/366 net: support compat 64-bit time in {s,g}etsockopt
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Lance Richardson <[email protected]>
commit 988bf7243e03ef69238381594e0334a79cef74a6 upstream.
For the x32 ABI, struct timeval has two 64-bit fields. However the kernel currently interprets the user-space values used for the SO_RCVTIMEO and SO_SNDTIMEO socket options as having a pair of 32-bit fields.
When the seconds portion of the requested timeout is less than 2**32, the seconds portion of the effective timeout is correct but the microseconds portion is zero. When the seconds portion of the requested timeout is zero and the microseconds portion is non-zero, the kernel interprets the timeout as zero (never timeout).
Fix by using 64-bit time for SO_RCVTIMEO/SO_SNDTIMEO as required for the ABI.
The code included below demonstrates the problem.
Results before patch:
$ gcc -m64 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 2.008181 seconds
send time: 2.015985 seconds $ gcc -m32 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 2.016763 seconds
send time: 2.016062 seconds $ gcc -mx32 -Wall -O2 -o socktmo socktmo.c && ./socktmo
recv time: 1.007239 seconds
send time: 1.023890 secondsResults after patch:
$ gcc -m64 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.010062 seconds
send time: 2.015836 seconds $ gcc -m32 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.013974 seconds
send time: 2.015981 seconds $ gcc -mx32 -O2 -Wall -o socktmo socktmo.c && ./socktmo
recv time: 2.030257 seconds
send time: 2.013383 seconds #include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
void checkrc(char *str, int rc)
{
if (rc >= 0)
return;
perror(str);
exit(1);}
static char buf[1024];
int main(int argc, char **argv)
{
int rc;
int socks[2];
struct timeval tv;
struct timeval start, end, delta;
rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socks);
checkrc("socketpair", rc);
/* set timeout to 1.999999 seconds */
tv.tv_sec = 1;
tv.tv_usec = 999999;
rc = setsockopt(socks[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
rc = setsockopt(socks[0], SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv);
checkrc("setsockopt", rc);
/* measure actual receive timeout */
gettimeofday(&start, NULL);
rc = recv(socks[0], buf, sizeof buf, 0);
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("recv time: %ld.%06ld seconds\n",
(long)delta.tv_sec, (long)delta.tv_usec);
/* fill send buffer */
do {
rc = send(socks[0], buf, sizeof buf, 0);
} while (rc > 0);
/* measure actual send timeout */
gettimeofday(&start, NULL);
rc = send(socks[0], buf, sizeof buf, 0);
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("send time: %ld.%06ld seconds\n",
(long)delta.tv_sec, (long)delta.tv_usec);
exit(0);}
--- net/compat.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/compat.c +4 -2
@@ -386,7 +386,8 @@ static int compat_sock_setsockopt(structif (optname ==SO_ATTACH_FILTER )return do_set_attach_filter (sock, level, optname, optval, optlen); -if (optname ==SO_RCVTIMEO || optname ==SO_SNDTIMEO ) +if (!COMPAT_USE_64BIT_TIME && + (optname ==SO_RCVTIMEO || optname ==SO_SNDTIMEO ))return do_set_sock_timeout (sock, level, optname, optval, optlen);return sock_setsockopt (sock, level, optname, optval, optlen);
@@ -451,7 +452,8 @@ static int do_get_sock_timeout(struct sostatic int compat_sock_getsockopt (struct socket *sock,int level,int optname,char __user *optval,int __user *optlen) { -if (optname ==SO_RCVTIMEO || optname ==SO_SNDTIMEO ) +if (!COMPAT_USE_64BIT_TIME && + (optname ==SO_RCVTIMEO || optname ==SO_SNDTIMEO ))return do_get_sock_timeout (sock, level, optname, optval, optlen);return sock_getsockopt (sock, level, optname, optval, optlen); }
PATCH 244/366 ALSA: aloop: Add missing cable lock to ctl API callbacks
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 76b3421b39bd610546931fc923edcf90c18fa395 upstream.
Some control API callbacks in aloop driver are too lazy to take the loopback->cable_lock and it results in possible races of cable access while it's being freed. It eventually lead to a UAF, as reported by fuzzer recently.
This patch covers such control API callbacks and add the proper mutex locks.
--- sound/drivers/aloop.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
sound/drivers/aloop.c +15 -2
@@ -829,9 +829,11 @@ static int loopback_rate_shift_get(struc {struct loopback *loopback =snd_kcontrol_chip (kcontrol); +mutex_lock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].rate_shift; +mutex_unlock (&loopback->cable_lock);return 0 ; }
@@ -863,9 +865,11 @@ static int loopback_notify_get(struct sn {struct loopback *loopback =snd_kcontrol_chip (kcontrol); +mutex_lock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify; +mutex_unlock (&loopback->cable_lock);return 0 ; }
@@ -877,12 +881,14 @@ static int loopback_notify_put(struct snint change =0 ; val = ucontrol->value.integer.value[0 ] ?1 :0 ; +mutex_lock (&loopback->cable_lock);if (val != loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify) { loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify = val; change =1 ; } +mutex_unlock (&loopback->cable_lock);return change; }
@@ -890,13 +896,16 @@ static int loopback_active_get(struct sn struct snd_ctl_elem_value *ucontrol) {struct loopback *loopback =snd_kcontrol_chip (kcontrol); -struct loopback_cable *cable = loopback->cables - [kcontrol->id.subdevice][kcontrol->id.device ^1 ]; +struct loopback_cable *cable; +unsigned int val =0 ; +mutex_lock (&loopback->cable_lock); + cable = loopback->cables[kcontrol->id.subdevice][kcontrol->id.device ^1 ];if (cable !=NULL ) val = (cable->running & (1 <<SNDRV_PCM_STREAM_PLAYBACK )) ?1 :0 ; +mutex_unlock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = val;return 0 ; }
@@ -939,9 +948,11 @@ static int loopback_rate_get(struct snd_ {struct loopback *loopback =snd_kcontrol_chip (kcontrol); +mutex_lock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].rate; +mutex_unlock (&loopback->cable_lock);return 0 ; }
@@ -961,9 +972,11 @@ static int loopback_channels_get(struct {struct loopback *loopback =snd_kcontrol_chip (kcontrol); +mutex_lock (&loopback->cable_lock); ucontrol->value.integer.value[0 ] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].channels; +mutex_unlock (&loopback->cable_lock);return 0 ; }
PATCH 245/366 tracepoint: Do not warn on ENOMEM
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mathieu Desnoyers <[email protected]>
commit d66a270be3310d7aa132fec0cea77d3d32a0ff75 upstream.
Tracepoint should only warn when a kernel API user does not respect the required preconditions (e.g. same tracepoint enabled twice, or called to remove a tracepoint that does not exist).
Silence warning in out-of-memory conditions, given that the error is returned to the caller.
This ensures that out-of-memory error-injection testing does not trigger warnings in tracepoint.c, which were seen by syzbot.
--- kernel/tracepoint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/tracepoint.c +2 -2
@@ -185,7 +185,7 @@ static int tracepoint_add_func(struct tr lockdep_is_held(&tracepoints_mutex)); old =func_add (&tp_funcs, func);if (IS_ERR (old)) { -WARN_ON_ONCE (1 ); +WARN_ON_ONCE (PTR_ERR (old) != -ENOMEM );return PTR_ERR (old); }
@@ -218,7 +218,7 @@ static int tracepoint_remove_func(struct lockdep_is_held(&tracepoints_mutex)); old =func_remove (&tp_funcs, func);if (IS_ERR (old)) { -WARN_ON_ONCE (1 ); +WARN_ON_ONCE (PTR_ERR (old) != -ENOMEM );return PTR_ERR (old); }
PATCH 246/366 usb: musb: host: fix potential NULL pointer dereference
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Bin Liu <[email protected]>
commit 2b63f1329df2cd814c1f8353fae4853ace6521d1 upstream.
musb_start_urb() doesn't check the pass-in parameter if it is NULL. But in musb_bulk_nak_timeout() the parameter passed to musb_start_urb() is returned from first_qh(), which could be NULL.
So wrap the musb_start_urb() call here with a if condition check to avoid the potential NULL pointer dereference.
--- drivers/usb/musb/musb_host.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_host.c +3 -1
@@ -1002,7 +1002,9 @@ static void musb_bulk_nak_timeout(struct/* set tx_reinit and schedule the next qh */ ep->tx_reinit =1 ; } -musb_start_urb (musb, is_in, next_qh); + +if (next_qh) +musb_start_urb (musb, is_in, next_qh); } }
PATCH 247/366 tcp: fix TCP_REPAIR_QUEUE bound checking
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit bf2acc943a45d2b2e8a9f1a5ddff6b6e43cc69d9 upstream.
syzbot is able to produce a nasty WARN_ON() in tcp_verify_left_out() with following C-repro :
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3setsockopt(3, SOL_TCP, TCP_REPAIR, [1], 4) = 0setsockopt(3, SOL_TCP, TCP_REPAIR_QUEUE, [-1], 4) = 0bind(3, {sa_family=AF_INET, sin_port=htons(20002), sin_addr=inet_addr("0.0.0.0")}, 16) = 0 sendto(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
1242, MSG_FASTOPEN, {sa_family=AF_INET, sin_port=htons(20002), sin_addr=inet_addr("127.0.0.1")}, 16) = 1242setsockopt(3, SOL_TCP, TCP_REPAIR_WINDOW, "\4\0\0@+\205\0\0\377\377\0\0\377\377\377\177\0\0\0\0", 20) = 0writev(3, [{"\270", 1}], 1) = 1
setsockopt(3, SOL_TCP, TCP_REPAIR_OPTIONS, "\10\0\0\0\0\0\0\0\0\0\0\0|\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 386) = 0 writev(3, [{"\210v\r[\226\320t\231qwQ\204\264l\254\t\1\20\245\214p\350H\223\254;\\\37\345\307p$"..., 3144}], 1) = 3144
The 3rd system call looks odd :setsockopt(3, SOL_TCP, TCP_REPAIR_QUEUE, [-1], 4) = 0
This patch makes sure bound checking is using an unsigned compare.
--- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -1
@@ -2551,7 +2551,7 @@ static int do_tcp_setsockopt(struct sockcase TCP_REPAIR_QUEUE :if (!tp->repair) err = -EPERM ; -else if (val <TCP_QUEUES_NR ) +else if ((unsigned int )val <TCP_QUEUES_NR ) tp->repair_queue = val;else err = -EINVAL ;
PATCH 248/366 ALSA: pcm: Check PCM state at xfern compat ioctl
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit f13876e2c33a657a71bcbb10f767c0951b165020 upstream.
Since snd_pcm_ioctl_xfern_compat() has no PCM state check, it may go further and hit the sanity check pcm_sanity_check() when the ioctl is called right after open. It may eventually spew a kernel warning, as triggered by syzbot, depending on kconfig.
The lack of PCM state check there was just an oversight. Although it's no real crash, the spurious kernel warning is annoying, so let's add the proper check.
--- sound/core/pcm_compat.c | 2 ++ 1 file changed, 2 insertions(+)
sound/core/pcm_compat.c +2 -0
@@ -334,6 +334,8 @@ static int snd_pcm_ioctl_xfern_compat(streturn -ENOTTY ;if (substream->stream != dir)return -EINVAL ; +if (substream->runtime->status->state ==SNDRV_PCM_STATE_OPEN ) +return -EBADFD ;if ((ch = substream->runtime->channels) >128 )return -EINVAL ;
PATCH 249/366 USB: serial: visor: handle potential invalid device configuration
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 4842ed5bfcb9daf6660537d70503c18d38dbdbb8 upstream.
If we get an invalid device configuration from a palm 3 type device, we might incorrectly parse things, and we have the potential to crash in "interesting" ways.
Fix this up by verifying the size of the configuration passed to us by the device, and only if it is correct, will we handle it.
Note that this also fixes an information leak of slab data.
--- drivers/usb/serial/visor.c | 69 +++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 34 deletions(-)
drivers/usb/serial/visor.c +35 -34
@@ -338,47 +338,48 @@ static int palm_os_3_probe(struct usb_se goto exit; } -if (retval ==sizeof (*connection_info)) { - connection_info = (struct visor_connection_info *) - transfer_buffer; - - num_ports =le16_to_cpu (connection_info->num_ports); -for (i =0 ; i < num_ports; ++i) { -switch ( - connection_info->connections[i].port_function_id) { -case VISOR_FUNCTION_GENERIC : - string ="Generic" ; -break ; -case VISOR_FUNCTION_DEBUGGER : - string ="Debugger" ; -break ; -case VISOR_FUNCTION_HOTSYNC : - string ="HotSync" ; -break ; -case VISOR_FUNCTION_CONSOLE : - string ="Console" ; -break ; -case VISOR_FUNCTION_REMOTE_FILE_SYS : - string ="Remote File System" ; -break ; -default : - string ="unknown" ; -break ; - } -dev_info (dev,"%s: port %d, is for %s use\n" , - serial->type->description, - connection_info->connections[i].port, string); - } +if (retval !=sizeof (*connection_info)) { +dev_err (dev,"Invalid connection information received from device\n" ); + retval = -ENODEV ; + goto exit; } -/* -* Handle devices that report invalid stuff here. -*/ + + connection_info = (struct visor_connection_info *)transfer_buffer; + + num_ports =le16_to_cpu (connection_info->num_ports); + +/* Handle devices that report invalid stuff here. */ if (num_ports ==0 || num_ports >2 ) {dev_warn (dev,"%s: No valid connect info available\n" , serial->type->description); num_ports =2 ; } +for (i =0 ; i < num_ports; ++i) { +switch (connection_info->connections[i].port_function_id) { +case VISOR_FUNCTION_GENERIC : + string ="Generic" ; +break ; +case VISOR_FUNCTION_DEBUGGER : + string ="Debugger" ; +break ; +case VISOR_FUNCTION_HOTSYNC : + string ="HotSync" ; +break ; +case VISOR_FUNCTION_CONSOLE : + string ="Console" ; +break ; +case VISOR_FUNCTION_REMOTE_FILE_SYS : + string ="Remote File System" ; +break ; +default : + string ="unknown" ; +break ; + } +dev_info (dev,"%s: port %d, is for %s use\n" , + serial->type->description, + connection_info->connections[i].port, string); + }dev_info (dev,"%s: Number of ports: %d\n" , serial->type->description, num_ports);
PATCH 250/366 clocksource: Initialize cs->wd_list
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 5b9e886a4af97574ca3ce1147f35545da0e7afc7 upstream.
A number of places relies on list_empty(&cs->wd_list), however the list_head does not get initialized. Do so upon registration, such that thereafter it is possible to rely on list_empty() correctly reflecting the list membership status.
--- kernel/time/clocksource.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/time/clocksource.c +2 -0
@@ -385,6 +385,8 @@ static void clocksource_enqueue_watchdog {unsigned long flags; +INIT_LIST_HEAD (&cs->wd_list); +spin_lock_irqsave (&watchdog_lock, flags);if (cs->flags &CLOCK_SOURCE_MUST_VERIFY ) {/* cs is a clocksource to be watched. */
PATCH 251/366 sctp: fix the issue that the cookie-ack with auth can't get processed
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
commit ce402f044e4e432c296f90eaabb8dbe8f3624391 upstream.
When auth is enabled for cookie-ack chunk, in sctp_inq_pop, sctp processes auth chunk first, then continues to the next chunk in this packet if chunk_end + chunk_hdr size < skb_tail_pointer(). Otherwise, it will go to the next packet or discard this chunk.
However, it missed the fact that cookie-ack chunk's size is equal to chunk_hdr size, which couldn't match that check, and thus this chunk would not get processed.
This patch fixes it by changing the check to chunk_end + chunk_hdr size <= skb_tail_pointer().
--- net/sctp/inqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/inqueue.c +1 -1
@@ -178,7 +178,7 @@ struct sctp_chunk *sctp_inq_pop(struct sskb_pull (chunk->skb,sizeof (sctp_chunkhdr_t)); chunk->subh.v =NULL ;/* Subheader is no longer valid. */ -if (chunk->chunk_end +sizeof (sctp_chunkhdr_t) < +if (chunk->chunk_end +sizeof (sctp_chunkhdr_t) <=skb_tail_pointer (chunk->skb)) {/* This is not a singleton */ chunk->singleton =0 ;
PATCH 252/366 bpf, x64: fix memleak when not converging after image
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
commit 3aab8884c9eb99189a3569ac4e6b205371c9ac0b upstream.
While reviewing x64 JIT code, I noticed that we leak the prior allocated JIT image in the case where proglen != oldproglen during the JIT passes. Prior to the commit e0ee9c12157d ("x86: bpf_jit: fix two bugs in eBPF JIT compiler") we would just break out of the loop, and using the image as the JITed prog since it could only shrink in size anyway. After e0ee9c12157d, we would bail out to out_addrs label where we free addrs and jit_data but not the image coming from bpf_jit_binary_alloc().
--- arch/x86/net/bpf_jit_comp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp.c +2 -1
@@ -914,6 +914,7 @@ void bpf_int_jit_compile(struct sk_filtefor (pass =0 ; pass <10 || image; pass++) { proglen =do_jit (prog, addrs, image, oldproglen, &ctx);if (proglen <=0 ) { +out_image: image =NULL ;if (header)module_free (NULL , header);
@@ -923,7 +924,7 @@ void bpf_int_jit_compile(struct sk_filteif (proglen != oldproglen) {pr_err ("bpf_jit: proglen=%d != oldproglen=%d\n" , proglen, oldproglen); - goto out; + goto out_image; }break ; }
PATCH 253/366 net_sched: fq: take care of throttled flows before reuse
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 7df40c2673a1307c3260aab6f9d4b9bf97ca8fd7 upstream.
Normally, a socket can not be freed/reused unless all its TX packets left qdisc and were TX-completed. However connect(AF_UNSPEC) allows this to happen.
With commit fc59d5bdf1e3 ("pkt_sched: fq: clear time_next_packet for reused flows") we cleared f->time_next_packet but took no special action if the flow was still in the throttled rb-tree.
Since f->time_next_packet is the key used in the rb-tree searches, blindly clearing it might break rb-tree integrity. We need to make sure the flow is no longer in the rb-tree to avoid this problem.
--- net/sched/sch_fq.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
net/sched/sch_fq.c +25 -12
@@ -124,6 +124,28 @@ static bool fq_flow_is_detached(const streturn f->next == &detached; } +static bool fq_flow_is_throttled (const struct fq_flow *f) +{ +return f->next == &throttled; +} + +static void fq_flow_add_tail (struct fq_flow_head *head,struct fq_flow *flow) +{ +if (head->first) + head->last->next = flow; +else + head->first = flow; + head->last = flow; + flow->next =NULL ; +} + +static void fq_flow_unset_throttled (struct fq_sched_data *q,struct fq_flow *f) +{ +rb_erase (&f->rate_node, &q->delayed); + q->throttled_flows--; +fq_flow_add_tail (&q->old_flows, f); +} +static void fq_flow_set_throttled (struct fq_sched_data *q,struct fq_flow *f) {struct rb_node **p = &q->delayed.rb_node, *parent =NULL ;
@@ -151,15 +173,6 @@ static void fq_flow_set_throttled(structstatic struct kmem_cache *fq_flow_cachep__read_mostly ; -static void fq_flow_add_tail (struct fq_flow_head *head,struct fq_flow *flow) -{ -if (head->first) - head->last->next = flow; -else - head->first = flow; - head->last = flow; - flow->next =NULL ; -}/* limit number of collected flows per round */ #define FQ_GC_MAX 8
@@ -251,6 +264,8 @@ static struct fq_flow *fq_classify(struc f->socket_hash != sk->sk_hash)) { f->credit = q->initial_quantum; f->socket_hash = sk->sk_hash; +if (fq_flow_is_throttled (f)) +fq_flow_unset_throttled (q, f); f->time_next_packet =0ULL ; }return f;
@@ -407,9 +422,7 @@ static void fq_check_throttled(struct fq q->time_next_delayed_flow = f->time_next_packet;break ; } -rb_erase (p, &q->delayed); - q->throttled_flows--; -fq_flow_add_tail (&q->old_flows, f); +fq_flow_unset_throttled (q, f); } }
PATCH 254/366 ipv4: fix fnhe usage by non-cached routes
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
commit 94720e3aee6884d8c8beb678001629da60ec6366 upstream.
Allow some non-cached routes to use non-expired fnhe:
1. ip_del_fnhe: moved above and now called by find_exception. The 4.5+ commit deed49df7390 expires fnhe only when caching routes. Change that to:
1.1. use fnhe for non-cached local output routes, with the help from (2)
1.2. allow __mkroute_input to detect expired fnhe (outdated fnhe_gw, for example) when do_cache is false, eg. when itag!=0 for unicast destinations.
2. __mkroute_output: keep fi to allow local routes with orig_oif != 0 to use fnhe info even when the new route will not be cached into fnhe. After commit 839da4d98960 ("net: ipv4: set orig_oif based on fib result for local traffic") it means all local routes will be affected because they are not cached. This change is used to solve a PMTU problem with IPVS (and probably Netfilter DNAT) setups that redirect local clients from target local IP (local route to Virtual IP) to new remote IP target, eg. IPVS TUN real server. Loopback has 64K MTU and we need to create fnhe on the local route that will keep the reduced PMTU for the Virtual IP. Without this change fnhe_pmtu is updated from ICMP but never exposed to non-cached local routes. This includes routes with flowi4_oif!=0 for 4.6+ and with flowi4_oif=any for 4.14+).
3. update_or_create_fnhe: make sure fnhe_expires is not 0 for new entries
--- net/ipv4/route.c | 118 +++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 65 deletions(-)
net/ipv4/route.c +53 -65
@@ -684,7 +684,7 @@ static void update_or_create_fnhe(struct fnhe->fnhe_gw = gw; fnhe->fnhe_pmtu = pmtu; fnhe->fnhe_mtu_locked = lock; - fnhe->fnhe_expires = expires; + fnhe->fnhe_expires =max (1UL , expires);/* Exception created; mark the cached routes for the nexthop * stale, so anyone caching it rechecks if this exception
@@ -1259,6 +1259,36 @@ static unsigned int ipv4_mtu(const struc return min_t(unsigned int, mtu, IP_MAX_MTU); } +static void ip_del_fnhe (struct fib_nh *nh,__be32 daddr) +{ +struct fnhe_hash_bucket *hash; +struct fib_nh_exception *fnhe,__rcu **fnhe_p; +u32 hval =fnhe_hashfun (daddr); + +spin_lock_bh (&fnhe_lock); + + hash =rcu_dereference_protected (nh->nh_exceptions, +lockdep_is_held (&fnhe_lock)); + hash += hval; + + fnhe_p = &hash->chain; + fnhe =rcu_dereference_protected (*fnhe_p,lockdep_is_held (&fnhe_lock)); +while (fnhe) { +if (fnhe->fnhe_daddr == daddr) { +rcu_assign_pointer (*fnhe_p,rcu_dereference_protected ( + fnhe->fnhe_next,lockdep_is_held (&fnhe_lock))); +fnhe_flush_routes (fnhe); +kfree_rcu (fnhe, rcu); +break ; + } + fnhe_p = &fnhe->fnhe_next; + fnhe =rcu_dereference_protected (fnhe->fnhe_next, +lockdep_is_held (&fnhe_lock)); + } + +spin_unlock_bh (&fnhe_lock); +} +static struct fib_nh_exception *find_exception (struct fib_nh *nh,__be32 daddr) {struct fnhe_hash_bucket *hash = nh->nh_exceptions;
@@ -1272,8 +1302,14 @@ static struct fib_nh_exception *find_excfor (fnhe =rcu_dereference (hash[hval].chain); fnhe; fnhe =rcu_dereference (fnhe->fnhe_next)) { -if (fnhe->fnhe_daddr == daddr) +if (fnhe->fnhe_daddr == daddr) { +if (fnhe->fnhe_expires && +time_after (jiffies, fnhe->fnhe_expires)) { +ip_del_fnhe (nh, daddr); +break ; + }return fnhe; + } }return NULL ; }
@@ -1568,36 +1604,6 @@ static void ip_handle_martian_source(str#endif } -static void ip_del_fnhe (struct fib_nh *nh,__be32 daddr) -{ -struct fnhe_hash_bucket *hash; -struct fib_nh_exception *fnhe,__rcu **fnhe_p; -u32 hval =fnhe_hashfun (daddr); - -spin_lock_bh (&fnhe_lock); - - hash =rcu_dereference_protected (nh->nh_exceptions, -lockdep_is_held (&fnhe_lock)); - hash += hval; - - fnhe_p = &hash->chain; - fnhe =rcu_dereference_protected (*fnhe_p,lockdep_is_held (&fnhe_lock)); -while (fnhe) { -if (fnhe->fnhe_daddr == daddr) { -rcu_assign_pointer (*fnhe_p,rcu_dereference_protected ( - fnhe->fnhe_next,lockdep_is_held (&fnhe_lock))); -fnhe_flush_routes (fnhe); -kfree_rcu (fnhe, rcu); -break ; - } - fnhe_p = &fnhe->fnhe_next; - fnhe =rcu_dereference_protected (fnhe->fnhe_next, -lockdep_is_held (&fnhe_lock)); - } - -spin_unlock_bh (&fnhe_lock); -} -/* called in rcu_read_lock() section */ static int __mkroute_input(struct sk_buff *skb, const struct fib_result *res,
@@ -1651,20 +1657,10 @@ static int __mkroute_input(struct sk_buf fnhe =find_exception (&FIB_RES_NH (*res), daddr);if (do_cache) { -if (fnhe) { +if (fnhe) rth =rcu_dereference (fnhe->fnhe_rth_input); -if (rth && rth->dst.expires && -time_after (jiffies, rth->dst.expires)) { -ip_del_fnhe (&FIB_RES_NH (*res), daddr); - fnhe =NULL ; - }else { - goto rt_cache; - } - } - - rth =rcu_dereference (FIB_RES_NH (*res).nh_rth_input); - -rt_cache: +else + rth =rcu_dereference (FIB_RES_NH (*res).nh_rth_input);if (rt_cache_valid (rth)) {skb_dst_set_noref (skb, &rth->dst); goto out;
@@ -2000,39 +1996,31 @@ static struct rtable *__mkroute_output(c* the loopback interface and the IP_PKTINFO ipi_ifindex will * be set to the loopback interface as well. */ - fi =NULL ; + do_cache = false; } fnhe =NULL ; do_cache &= fi !=NULL ; -if (do_cache) { +if (fi) {struct rtable __rcu **prth;struct fib_nh *nh = &FIB_RES_NH (*res); fnhe =find_exception (nh, fl4->daddr); +if (!do_cache) + goto add;if (fnhe) { prth = &fnhe->fnhe_rth_output; - rth =rcu_dereference (*prth); -if (rth && rth->dst.expires && -time_after (jiffies, rth->dst.expires)) { -ip_del_fnhe (nh, fl4->daddr); - fnhe =NULL ; - }else { - goto rt_cache; + }else { +if (unlikely (fl4->flowi4_flags & +FLOWI_FLAG_KNOWN_NH && + !(nh->nh_gw && + nh->nh_scope ==RT_SCOPE_LINK ))) { + do_cache = false; + goto add; } + prth =raw_cpu_ptr (nh->nh_pcpu_rth_output); } - -if (unlikely (fl4->flowi4_flags & -FLOWI_FLAG_KNOWN_NH && - !(nh->nh_gw && - nh->nh_scope ==RT_SCOPE_LINK ))) { - do_cache = false; - goto add; - } - prth =raw_cpu_ptr (nh->nh_pcpu_rth_output); rth =rcu_dereference (*prth); - -rt_cache:if (rt_cache_valid (rth)) {dst_hold (&rth->dst);return rth;
PATCH 255/366 qmi_wwan: do not steal interfaces from class drivers
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Bjørn Mork <[email protected]>
commit 5697db4a696c41601a1d15c1922150b4dbf5726c upstream.
The USB_DEVICE_INTERFACE_NUMBER matching macro assumes that the { vendorid, productid, interfacenumber } set uniquely identifies one specific function. This has proven to fail for some configurable devices. One example is the Quectel EM06/EP06 where the same interface number can be either QMI or MBIM, without the device ID changing either.
Fix by requiring the vendor-specific class for interface number based matching. Functions of other classes can and should use class based matching instead.
--- drivers/net/usb/qmi_wwan.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/usb/qmi_wwan.c +12 -0
@@ -899,6 +899,18 @@ static int qmi_wwan_probe(struct usb_int id->driver_info = (unsigned long )&qmi_wwan_info; } +/* There are devices where the same interface number can be +* configured as different functions. We should only bind to +* vendor specific functions when matching on interface number +*/ +if (id->match_flags &USB_DEVICE_ID_MATCH_INT_NUMBER && + desc->bInterfaceClass !=USB_CLASS_VENDOR_SPEC ) { +dev_dbg (&intf->dev, +"Rejecting interface number match for class %02x\n" , + desc->bInterfaceClass); +return -ENODEV ; + } +/* Quectel EC20 quirk where we've QMI on interface 4 instead of 0 */ if (quectel_ec20_detected (intf) && desc->bInterfaceNumber ==0 ) {dev_dbg (&intf->dev,"Quectel EC20 quirk, skipping interface 0\n" );
PATCH 256/366 USB: Accept bulk endpoints with 1024-byte maxpacket
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Alan Stern <[email protected]>
commit fb5ee84ea72c5f1b6cabdd1c9d6e8648995ca7c6 upstream.
Some non-compliant high-speed USB devices have bulk endpoints with a 1024-byte maxpacket size. Although such endpoints don't work with xHCI host controllers, they do work with EHCI controllers. We used to accept these invalid sizes (with a warning), but we no longer do because of an unintentional change introduced by commit aed9d65ac327 ("USB: validate wMaxPacketValue entries in endpoint descriptors").
This patch restores the old behavior, so that people with these peculiar devices can use them without patching their kernels by hand.
--- drivers/usb/core/config.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/core/config.c +3 -1
@@ -157,7 +157,9 @@ static const unsigned short full_speed_mstatic const unsigned short high_speed_maxpacket_maxes[4 ] = { [USB_ENDPOINT_XFER_CONTROL ] =64 , [USB_ENDPOINT_XFER_ISOC ] =1024 , - [USB_ENDPOINT_XFER_BULK ] =512 , + +/* Bulk should be 512, but some devices use 1024: we will warn below */ + [USB_ENDPOINT_XFER_BULK ] =1024 , [USB_ENDPOINT_XFER_INT ] =1024 , };static const unsigned short super_speed_maxpacket_maxes[4 ] = {
PATCH 257/366 dccp: fix tasklet usage
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit a8d7aa17bbc970971ccdf71988ea19230ab368b1 upstream.
syzbot reported a crash in tasklet_action_common() caused by dccp.
dccp needs to make sure socket wont disappear before tasklet handler has completed.
This patch takes a reference on the socket when arming the tasklet, and moves the sock_put() from dccp_write_xmit_timer() to dccp_write_xmitlet()
kernel BUG at kernel/softirq.c:514!
invalid opcode: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in: CPU: 1 PID: 17 Comm: ksoftirqd/1 Not tainted 4.17.0-rc3+ #30 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:tasklet_action_common.isra.19+0x6db/0x700 kernel/softirq.c:515 RSP: 0018:ffff8801d9b3faf8 EFLAGS: 00010246 dccp_close: ABORT with 65423 bytes unread RAX: 1ffff1003b367f6b RBX: ffff8801daf1f3f0 RCX: 0000000000000000 RDX: ffff8801cf895498 RSI: 0000000000000004 RDI: 0000000000000000 RBP: ffff8801d9b3fc40 R08: ffffed0039f12a95 R09: ffffed0039f12a94 dccp_close: ABORT with 65423 bytes unread R10: ffffed0039f12a94 R11: ffff8801cf8954a3 R12: 0000000000000000 R13: ffff8801d9b3fc18 R14: dffffc0000000000 R15: ffff8801cf895490 FS: 0000000000000000(0000) GS:ffff8801daf00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b2bc28000 CR3: 00000001a08a9000 CR4: 00000000001406e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: tasklet_action+0x1d/0x20 kernel/softirq.c:533 __do_softirq+0x2e0/0xaf5 kernel/softirq.c:285 dccp_close: ABORT with 65423 bytes unread run_ksoftirqd+0x86/0x100 kernel/softirq.c:646 smpboot_thread_fn+0x417/0x870 kernel/smpboot.c:164 kthread+0x345/0x410 kernel/kthread.c:238 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412 Code: 48 8b 85 e8 fe ff ff 48 8b 95 f0 fe ff ff e9 94 fb ff ff 48 89 95 f0 fe ff ff e8 81 53 6e 00 48 8b 95 f0 fe ff ff e9 62 fb ff ff <0f> 0b 48 89 cf 48 89 8d e8 fe ff ff e8 64 53 6e 00 48 8b 8d e8 RIP: tasklet_action_common.isra.19+0x6db/0x700 kernel/softirq.c:515 RSP: ffff8801d9b3faf8
--- net/dccp/ccids/ccid2.c | 14 ++++++++++++-- net/dccp/timer.c | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-)
net/dccp/ccids/ccid2.c +12 -2
@@ -126,6 +126,16 @@ static void ccid2_change_l_seq_window(st DCCPF_SEQ_WMAX)); } +static void dccp_tasklet_schedule (struct sock *sk) +{ +struct tasklet_struct *t = &dccp_sk (sk)->dccps_xmitlet; + +if (!test_and_set_bit (TASKLET_STATE_SCHED , &t->state)) { +sock_hold (sk); +__tasklet_schedule (t); + } +} +static void ccid2_hc_tx_rto_expire (unsigned long data) {struct sock *sk = (struct sock *)data;
@@ -166,7 +176,7 @@ static void ccid2_hc_tx_rto_expire(unsig/* if we were blocked before, we may now send cwnd=1 packet */ if (sender_was_blocked) -tasklet_schedule (&dccp_sk (sk)->dccps_xmitlet); +dccp_tasklet_schedule (sk);/* restart backed-off timer */ sk_reset_timer (sk, &hc->tx_rtotimer, jiffies + hc->tx_rto); out:
@@ -706,7 +716,7 @@ static void ccid2_hc_tx_packet_recv(stru done:/* check if incoming Acks allow pending packets to be sent */ if (sender_was_blocked && !ccid2_cwnd_network_limited (hc)) -tasklet_schedule (&dccp_sk (sk)->dccps_xmitlet); +dccp_tasklet_schedule (sk);dccp_ackvec_parsed_cleanup (&hc->tx_av_chunks); }
net/dccp/timer.c +1 -1
@@ -252,12 +252,12 @@ static void dccp_write_xmitlet(unsignedelse dccp_write_xmit (sk);bh_unlock_sock (sk); +sock_put (sk); }static void dccp_write_xmit_timer (unsigned long data) {dccp_write_xmitlet (data); -sock_put ((struct sock *)data); }void dccp_init_xmit_timers (struct sock *sk)
PATCH 258/366 bdi: Fix oops in wb_workfn()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit b8b784958eccbf8f51ebeee65282ca3fd59ea391 upstream.
Syzbot has reported that it can hit a NULL pointer dereference in wb_workfn() due to wb->bdi->dev being NULL. This indicates that wb_workfn() was called for an already unregistered bdi which should not happen as wb_shutdown() called from bdi_unregister() should make sure all pending writeback works are completed before bdi is unregistered. Except that wb_workfn() itself can requeue the work with:
mod_delayed_work(bdi_wq, &wb->dwork, 0);
and if this happens while wb_shutdown() is waiting in:
flush_delayed_work(&wb->dwork);
the dwork can get executed after wb_shutdown() has finished and bdi_unregister() has cleared wb->bdi->dev.
Make wb_workfn() use wakeup_wb() for requeueing the work which takes all the necessary precautions against racing with bdi unregistration.
[bwh: Backported to 3.16:
- Use bdi_wakeup_thread() instead of wb_wakeup()
- Adjust context]
--- fs/fs-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fs-writeback.c +1 -1
@@ -1071,7 +1071,7 @@ void bdi_writeback_workfn(struct work_st }if (!list_empty (&bdi->work_list)) -mod_delayed_work (bdi_wq, &wb->dwork,0 ); +bdi_wakeup_thread (bdi);else if (wb_has_dirty_io (wb) && dirty_writeback_interval)bdi_wakeup_thread_delayed (bdi);
PATCH 259/366 atm: zatm: Fix potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Gustavo A. R. Silva" <[email protected]>
commit 2be147f7459db5bbf292e0a6f135037b55e20b39 upstream.
pool can be indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability.
This issue was detected with the help of Smatch:
drivers/atm/zatm.c:1462 zatm_ioctl() warn: potential spectre issue 'zatm_dev->pool_info' (local cap)
Fix this by sanitizing pool before using it to index zatm_dev->pool_info
Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1].
[1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2
--- drivers/atm/zatm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/atm/zatm.c +3 -0
@@ -28,6 +28,7 @@#include <asm/io.h> #include <linux/atomic.h> #include <asm/uaccess.h> +#include <linux/nospec.h> #include "uPD98401.h" #include "uPD98402.h"
@@ -1455,6 +1456,8 @@ static int zatm_ioctl(struct atm_dev *dereturn -EFAULT ;if (pool <0 || pool >ZATM_LAST_POOL )return -EINVAL ; + pool =array_index_nospec (pool, +ZATM_LAST_POOL +1 );spin_lock_irqsave (&zatm_dev->lock, flags); info = zatm_dev->pool_info[pool];if (cmd ==ZATM_GETPOOLZ ) {
PATCH 260/366 net: atm: Fix potential Spectre v1
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Gustavo A. R. Silva" <[email protected]>
commit acf784bd0ce257fe43da7ca266f7a10b837479d2 upstream.
ioc_data.dev_num can be controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability.
This issue was detected with the help of Smatch:net/atm/lec.c:702 lec_vcc_attach() warn: potential spectre issue 'dev_lec'
Fix this by sanitizing ioc_data.dev_num before using it to index dev_lec. Also, notice that there is another instance in which array dev_lec is being indexed using ioc_data.dev_num at line 705:
lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1].
[1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2
--- net/atm/lec.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/atm/lec.c +7 -2
@@ -41,6 +41,9 @@ static unsigned char bridge_ula_lec[] =#include <linux/module.h> #include <linux/init.h> +/* Hardening for Spectre-v1 */ +#include <linux/nospec.h> +#include "lec.h" #include "lec_arpc.h" #include "resources.h"
@@ -695,8 +698,10 @@ static int lec_vcc_attach(struct atm_vcc bytes_left =copy_from_user (&ioc_data, arg,sizeof (struct atmlec_ioc ));if (bytes_left !=0 )pr_info ("copy from user failed for %d bytes\n" , bytes_left); -if (ioc_data.dev_num <0 || ioc_data.dev_num >=MAX_LEC_ITF || - !dev_lec[ioc_data.dev_num]) +if (ioc_data.dev_num <0 || ioc_data.dev_num >=MAX_LEC_ITF ) +return -EINVAL ; + ioc_data.dev_num =array_index_nospec (ioc_data.dev_num,MAX_LEC_ITF ); +if (!dev_lec[ioc_data.dev_num])return -EINVAL ; vpriv =kmalloc (sizeof (struct lec_vcc_priv ),GFP_KERNEL );if (!vpriv)
PATCH 261/366 sched/core: Fix possible Spectre-v1 indexing for sched_prio_to_weight[]
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 7281c8dec8a87685cb54d503d8cceef5a0fc2fdd upstream.
Quoted 1 line
kernel/sched/core.c:6921cpu_weight_nice_write_s64()warn: potential spectre issue 'sched_prio_to_weight'
Userspace controls @nice, so sanitize the value before using it to index an array.
---
kernel/sched/core.c +3 -0
@@ -74,6 +74,7 @@#include <linux/binfmts.h> #include <linux/context_tracking.h> #include <linux/compiler.h> +#include <linux/nospec.h> #include <asm/switch_to.h> #include <asm/tlb.h>
@@ -820,6 +821,8 @@ static void set_load_weight(struct task_return ; } + prio =array_index_nospec (prio,40 ); + load->weight =scale_load (prio_to_weight[prio]); load->inv_weight = prio_to_wmult[prio]; }
PATCH 262/366 sched/autogroup: Fix 64-bit kernel nice level adjustment
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Mike Galbraith <[email protected]>
commit 83929cce95251cc77e5659bf493bd424ae0e7a67 upstream.
Michael Kerrisk reported:
Quoted 3 lines
Regarding the previous paragraph... My tests indicate that writing *any* value to the autogroup [nice priority level] file causes the task group to get a lower priority.
Because autogroup didn't call the then meaningless scale_load()...
Autogroup nice level adjustment has been broken ever since load resolution was increased for 64-bit kernels. Use scale_load() to scale group weight.
Michael Kerrisk tested this patch to fix the problem:
Quoted 7 lines
Applied and tested against 4.9-rc6 on an Intel u7 (4 cores). Test setup:
Terminal window 1: running 40 CPU burner jobs
Terminal window 2: running 40 CPU burner jobs
Terminal window 1: running 1 CPU burner job
Quoted 8 lines
Demonstrated that:
* Writing "0" to the autogroup file for TW1 now causes no change to the rate at which the process on the terminal consume CPU.
* Writing -20 to the autogroup file for TW1 caused those processes to get the lion's share of CPU while TW2 TW3 get a tiny amount.
* Writing -20 to the autogroup files for TW1 and TW3 allowed the process on TW3 to get as much CPU as it was getting as when the autogroup nice values for both terminals were 0.
--- kernel/sched/auto_group.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/auto_group.c +3 -1
@@ -197,6 +197,7 @@ int proc_sched_autogroup_set_nice(struct {static unsigned long next =INITIAL_JIFFIES ;struct autogroup *ag; +unsigned long shares;int err;if (nice <MIN_NICE || nice >MAX_NICE )
@@ -215,9 +216,10 @@ int proc_sched_autogroup_set_nice(struct next =HZ /10 + jiffies; ag =autogroup_task_get (p); + shares =scale_load (prio_to_weight[nice +20 ]);down_write (&ag->lock); - err =sched_group_set_shares (ag->tg, prio_to_weight[nice +20 ]); + err =sched_group_set_shares (ag->tg, shares);if (!err) ag->nice = nice;up_write (&ag->lock);
PATCH 263/366 sched/autogroup: Fix possible Spectre-v1 indexing for sched_prio_to_weight[]
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 354d7793070611b4df5a79fbb0f12752d0ed0cc5 upstream.
Quoted 1 line
kernel/sched/autogroup.c:230proc_sched_autogroup_set_nice()warn: potential spectre issue 'sched_prio_to_weight'
Userspace controls @nice, sanitize the array index.
--- kernel/sched/auto_group.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/sched/auto_group.c +5 -2
@@ -8,6 +8,7 @@#include <linux/utsname.h> #include <linux/security.h> #include <linux/export.h> +#include <linux/nospec.h> unsigned int __read_mostly sysctl_sched_autogroup_enabled =1 ;static struct autogroup autogroup_default;
@@ -198,7 +199,7 @@ int proc_sched_autogroup_set_nice(structstatic unsigned long next =INITIAL_JIFFIES ;struct autogroup *ag;unsigned long shares; -int err; +int err, idx;if (nice <MIN_NICE || nice >MAX_NICE )return -EINVAL ;
@@ -216,7 +217,9 @@ int proc_sched_autogroup_set_nice(struct next =HZ /10 + jiffies; ag =autogroup_task_get (p); - shares =scale_load (prio_to_weight[nice +20 ]); + + idx =array_index_nospec (nice +20 ,40 ); + shares =scale_load (prio_to_weight[idx]);down_write (&ag->lock); err =sched_group_set_shares (ag->tg, shares);
PATCH 264/366 perf/x86: Fix possible Spectre-v1 indexing for x86_pmu::event_map()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 46b1b577229a091b137831becaa0fae8690ee15a upstream.
Quoted 6 lines
arch/x86/events/intel/cstate.c:307cstate_pmu_event_init()warn: potential spectre issue 'pkg_msr' (local cap)arch/x86/events/intel/core.c:337intel_pmu_event_map()warn: potential spectre issue 'intel_perfmon_event_map'arch/x86/events/intel/knc.c:122knc_pmu_event_map()warn: potential spectre issue 'knc_perfmon_event_map'arch/x86/events/intel/p4.c:722p4_pmu_event_map()warn: potential spectre issue 'p4_general_events'arch/x86/events/intel/p6.c:116p6_pmu_event_map()warn: potential spectre issue 'p6_perfmon_event_map'arch/x86/events/amd/core.c:132amd_pmu_event_map()warn: potential spectre issue 'amd_perfmon_event_map'
Userspace controls @attr, sanitize @attr->config before passing it on to x86_pmu::event_map().
--- arch/x86/kernel/cpu/perf_event.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kernel/cpu/perf_event.c +3 -0
@@ -25,6 +25,7 @@#include <linux/cpu.h> #include <linux/bitops.h> #include <linux/device.h> +#include <linux/nospec.h> #include <asm/apic.h> #include <asm/stacktrace.h>
@@ -319,6 +320,8 @@ int x86_setup_perfctr(struct perf_eventif (attr->config >= x86_pmu.max_events)return -EINVAL ; + attr->config =array_index_nospec ((unsigned long )attr->config, x86_pmu.max_events); +/* * The generic map: */
PATCH 265/366 perf/x86: Fix possible Spectre-v1 indexing for hw_perf_event cache_*
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit ef9ee4ad38445a30909c48998624861716f2a994 upstream.
Quoted 4 lines
arch/x86/events/core.c:319set_ext_hw_attr()warn: potential spectre issue 'hw_cache_event_ids[cache_type]' (local cap)arch/x86/events/core.c:319set_ext_hw_attr()warn: potential spectre issue 'hw_cache_event_ids' (local cap)arch/x86/events/core.c:328set_ext_hw_attr()warn: potential spectre issue 'hw_cache_extra_regs[cache_type]' (local cap)arch/x86/events/core.c:328set_ext_hw_attr()warn: potential spectre issue 'hw_cache_extra_regs' (local cap)
Userspace controls @config which contains 3 (byte) fields used for a 3 dimensional array deref.
--- arch/x86/kernel/cpu/perf_event.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event.c +4 -1
@@ -274,17 +274,20 @@ set_ext_hw_attr(struct hw_perf_event *hw config = attr->config; - cache_type = (config >>0 ) &0xff ; + cache_type = (config >>0 ) &0xff ;if (cache_type >=PERF_COUNT_HW_CACHE_MAX )return -EINVAL ; + cache_type =array_index_nospec (cache_type,PERF_COUNT_HW_CACHE_MAX ); cache_op = (config >>8 ) &0xff ;if (cache_op >=PERF_COUNT_HW_CACHE_OP_MAX )return -EINVAL ; + cache_op =array_index_nospec (cache_op,PERF_COUNT_HW_CACHE_OP_MAX ); cache_result = (config >>16 ) &0xff ;if (cache_result >=PERF_COUNT_HW_CACHE_RESULT_MAX )return -EINVAL ; + cache_result =array_index_nospec (cache_result,PERF_COUNT_HW_CACHE_RESULT_MAX ); val = hw_cache_event_ids[cache_type][cache_op][cache_result];
PATCH 266/366 rfkill: gpio: fix memory leak in probe error path
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 4bf01ca21e2e0e4561d1a03c48c3d740418702db upstream.
Make sure to free the rfkill device in case registration fails during probe.
--- net/rfkill/rfkill-gpio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/rfkill/rfkill-gpio.c +6 -1
@@ -134,13 +134,18 @@ static int rfkill_gpio_probe(struct plat ret =rfkill_register (rfkill->rfkill_dev);if (ret <0 ) -return ret; + goto err_destroy;platform_set_drvdata (pdev, rfkill);dev_info (&pdev->dev,"%s device registered.\n" , rfkill->name);return 0 ; + +err_destroy: +rfkill_destroy (rfkill->rfkill_dev); + +return ret; }static int rfkill_gpio_remove (struct platform_device *pdev)
PATCH 267/366 scsi: zfcp: fix infinite iteration on ERP ready list
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jens Remus <[email protected]>
commit fa89adba1941e4f3b213399b81732a5c12fd9131 upstream.
zfcp_erp_adapter_reopen() schedules blocking of all of the adapter's rports via zfcp_scsi_schedule_rports_block() and enqueues a reopen adapter ERP action via zfcp_erp_action_enqueue(). Both are separately processed asynchronously and concurrently.
Blocking of rports is done in a kworker by zfcp_scsi_rport_work(). It calls zfcp_scsi_rport_block(), which then traces a DBF REC "scpdely" via zfcp_dbf_rec_trig(). zfcp_dbf_rec_trig() acquires the DBF REC spin lock and then iterates with list_for_each() over the adapter's ERP ready list without holding the ERP lock. This opens a race window in which the current list entry can be moved to another list, causing list_for_each() to iterate forever on the wrong list, as the erp_ready_head is never encountered as terminal condition.
Meanwhile the ERP action can be processed in the ERP thread by zfcp_erp_thread(). It calls zfcp_erp_strategy(), which acquires the ERP lock and then calls zfcp_erp_action_to_running() to move the ERP action from the ready to the running list. zfcp_erp_action_to_running() can move the ERP action using list_move() just during the aforementioned race window. It then traces a REC RUN "erator1" via zfcp_dbf_rec_run(). zfcp_dbf_rec_run() tries to acquire the DBF REC spin lock. If this is held by the infinitely looping kworker, it effectively spins forever.
Example Sequence Diagram:
Process ERP Thread rport_work ------------------- ------------------- -------------------
zfcp_erp_adapter_reopen() zfcp_erp_adapter_block() zfcp_scsi_schedule_rports_block()
lock ERP zfcp_scsi_rport_work()zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER)
list_add_tail() on ready !(rport_task==RPORT_ADD) wake_up() ERP thread zfcp_scsi_rport_block() zfcp_dbf_rec_trig() zfcp_erp_strategy() zfcp_dbf_rec_trig() unlock ERP lock DBF REC zfcp_erp_wait() lock ERP | zfcp_erp_action_to_running() | list_for_each() ready | list_move() current entry | ready to running | zfcp_dbf_rec_run() endless loop over running | zfcp_dbf_rec_run_lvl() | lock DBF REC spins forever
Any adapter recovery can trigger this, such as setting the device offline or reboot.
V4.9 commit 4eeaa4f3f1d6 ("zfcp: close window with unblocked rport during rport gone") introduced additional tracing of (un)blocking of rports. It missed that the adapter->erp_lock must be held when calling zfcp_dbf_rec_trig().
This fix uses the approach formerly introduced by commit aa0fec62391c ("[SCSI] zfcp: Fix sparse warning by providing new entry in dbf") that got later removed by commit ae0904f60fab ("[SCSI] zfcp: Redesign of the debug tracing for recovery actions.").
Introduce zfcp_dbf_rec_trig_lock(), a wrapper for zfcp_dbf_rec_trig() that acquires and releases the adapter->erp_lock for read.
--- drivers/s390/scsi/zfcp_dbf.c | 23 ++++++++++++++++++++++- drivers/s390/scsi/zfcp_ext.h | 5 ++++- drivers/s390/scsi/zfcp_scsi.c | 14 +++++++------- 3 files changed, 33 insertions(+), 9 deletions(-)
drivers/s390/scsi/zfcp_dbf.c +22 -1
@@ -3,7 +3,7 @@* * Debug traces for zfcp. * -* Copyright IBM Corp. 2002, 2017 +* Copyright IBM Corp. 2002, 2018 */ #define KMSG_COMPONENT "zfcp"
@@ -287,6 +287,27 @@ void zfcp_dbf_rec_trig(char *tag, structspin_unlock_irqrestore (&dbf->rec_lock, flags); } +/** +* zfcp_dbf_rec_trig_lock - trace event related to triggered recovery with lock +* @tag: identifier for event +* @adapter: adapter on which the erp_action should run +* @port: remote port involved in the erp_action +* @sdev: scsi device involved in the erp_action +* @want: wanted erp_action +* @need: required erp_action +* +* The adapter->erp_lock must not be held. +*/ +void zfcp_dbf_rec_trig_lock (char *tag,struct zfcp_adapter *adapter, +struct zfcp_port *port,struct scsi_device *sdev, +u8 want,u8 need) +{ +unsigned long flags; + +read_lock_irqsave (&adapter->erp_lock, flags); +zfcp_dbf_rec_trig (tag, adapter, port, sdev, want, need); +read_unlock_irqrestore (&adapter->erp_lock, flags); +}/** * zfcp_dbf_rec_run_lvl - trace event related to running recovery
drivers/s390/scsi/zfcp_ext.h +4 -1
@@ -3,7 +3,7 @@* * External function declarations. * -* Copyright IBM Corp. 2002, 2016 +* Copyright IBM Corp. 2002, 2018 */ #ifndef ZFCP_EXT_H
@@ -34,6 +34,9 @@ extern int zfcp_dbf_adapter_register(strextern void zfcp_dbf_adapter_unregister (struct zfcp_adapter *);extern void zfcp_dbf_rec_trig (char *,struct zfcp_adapter *,struct zfcp_port *,struct scsi_device *,u8 ,u8 ); +extern void zfcp_dbf_rec_trig_lock (char *tag,struct zfcp_adapter *adapter, +struct zfcp_port *port, +struct scsi_device *sdev,u8 want,u8 need);extern void zfcp_dbf_rec_run (char *,struct zfcp_erp_action *);extern void zfcp_dbf_rec_run_lvl (int level,char *tag,struct zfcp_erp_action *erp);
drivers/s390/scsi/zfcp_scsi.c +7 -7
@@ -3,7 +3,7 @@* * Interface to Linux SCSI midlayer. * -* Copyright IBM Corp. 2002, 2017 +* Copyright IBM Corp. 2002, 2018 */ #define KMSG_COMPONENT "zfcp"
@@ -637,9 +637,9 @@ static void zfcp_scsi_rport_register(str ids.port_id = port->d_id; ids.roles =FC_RPORT_ROLE_FCP_TARGET ; -zfcp_dbf_rec_trig ("scpaddy" , port->adapter, port,NULL , -ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD , -ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD ); +zfcp_dbf_rec_trig_lock ("scpaddy" , port->adapter, port,NULL , +ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD , +ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD ); rport =fc_remote_port_add (port->adapter->scsi_host,0 , &ids);if (!rport) { dev_err(&port->adapter->ccw_device->dev,
@@ -661,9 +661,9 @@ static void zfcp_scsi_rport_block(structstruct fc_rport *rport = port->rport;if (rport) { -zfcp_dbf_rec_trig ("scpdely" , port->adapter, port,NULL , -ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL , -ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL ); +zfcp_dbf_rec_trig_lock ("scpdely" , port->adapter, port,NULL , +ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL , +ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL );fc_remote_port_delete (rport); port->rport =NULL ; }
PATCH 268/366 llc: better deal with too small mtu
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 2c5d5b13c6eb79f5677e206b8aad59b3a2097f60 upstream.
syzbot loves to set very small mtu on devices, since it brings joy. We must make llc_ui_sendmsg() fool proof.
usercopy: Kernel memory overwrite attempt detected to wrapped address (offset 0, size 18446612139802320068)!
kernel BUG at mm/usercopy.c:100!
invalid opcode: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in: CPU: 0 PID: 17464 Comm: syz-executor1 Not tainted 4.17.0-rc3+ #36 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:usercopy_abort+0xbb/0xbd mm/usercopy.c:88 RSP: 0018:ffff8801868bf800 EFLAGS: 00010282 RAX: 000000000000006c RBX: ffffffff87d2fb00 RCX: 0000000000000000 RDX: 000000000000006c RSI: ffffffff81610731 RDI: ffffed0030d17ef6 RBP: ffff8801868bf858 R08: ffff88018daa4200 R09: ffffed003b5c4fb0 R10: ffffed003b5c4fb0 R11: ffff8801dae27d87 R12: ffffffff87d2f8e0 R13: ffffffff87d2f7a0 R14: ffffffff87d2f7a0 R15: ffffffff87d2f7a0 FS: 00007f56a14ac700(0000) GS:ffff8801dae00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b2bc21000 CR3: 00000001abeb1000 CR4: 00000000001426f0 DR0: 0000000020000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000030602 Call Trace: check_bogus_address mm/usercopy.c:153 [inline] __check_object_size+0x5d9/0x5d9 mm/usercopy.c:256 check_object_size include/linux/thread_info.h:108 [inline] check_copy_size include/linux/thread_info.h:139 [inline] copy_from_iter_full include/linux/uio.h:121 [inline] memcpy_from_msg include/linux/skbuff.h:3305 [inline] llc_ui_sendmsg+0x4b1/0x1530 net/llc/af_llc.c:941 sock_sendmsg_nosec net/socket.c:629 [inline] sock_sendmsg+0xd5/0x120 net/socket.c:639 __sys_sendto+0x3d7/0x670 net/socket.c:1789 __do_sys_sendto net/socket.c:1801 [inline] __se_sys_sendto net/socket.c:1797 [inline] __x64_sys_sendto+0xe1/0x1a0 net/socket.c:1797 do_syscall_64+0x1b1/0x800 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x455979 RSP: 002b:00007f56a14abc68 EFLAGS: 00000246 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 00007f56a14ac6d4 RCX: 0000000000455979 RDX: 0000000000000000 RSI: 0000000020000000 RDI: 0000000000000018 RBP: 000000000072bea0 R08: 00000000200012c0 R09: 0000000000000010 R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff R13: 0000000000000548 R14: 00000000006fbf60 R15: 0000000000000000 Code: 55 c0 e8 c0 55 bb ff ff 75 c8 48 8b 55 c0 4d 89 f9 ff 75 d0 4d 89 e8 48 89 d9 4c 89 e6 41 56 48 c7 c7 80 fa d2 87 e8 a0 0b a3 ff <0f> 0b e8 95 55 bb ff e8 c0 a8 f7 ff 8b 95 14 ff ff ff 4d 89 e8 RIP: usercopy_abort+0xbb/0xbd mm/usercopy.c:88 RSP: ffff8801868bf800
--- net/llc/af_llc.c | 3 +++ 1 file changed, 3 insertions(+)
net/llc/af_llc.c +3 -0
@@ -925,6 +925,9 @@ static int llc_ui_sendmsg(struct kiocb *if (size > llc->dev->mtu) size = llc->dev->mtu; copied = size - hdrlen; + rc = -EINVAL ; +if (copied <0 ) + goto release;release_sock (sk); skb =sock_alloc_send_skb (sk, size, noblock, &rc);lock_sock (sk);
PATCH 269/366 can: kvaser_usb: Increase correct stats counter in kvaser_usb_rx_can_msg()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jimmy Assarsson <[email protected]>
commit 6ee00865ffe4e8c8ba4a68d26db53c7ec09bbb89 upstream.
Increase rx_dropped, if alloc_can_skb() fails, not tx_dropped.
--- drivers/net/can/usb/kvaser_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/usb/kvaser_usb.c +1 -1
@@ -845,7 +845,7 @@ static void kvaser_usb_rx_can_msg(const skb =alloc_can_skb (priv->netdev, &cf);if (!skb) { - stats->tx_dropped++; + stats->rx_dropped++;return ; }
PATCH 270/366 ipvs: fix stats update from local clients
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
commit d5e032fc5697b6c0d6b4958bcacb981a08f8174e upstream.
Local clients are not properly synchronized on 32-bit CPUs when updating stats (3.10+). Now it is possible estimation_timer (timer), a stats reader, to interrupt the local client in the middle of write_seqcount_{begin,end} sequence leading to loop (DEADLOCK). The same interrupt can happen from received packet (SoftIRQ) which updates the same per-CPU stats.
Fix it by disabling BH while updating stats.
Found with debug:
WARNING: inconsistent lock state 4.17.0-rc2-00105-g35cb6d7-dirty #2 Not tainted
--------------------------------
inconsistent {IN-SOFTIRQ-R} -> {SOFTIRQ-ON-W} usage. ftp/2545 [HC0[0]:SC0[0]:HE1:SE1] takes:
86845479 (&syncp->seq#6){+.+-}, at: ip_vs_schedule+0x1c5/0x59e [ip_vs] {IN-SOFTIRQ-R} state was registered at:
lock_acquire+0x44/0x5b estimation_timer+0x1b3/0x341 [ip_vs] call_timer_fn+0x54/0xcd run_timer_softirq+0x10c/0x12b __do_softirq+0xc1/0x1a9 do_softirq_own_stack+0x1d/0x23 irq_exit+0x4a/0x64 smp_apic_timer_interrupt+0x63/0x71 apic_timer_interrupt+0x3a/0x40 default_idle+0xa/0xc arch_cpu_idle+0x9/0xb default_idle_call+0x21/0x23 do_idle+0xa0/0x167 cpu_startup_entry+0x19/0x1b start_secondary+0x133/0x182 startup_32_smp+0x164/0x168 irq event stamp: 42213
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
---- lock(&syncp->seq#6);
<Interrupt>
lock(&syncp->seq#6);
*** DEADLOCK ***
[bwh: Backported to 3.16:
- Drop change in ip_vs_conn_stats(), which doesn't use a seqlock
- Adjust context]
---
net/netfilter/ipvs/ip_vs_core.c +8 -0
@@ -118,6 +118,8 @@ ip_vs_in_stats(struct ip_vs_conn *cp, ststruct ip_vs_cpu_stats *s;struct ip_vs_service *svc; +local_bh_disable (); + s =this_cpu_ptr (dest->stats.cpustats); s->ustats.inpkts++;u64_stats_update_begin (&s->syncp);
@@ -138,6 +140,8 @@ ip_vs_in_stats(struct ip_vs_conn *cp, stu64_stats_update_begin (&s->syncp); s->ustats.inbytes += skb->len;u64_stats_update_end (&s->syncp); + +local_bh_enable (); } }
@@ -152,6 +156,8 @@ ip_vs_out_stats(struct ip_vs_conn *cp, sstruct ip_vs_cpu_stats *s;struct ip_vs_service *svc; +local_bh_disable (); + s =this_cpu_ptr (dest->stats.cpustats); s->ustats.outpkts++;u64_stats_update_begin (&s->syncp);
@@ -172,6 +178,8 @@ ip_vs_out_stats(struct ip_vs_conn *cp, su64_stats_update_begin (&s->syncp); s->ustats.outbytes += skb->len;u64_stats_update_end (&s->syncp); + +local_bh_enable (); } }
PATCH 271/366 drm/i915: Fix drm:intel_enable_lvds ERROR message in kernel log
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Florent Flament <[email protected]>
commit e8f48f96db7e482995743f461b3e8a5c1a102533 upstream.
Fix [drm:intel_enable_lvds] *ERROR* timed out waiting for panel to power on in kernel log at boot time.
Toshiba Satellite Z930 laptops needs between 1 and 2 seconds to power on its screen during Intel i915 DRM initialization. This currently results in a [drm:intel_enable_lvds] *ERROR* timed out waiting for panel to power on message appearing in the kernel log during boot time and when stopping the machine.
This change increases the timeout of the intel_enable_lvds function from 1 to 5 seconds, letting enough time for the Satellite 930 LCD screen to power on, and suppressing the error message from the kernel log.
This patch has been successfully tested on Linux 4.14 running on a Toshiba Satellite Z930.
[vsyrjala: bump the timeout from 2 to 5 seconds to match the DP
code and properly cover the max hw timeout of ~4 seconds, and drop the comment about the specific machine since this is not a particulary surprising issue, nor specific to that one machine]
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103414
References: https://bugzilla.kernel.org/show_bug.cgi?id=57591
--- drivers/gpu/drm/i915/intel_lvds.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_lvds.c +2 -1
@@ -219,7 +219,8 @@ static void intel_enable_lvds(struct intI915_WRITE (ctl_reg,I915_READ (ctl_reg) |POWER_TARGET_ON );POSTING_READ (lvds_encoder->reg); -if (wait_for ((I915_READ (stat_reg) &PP_ON ) !=0 ,1000 )) + +if (wait_for ((I915_READ (stat_reg) &PP_ON ) !=0 ,5000 ))DRM_ERROR ("timed out waiting for panel to power on\n" );intel_panel_enable_backlight (intel_connector);
PATCH 272/366 s390/cpum_sf: ensure sample frequency of perf event attributes is non-zero
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Hendrik Brueckner <[email protected]>
commit 4bbaf2584b86b0772413edeac22ff448f36351b1 upstream.
Correct a trinity finding for the perf_event_open() system call with a perf event attribute structure that uses a frequency but has the sampling frequency set to zero. This causes a FP divide exception during the sample rate initialization for the hardware sampling facility.
--- arch/s390/kernel/perf_cpum_sf.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/s390/kernel/perf_cpum_sf.c +4 -0
@@ -744,6 +744,10 @@ static int __hw_perf_event_init(struct p*/ rate =0 ;if (attr->freq) { +if (!attr->sample_freq) { + err = -EINVAL ; + goto out; + } rate =freq_to_sample_rate (&si, attr->sample_freq); rate =hw_limit_rate (&si, rate); attr->freq =0 ;
PATCH 273/366 libata: Blacklist some Sandisk SSDs for NCQ
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
commit 322579dcc865b94b47345ad1b6002ad167f85405 upstream.
Sandisk SSDs SD7SN6S256G and SD8SN8U256G are regularly locking up regularly under sustained moderate load with NCQ enabled. Blacklist for now.
--- drivers/ata/libata-core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/ata/libata-core.c +4 -0
@@ -4187,6 +4187,10 @@ static const struct ata_blacklist_entry/* https://bugzilla.kernel.org/show_bug.cgi?id=15573 */ { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ, }, + /* Some Sandisk SSDs lock up hard with NCQ enabled. Reported on + SD7SN6S256G and SD8SN8U256G */ + { "SanDisk SD[78]SN*G", NULL, ATA_HORKAGE_NONCQ, }, + /* devices which puke on READ_NATIVE_MAX */ { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, }, { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },
PATCH 274/366 RDMA/mlx5: Don't assume that medium blueFlame register exists
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Yishai Hadas <[email protected]>
commit 18b0362e87dfa09e355093b897b9db854e360d28 upstream.
User can leave system without medium BlueFlames registers, however the code assumed that at least one such register exists.
This patch fixes that assumption.
[bwh: Backported to 3.16:
- s/bfreg/uuar/g
- Neither alloc_med_class_uuar() nor num_med_uuar() takes a mlx5_ib_dev pointer, so first_med_uuar() doesn't need to take one
- Adjust context]
--- drivers/infiniband/hw/mlx5/qp.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +10 -7
@@ -356,11 +356,6 @@ static int qp_has_rq(struct ib_qp_init_areturn 1 ; } -static int first_med_uuar (void ) -{ -return 1 ; -} -static int next_uuar (int n) { n++;
@@ -395,6 +390,11 @@ static int max_uuari(struct mlx5_uuar_inreturn uuari->num_uars *4 ; } +static int first_med_uuar (struct mlx5_uuar_info *uuari) +{ +return num_med_uuar (uuari) ?1 : -ENOMEM ; +} +static int first_hi_uuar (struct mlx5_uuar_info *uuari) {int med;
@@ -420,10 +420,13 @@ static int alloc_high_class_uuar(structstatic int alloc_med_class_uuar (struct mlx5_uuar_info *uuari) { -int minidx =first_med_uuar (); +int minidx =first_med_uuar (uuari);int i; -for (i =first_med_uuar (); i <first_hi_uuar (uuari); i =next_uuar (i)) { +if (minidx <0 ) +return minidx; + +for (i = minidx; i <first_hi_uuar (uuari); i =next_uuar (i)) {if (uuari->count[i] < uuari->count[minidx]) minidx = i;if (!uuari->count[minidx])
PATCH 275/366 cifs: Allocate validate negotiation request through kmalloc
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Long Li <[email protected]>
commit 2796d303e3c5ec213c578ed3a66872205c126eb8 upstream.
The data buffer allocated on the stack can't be DMA'ed, ib_dma_map_page will return an invalid DMA address for a buffer on stack. Even worse, this incorrect address can't be detected by ib_dma_mapping_error. Sending data from this address to hardware will not fail, but the remote peer will get junk data.
Fix this by allocating the request on the heap in smb3_validate_negotiate.
Changes in v2:
Removed duplicated code on freeing buffers on function exit. (Thanks to Parav Pandit <[email protected]>) Fixed typo in the patch title.
Changes in v3:
Added "Fixes" to the patch.
Changed several sizeof() to use *pointer in place of struct.
Changes in v4:
Added detailed comments on the failure through RDMA. Allocate request buffer using GPF_NOFS. Fixed possible memory leak.
Changes in v5:
Removed variable ret for checking return value.
Changed to use pneg_inbuf->Dialects[0] to calculate unused space in pneg_inbuf.
--- fs/cifs/smb2pdu.c | 68 ++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 30 deletions(-)
fs/cifs/smb2pdu.c +26 -19
@@ -477,8 +477,8 @@ neg_exit:int smb3_validate_negotiate (const unsigned int xid,struct cifs_tcon *tcon) { -int rc =0 ; -struct validate_negotiate_info_req vneg_inbuf; +int rc; +struct validate_negotiate_info_req *pneg_inbuf;struct validate_negotiate_info_rsp *pneg_rsp =NULL ;u32 rsplen;
@@ -502,42 +502,47 @@ int smb3_validate_negotiate(const unsignif (tcon->ses->session_flags &SMB2_SESSION_FLAG_IS_NULL )cifs_dbg (VFS ,"Unexpected null user (anonymous) auth flag sent by server\n" ); - vneg_inbuf.Capabilities = + pneg_inbuf =kmalloc (sizeof (*pneg_inbuf),GFP_NOFS ); +if (!pneg_inbuf) +return -ENOMEM ; + + pneg_inbuf->Capabilities =cpu_to_le32 (tcon->ses->server->vals->req_capabilities); -memcpy (vneg_inbuf.Guid, tcon->ses->server->client_guid, +memcpy (pneg_inbuf->Guid, tcon->ses->server->client_guid,SMB2_CLIENT_GUID_SIZE );if (tcon->ses->sign) - vneg_inbuf.SecurityMode = + pneg_inbuf->SecurityMode =cpu_to_le16 (SMB2_NEGOTIATE_SIGNING_REQUIRED );else if (global_secflags &CIFSSEC_MAY_SIGN ) - vneg_inbuf.SecurityMode = + pneg_inbuf->SecurityMode =cpu_to_le16 (SMB2_NEGOTIATE_SIGNING_ENABLED );else - vneg_inbuf.SecurityMode =0 ; + pneg_inbuf->SecurityMode =0 ; - vneg_inbuf.DialectCount =cpu_to_le16 (1 ); - vneg_inbuf.Dialects[0 ] = + pneg_inbuf->DialectCount =cpu_to_le16 (1 ); + pneg_inbuf->Dialects[0 ] =cpu_to_le16 (tcon->ses->server->vals->protocol_id); rc =SMB2_ioctl (xid, tcon,NO_FILE_ID ,NO_FILE_ID ,FSCTL_VALIDATE_NEGOTIATE_INFO , true/* is_fsctl */ , - (char *)&vneg_inbuf,sizeof (struct validate_negotiate_info_req ), + (char *)pneg_inbuf,sizeof (struct validate_negotiate_info_req ), (char **)&pneg_rsp, &rsplen);if (rc !=0 ) {cifs_dbg (VFS ,"validate protocol negotiate failed: %d\n" , rc); -return -EIO ; + rc = -EIO ; + goto out_free_inbuf; } -if (rsplen !=sizeof (struct validate_negotiate_info_rsp )) { + rc = -EIO ; +if (rsplen !=sizeof (*pneg_rsp)) {cifs_dbg (VFS ,"invalid protocol negotiate response size: %d\n" , rsplen);/* relax check since Mac returns max bufsize allowed on ioctl */ -if ((rsplen > CIFSMaxBufSize) - || (rsplen <sizeof (struct validate_negotiate_info_rsp ))) - goto err_rsp_free; +if (rsplen > CIFSMaxBufSize || rsplen <sizeof (*pneg_rsp)) + goto out_free_rsp; }/* check validate negotiate info response matches what we got earlier */
@@ -554,15 +559,17 @@ int smb3_validate_negotiate(const unsign goto vneg_out;/* validate negotiate successful */ + rc =0 ;cifs_dbg (FYI ,"validate negotiate info successful\n" ); -kfree (pneg_rsp); -return 0 ; + goto out_free_rsp; vneg_out:cifs_dbg (VFS ,"protocol revalidation - security settings mismatch\n" ); -err_rsp_free: +out_free_rsp:kfree (pneg_rsp); -return -EIO ; +out_free_inbuf: +kfree (pneg_inbuf); +return rc; }int
PATCH 276/366 batman-adv: Avoid race in TT TVLV allocator helper
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 8ba0f9bd3bdea1058c2b2676bec7905724418e40 upstream.
The functions batadv_tt_prepare_tvlv_local_data and batadv_tt_prepare_tvlv_global_data are responsible for preparing a buffer which can be used to store the TVLV container for TT and add the VLAN information to it.
This will be done in three phases:
1. count the number of VLANs and their entries
2. allocate the buffer using the counters from the previous step and limits from the caller (parameter tt_len)
3. insert the VLAN information to the buffer
The step 1 and 3 operate on a list which contains the VLANs. The access to these lists must be protected with an appropriate lock or otherwise they might operate on on different entries. This could for example happen when another context is adding VLAN entries to this list.
This could lead to a buffer overflow in these functions when enough entries were added between step 1 and 3 to the VLAN lists that the buffer room for the entries (*tt_change) is smaller then the now required extra buffer for new VLAN entries.
--- net/batman-adv/translation-table.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/batman-adv/translation-table.c +4 -4
@@ -718,7 +718,7 @@ batadv_tt_prepare_tvlv_global_data(strucstruct batadv_orig_node_vlan *vlan;uint8_t *tt_change_ptr; -rcu_read_lock (); +spin_lock_bh (&orig_node->vlan_list_lock);list_for_each_entry_rcu (vlan, &orig_node->vlan_list, list) { num_vlan++; num_entries +=atomic_read (&vlan->tt.num_entries);
@@ -756,7 +756,7 @@ batadv_tt_prepare_tvlv_global_data(struc *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; out: -rcu_read_unlock (); +spin_unlock_bh (&orig_node->vlan_list_lock);return tvlv_len; }
@@ -790,7 +790,7 @@ batadv_tt_prepare_tvlv_local_data(structuint8_t *tt_change_ptr;int change_offset; -rcu_read_lock (); +spin_lock_bh (&bat_priv->softif_vlan_list_lock);hlist_for_each_entry_rcu (vlan, &bat_priv->softif_vlan_list, list) { num_vlan++; num_entries +=atomic_read (&vlan->tt.num_entries);
@@ -828,7 +828,7 @@ batadv_tt_prepare_tvlv_local_data(struct *tt_change = (struct batadv_tvlv_tt_change *)tt_change_ptr; out: -rcu_read_unlock (); +spin_unlock_bh (&bat_priv->softif_vlan_list_lock);return tvlv_len; }
PATCH 277/366 net/mlx4_en: Verify coalescing parameters are in range
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Moshe Shemesh <[email protected]>
commit 6ad4e91c6d796b38a7f0e724db1de28eeb122bad upstream.
Add check of coalescing parameters received through ethtool are within range of values supported by the HW.
Driver gets the coalescing rx/tx-usecs and rx/tx-frames as set by the users through ethtool. The ethtool support up to 32 bit value for each. However, mlx4 modify cq limits the coalescing time parameter and coalescing frames parameters to 16 bits.
Return out of range error if user tries to set these parameters to higher values.
Change type of sample-interval and adaptive_rx_coal parameters in mlx4 driver to u32 as the ethtool holds them as u32 and these parameters are not limited due to mlx4 HW.
--- drivers/net/ethernet/mellanox/mlx4/en_ethtool.c | 16 ++++++++++++++++ drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c +16 -0
@@ -441,6 +441,22 @@ static int mlx4_en_set_coalesce(struct nif (!coal->tx_max_coalesced_frames_irq)return -EINVAL ; +if (coal->tx_coalesce_usecs >MLX4_EN_MAX_COAL_TIME || + coal->rx_coalesce_usecs >MLX4_EN_MAX_COAL_TIME || + coal->rx_coalesce_usecs_low >MLX4_EN_MAX_COAL_TIME || + coal->rx_coalesce_usecs_high >MLX4_EN_MAX_COAL_TIME ) { +netdev_info (dev,"%s: maximum coalesce time supported is %d usecs\n" , + __func__,MLX4_EN_MAX_COAL_TIME ); +return -ERANGE ; + } + +if (coal->tx_max_coalesced_frames >MLX4_EN_MAX_COAL_PKTS || + coal->rx_max_coalesced_frames >MLX4_EN_MAX_COAL_PKTS ) { +netdev_info (dev,"%s: maximum coalesced frames supported is %d\n" , + __func__,MLX4_EN_MAX_COAL_PKTS ); +return -ERANGE ; + } + priv->rx_frames = (coal->rx_max_coalesced_frames ==MLX4_EN_AUTO_CONF ) ? MLX4_EN_RX_COAL_TARGET :
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +5 -2
@@ -136,6 +136,9 @@ enum {#define MLX4_EN_TX_COAL_PKTS 16#define MLX4_EN_TX_COAL_TIME 0x10 +#define MLX4_EN_MAX_COAL_PKTS U16_MAX +#define MLX4_EN_MAX_COAL_TIME U16_MAX +#define MLX4_EN_RX_RATE_LOW 400000#define MLX4_EN_RX_COAL_TIME_LOW 0#define MLX4_EN_RX_RATE_HIGH 450000
@@ -522,8 +525,8 @@ struct mlx4_en_priv {u16 rx_usecs_low;u32 pkt_rate_high;u16 rx_usecs_high; -u16 sample_interval; -u16 adaptive_rx_coal; +u32 sample_interval; +u32 adaptive_rx_coal;u32 msg_enable;u32 loopback_ok;u32 validate_loopback;
PATCH 278/366 smb3: directory sync should not return an error
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Steve French <[email protected]>
commit 6e70c267e68d77679534dcf4aaf84e66f2cf1425 upstream.
As with NFS, which ignores sync on directory handles, fsync on a directory handle is a noop for CIFS/SMB3. Do not return an error on it. It breaks some database apps otherwise.
--- fs/cifs/cifsfs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
fs/cifs/cifsfs.c +13 -0
@@ -899,6 +899,18 @@ const struct inode_operations cifs_symli#endif }; +/* +* Directory operations under CIFS/SMB2/SMB3 are synchronous, so fsync() +* is a dummy operation. +*/ +static int cifs_dir_fsync (struct file *file,loff_t start,loff_t end,int datasync) +{ +cifs_dbg (FYI ,"Sync directory - name: %pD datasync: 0x%x\n" , + file, datasync); + +return 0 ; +} +const struct file_operations cifs_file_ops = { .read = new_sync_read, .write = new_sync_write,
@@ -1018,6 +1030,7 @@ const struct file_operations cifs_dir_op .read = generic_read_dir, .unlocked_ioctl = cifs_ioctl, .llseek = generic_file_llseek, + .fsync = cifs_dir_fsync, }; static void
PATCH 279/366 tracing: Fix regex_match_front() to not over compare the test string
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Steven Rostedt (VMware)" <[email protected]>
commit dc432c3d7f9bceb3de6f5b44fb9c657c9810ed6d upstream.
The regex match function regex_match_front() in the tracing filter logic, was fixed to test just the pattern length from testing the entire test string. That is, it went from strncmp(str, r->pattern, len) to strcmp(str, r->pattern, r->len).
The issue is that str is not guaranteed to be nul terminated, and if r->len is greater than the length of str, it can access more memory than is allocated.
The solution is to add a simple test if (len < r->len) return 0.
--- kernel/trace/trace_events_filter.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_events_filter.c +3 -0
@@ -273,6 +273,9 @@ static int regex_match_full(char *str, sstatic int regex_match_front (char *str,struct regex *r,int len) { +if (len < r->len) +return 0 ; +if (strncmp (str, r->pattern, r->len) ==0 )return 1 ;return 0 ;
PATCH 280/366 ipv4: fix memory leaks in udp_sendmsg, ping_v4_sendmsg
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Andrey Ignatov <[email protected]>
commit 1b97013bfb11d66f041de691de6f0fec748ce016 upstream.
Fix more memory leaks in ip_cmsg_send() callers. Part of them were fixed earlier in 919483096bfe.
* udp_sendmsg one was there since the beginning when linux sources were first added to git;
* ping_v4_sendmsg one was copy/pasted in c319b4d76b9e.
Whenever return happens in udp_sendmsg() or ping_v4_sendmsg() IP options have to be freed if they were allocated previously.
Add label so that future callers (if any) can use it instead of kfree() before return that is easy to forget.
--- net/ipv4/ping.c | 7 +++++-- net/ipv4/udp.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-)
net/ipv4/ping.c +5 -2
@@ -779,8 +779,10 @@ static int ping_v4_sendmsg(struct kiocb ipc.addr = faddr = daddr;if (ipc.opt && ipc.opt->opt.srr) { -if (!daddr) -return -EINVAL ; +if (!daddr) { + err = -EINVAL ; + goto out_free; + } faddr = ipc.opt->opt.faddr; } tos =get_rttos (&ipc, inet);
@@ -845,6 +847,7 @@ back_from_confirm: out:ip_rt_put (rt); +out_free:if (free)kfree (ipc.opt);if (!err) {
net/ipv4/udp.c +5 -2
@@ -997,8 +997,10 @@ int udp_sendmsg(struct kiocb *iocb, stru ipc.addr = faddr = daddr;if (ipc.opt && ipc.opt->opt.srr) { -if (!daddr) -return -EINVAL ; +if (!daddr) { + err = -EINVAL ; + goto out_free; + } faddr = ipc.opt->opt.faddr; connected =0 ; }
@@ -1103,6 +1105,7 @@ do_append_data: out:ip_rt_put (rt); +out_free:if (free)kfree (ipc.opt);if (!err)
PATCH 281/366 Btrfs: ensure tmpfile inode is always persisted with link count of 0
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit 5762b5c958abbecb7fb9f4596a6476d1ce91ecf6 upstream.
If we open a file with O_TMPFILE, don't do any further operation on it (so that the inode item isn't updated) and then force a transaction commit, we get a persisted inode item with a link count of 1, and not 0 as it should be.
Steps to reproduce it (requires a modern xfs_io with -T support):
$ mkfs.btrfs -f /dev/sdd
$ mount -o /dev/sdd /mnt
$ xfs_io -T /mnt &
$ syncThen btrfs-debug-tree shows the inode item with a link count of 1:
$ btrfs-debug-tree /dev/sdd
(...)
fs tree key (FS_TREE ROOT_ITEM 0)
leaf 29556736 items 4 free space 15851 generation 6 owner 5
fs uuid f164d01b-1b92-481d-a4e4-435fb0f843d0
chunk uuid 0e3d0e56-bcca-4a1c-aa5f-cec2c6f4f7a6
item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
inode generation 3 transid 6 size 0 block group 0 mode 40755 links 1
item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
inode ref index 0 namelen 2 name: ..
item 2 key (257 INODE_ITEM 0) itemoff 15951 itemsize 160
inode generation 6 transid 6 size 0 block group 0 mode 100600 links 1
item 3 key (ORPHAN ORPHAN_ITEM 257) itemoff 15951 itemsize 0
orphan item
checksum tree key (CSUM_TREE ROOT_ITEM 0)
(...)--- fs/btrfs/inode.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
fs/btrfs/inode.c +15 -0
@@ -5731,6 +5731,13 @@ static struct inode *btrfs_new_inode(str }/* +* O_TMPFILE, set link count to 0, so that after this point, +* we fill in an inode item with the correct link count. +*/ +if (!name) +set_nlink (inode,0 ); + +/* * we have to initialize this early, so we can reclaim the inode * number if we fail afterwards in this function. */
@@ -9096,6 +9103,14 @@ static int btrfs_tmpfile(struct inode *dif (ret) goto out; +/* +* We set number of links to 0 in btrfs_new_inode(), and here we set +* it to 1 because d_tmpfile() will issue a warning if the count is 0, +* through: +* +* d_tmpfile() -> inode_dec_link_count() -> drop_nlink() +*/ +set_nlink (inode,1 );d_tmpfile (dentry, inode);mark_inode_dirty (inode);
PATCH 282/366 Btrfs: use insert_inode_locked4 for inode creation
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
commit b0d5d10f41a0f1cd839408dd94427f2db3553bca upstream.
Btrfs was inserting inodes into the hash table before we had fully set the inode up on disk. This leaves us open to rare races that allow two different inodes in memory for the same [root, inode] pair.
This patch fixes things by using insert_inode_locked4 to insert an I_NEW inode and unlock_new_inode when we're ready for the rest of the kernel to use the inode.
It also makes sure to init the operations pointers on the inode before going into the error handling paths.
--- fs/btrfs/inode.c | 176 +++++++++++++++++++++++++++++------------------ 1 file changed, 109 insertions(+), 67 deletions(-)
fs/btrfs/inode.c +109 -67
@@ -5702,6 +5702,17 @@ int btrfs_set_inode_index(struct inode *return ret; } +static int btrfs_insert_inode_locked (struct inode *inode) +{ +struct btrfs_iget_args args; + args.location = &BTRFS_I (inode)->location; + args.root =BTRFS_I (inode)->root; + +return insert_inode_locked4 (inode, +btrfs_inode_hash (inode->i_ino,BTRFS_I (inode)->root), + btrfs_find_actor, &args); +} + static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct inode *dir,
@@ -5794,10 +5805,19 @@ static struct inode *btrfs_new_inode(str sizes[1 ] = name_len +sizeof (*ref); } + location = &BTRFS_I (inode)->location; + location->objectid = objectid; + location->offset =0 ; +btrfs_set_key_type (location,BTRFS_INODE_ITEM_KEY ); + + ret =btrfs_insert_inode_locked (inode); +if (ret <0 ) + goto fail; + path->leave_spinning =1 ; ret =btrfs_insert_empty_items (trans, root, path, key, sizes, nitems);if (ret !=0 ) - goto fail; + goto fail_unlock;inode_init_owner (inode, dir, mode);inode_set_bytes (inode,0 );
@@ -5820,11 +5840,6 @@ static struct inode *btrfs_new_inode(strbtrfs_mark_buffer_dirty (path->nodes[0 ]);btrfs_free_path (path); - location = &BTRFS_I (inode)->location; - location->objectid = objectid; - location->offset =0 ; -btrfs_set_key_type (location,BTRFS_INODE_ITEM_KEY ); -btrfs_inherit_iflags (inode, dir);if (S_ISREG (mode)) {
@@ -5835,7 +5850,6 @@ static struct inode *btrfs_new_inode(strBTRFS_INODE_NODATASUM ; } -btrfs_insert_inode_hash (inode);inode_tree_add (inode);trace_btrfs_inode_new (inode);
@@ -5850,6 +5864,9 @@ static struct inode *btrfs_new_inode(str btrfs_ino(inode), root->root_key.objectid, ret);return inode; + +fail_unlock: +unlock_new_inode (inode); fail:if (dir && name)BTRFS_I (dir)->index_cnt--;
@@ -5984,28 +6001,28 @@ static int btrfs_mknod(struct inode *dir goto out_unlock; } - err =btrfs_init_inode_security (trans, inode, dir, &dentry->d_name); -if (err) { - drop_inode =1 ; - goto out_unlock; - } -/* * If the active LSM wants to access the inode during * d_instantiate it needs these. Smack checks to see * if the filesystem supports xattrs by looking at the * ops vector. */ - inode->i_op = &btrfs_special_inode_operations; - err =btrfs_add_nondir (trans, dir, dentry, inode,0 , index); +init_special_inode (inode, inode->i_mode, rdev); + + err =btrfs_init_inode_security (trans, inode, dir, &dentry->d_name);if (err) - drop_inode =1 ; -else { -init_special_inode (inode, inode->i_mode, rdev); + goto out_unlock_inode; + + err =btrfs_add_nondir (trans, dir, dentry, inode,0 , index); +if (err) { + goto out_unlock_inode; + }else {btrfs_update_inode (trans, root, inode); +unlock_new_inode (inode);d_instantiate (dentry, inode); } + out_unlock:btrfs_end_transaction (trans, root);btrfs_balance_delayed_items (root);
@@ -6015,6 +6032,12 @@ out_unlock:iput (inode); }return err; + +out_unlock_inode: + drop_inode =1 ; +unlock_new_inode (inode); + goto out_unlock; + } static int btrfs_create(struct inode *dir, struct dentry *dentry,
@@ -6049,15 +6072,6 @@ static int btrfs_create(struct inode *di goto out_unlock; } drop_inode_on_err =1 ; - - err =btrfs_init_inode_security (trans, inode, dir, &dentry->d_name); -if (err) - goto out_unlock; - - err =btrfs_update_inode (trans, root, inode); -if (err) - goto out_unlock; -/* * If the active LSM wants to access the inode during * d_instantiate it needs these. Smack checks to see
@@ -6066,14 +6080,23 @@ static int btrfs_create(struct inode *di*/ inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations; + inode->i_mapping->a_ops = &btrfs_aops; + inode->i_mapping->backing_dev_info = &root->fs_info->bdi; + + err =btrfs_init_inode_security (trans, inode, dir, &dentry->d_name); +if (err) + goto out_unlock_inode; + + err =btrfs_update_inode (trans, root, inode); +if (err) + goto out_unlock_inode; err =btrfs_add_nondir (trans, dir, dentry, inode,0 , index);if (err) - goto out_unlock; + goto out_unlock_inode; - inode->i_mapping->a_ops = &btrfs_aops; - inode->i_mapping->backing_dev_info = &root->fs_info->bdi;BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops; +unlock_new_inode (inode);d_instantiate (dentry, inode); out_unlock:
@@ -6085,6 +6108,11 @@ out_unlock:btrfs_balance_delayed_items (root);btrfs_btree_balance_dirty (root);return err; + +out_unlock_inode: +unlock_new_inode (inode); + goto out_unlock; + } static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
@@ -6192,25 +6220,30 @@ static int btrfs_mkdir(struct inode *dir } drop_on_err =1 ; +/* these must be set before we unlock the inode */ + inode->i_op = &btrfs_dir_inode_operations; + inode->i_fop = &btrfs_dir_file_operations; err =btrfs_init_inode_security (trans, inode, dir, &dentry->d_name);if (err) - goto out_fail; - - inode->i_op = &btrfs_dir_inode_operations; - inode->i_fop = &btrfs_dir_file_operations; + goto out_fail_inode;btrfs_i_size_write (inode,0 ); err =btrfs_update_inode (trans, root, inode);if (err) - goto out_fail; + goto out_fail_inode; err =btrfs_add_link (trans, dir, inode, dentry->d_name.name, dentry->d_name.len,0 , index);if (err) - goto out_fail; + goto out_fail_inode;d_instantiate (dentry, inode); +/* +* mkdir is special. We're unlocking after we call d_instantiate +* to avoid a race with nfsd calling d_instantiate. +*/ +unlock_new_inode (inode); drop_on_err =0 ; out_fail:
@@ -6220,6 +6253,10 @@ out_fail:btrfs_balance_delayed_items (root);btrfs_btree_balance_dirty (root);return err; + +out_fail_inode: +unlock_new_inode (inode); + goto out_fail; }/* helper for btfs_get_extent. Given an existing extent in the tree,
@@ -8173,6 +8210,7 @@ int btrfs_create_subvol_root(struct btrfset_nlink (inode,1 );btrfs_i_size_write (inode,0 ); +unlock_new_inode (inode); err =btrfs_subvol_inherit_props (trans, new_root, parent_root);if (err)
@@ -8823,12 +8861,6 @@ static int btrfs_symlink(struct inode *d goto out_unlock; } - err =btrfs_init_inode_security (trans, inode, dir, &dentry->d_name); -if (err) { - drop_inode =1 ; - goto out_unlock; - } -/* * If the active LSM wants to access the inode during * d_instantiate it needs these. Smack checks to see
@@ -8837,23 +8869,22 @@ static int btrfs_symlink(struct inode *d*/ inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations; + inode->i_mapping->a_ops = &btrfs_aops; + inode->i_mapping->backing_dev_info = &root->fs_info->bdi; +BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops; + + err =btrfs_init_inode_security (trans, inode, dir, &dentry->d_name); +if (err) + goto out_unlock_inode; err =btrfs_add_nondir (trans, dir, dentry, inode,0 , index);if (err) - drop_inode =1 ; -else { - inode->i_mapping->a_ops = &btrfs_aops; - inode->i_mapping->backing_dev_info = &root->fs_info->bdi; -BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops; - } -if (drop_inode) - goto out_unlock; + goto out_unlock_inode; path =btrfs_alloc_path ();if (!path) { err = -ENOMEM ; - drop_inode =1 ; - goto out_unlock; + goto out_unlock_inode; } key.objectid =btrfs_ino (inode); key.offset =0 ;
@@ -8862,9 +8893,8 @@ static int btrfs_symlink(struct inode *d err =btrfs_insert_empty_item (trans, root, path, &key, datasize);if (err) { - drop_inode =1 ;btrfs_free_path (path); - goto out_unlock; + goto out_unlock_inode; } leaf = path->nodes[0 ]; ei = btrfs_item_ptr(leaf, path->slots[0],
@@ -8888,12 +8918,15 @@ static int btrfs_symlink(struct inode *dinode_set_bytes (inode, name_len);btrfs_i_size_write (inode, name_len); err =btrfs_update_inode (trans, root, inode); -if (err) +if (err) { drop_inode =1 ; + goto out_unlock_inode; + } + +unlock_new_inode (inode); +d_instantiate (dentry, inode); out_unlock: -if (!err) -d_instantiate (dentry, inode);btrfs_end_transaction (trans, root);if (drop_inode) {inode_dec_link_count (inode);
@@ -8901,6 +8934,11 @@ out_unlock: }btrfs_btree_balance_dirty (root);return err; + +out_unlock_inode: + drop_inode =1 ; +unlock_new_inode (inode); + goto out_unlock; } static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
@@ -9084,14 +9122,6 @@ static int btrfs_tmpfile(struct inode *d goto out; } - ret =btrfs_init_inode_security (trans, inode, dir,NULL ); -if (ret) - goto out; - - ret =btrfs_update_inode (trans, root, inode); -if (ret) - goto out; - inode->i_fop = &btrfs_file_operations; inode->i_op = &btrfs_file_inode_operations;
@@ -9099,9 +9129,16 @@ static int btrfs_tmpfile(struct inode *d inode->i_mapping->backing_dev_info = &root->fs_info->bdi;BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops; + ret =btrfs_init_inode_security (trans, inode, dir,NULL ); +if (ret) + goto out_inode; + + ret =btrfs_update_inode (trans, root, inode); +if (ret) + goto out_inode; ret =btrfs_orphan_add (trans, inode);if (ret) - goto out; + goto out_inode;/* * We set number of links to 0 in btrfs_new_inode(), and here we set
@@ -9111,6 +9148,7 @@ static int btrfs_tmpfile(struct inode *d* d_tmpfile() -> inode_dec_link_count() -> drop_nlink() */ set_nlink (inode,1 ); +unlock_new_inode (inode);d_tmpfile (dentry, inode);mark_inode_dirty (inode);
@@ -9120,8 +9158,12 @@ out:iput (inode);btrfs_balance_delayed_items (root);btrfs_btree_balance_dirty (root); -return ret; + +out_inode: +unlock_new_inode (inode); + goto out; + }static const struct inode_operations btrfs_dir_inode_operations = {
PATCH 283/366 Btrfs: don't leave dangling dentry if symlink creation failed
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit d50866d00fb39fcf72307001763ee9cc92625a43 upstream.
When we are creating a symlink we might fail with an error after we created its inode and added the corresponding directory indexes to its parent inode. In this case we end up never removing the directory indexes because the inode eviction handler, called for our symlink inode on the final iput(), only removes items associated with the symlink inode and not with the parent inode.
Example:
$ mkfs.btrfs -f /dev/sdi $ mount /dev/sdi /mnt $ touch /mnt/foo $ ln -s /mnt/foo /mnt/bar ln: failed to create symbolic link ‘bar’: Cannot allocate memory $ umount /mnt $ btrfsck /dev/sdi Checking filesystem on /dev/sdi UUID: d5acb5ba-31bd-42da-b456-89dca2e716e1 checking extents checking free space cache checking fs roots root 5 inode 258 errors 2001, no inode item, link count wrong unresolved ref dir 256 index 3 namelen 3 name bar filetype 7 errors 4, no inode ref found 131073 bytes used err is 1 total csum bytes: 0 total tree bytes: 131072 total fs tree bytes: 32768 total extent tree bytes: 16384 btree space waste bytes: 124305 file data blocks allocated: 262144 referenced 262144 btrfs-progs v4.2.3
So fix this by adding the directory index entries as the very last step of symlink creation.
--- fs/btrfs/inode.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
fs/btrfs/inode.c +7 -4
@@ -8877,10 +8877,6 @@ static int btrfs_symlink(struct inode *dif (err) goto out_unlock_inode; - err =btrfs_add_nondir (trans, dir, dentry, inode,0 , index); -if (err) - goto out_unlock_inode; - path =btrfs_alloc_path ();if (!path) { err = -ENOMEM ;
@@ -8918,6 +8914,13 @@ static int btrfs_symlink(struct inode *dinode_set_bytes (inode, name_len);btrfs_i_size_write (inode, name_len); err =btrfs_update_inode (trans, root, inode); +/* +* Last step, add directory indexes for our symlink inode. This is the +* last step to avoid extra cleanup of these indexes if an error happens +* elsewhere above. +*/ +if (!err) + err =btrfs_add_nondir (trans, dir, dentry, inode,0 , index);if (err) { drop_inode =1 ; goto out_unlock_inode;
PATCH 284/366 f2fs: reposition unlock_new_inode to prevent accessing invalid inode
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
commit b73e52824c8920a5ff754e3c8ff68466a7dd61f9 upstream.
As the race condition on the inode cache, following scenario can appear:
[Thread a] [Thread b]
->f2fs_mkdir
->f2fs_add_link
->__f2fs_add_link
->init_inode_metadata failed here
->gc_thread_func
->f2fs_gc
->do_garbage_collect
->gc_data_segment
->f2fs_iget
->iget_locked
->wait_on_inode
->unlock_new_inode
->move_data_page
->make_bad_inode
->iputWhen we fail in create/symlink/mkdir/mknod/tmpfile, the new allocated inode should be set as bad to avoid being accessed by other thread. But in above scenario, it allows f2fs to access the invalid inode before this inode was set as bad.
This patch fix the potential problem, and this issue was found by code review.
change log from v1:
o Add condition judgment in gc_data_segment() suggested by Changman Lee.
o use iget_failed to simplify code.
---
fs/f2fs/gc.c +1 -1
@@ -602,7 +602,7 @@ next_step:if (phase ==2 ) { inode =f2fs_iget (sb, dni.ino); -if (IS_ERR (inode)) +if (IS_ERR (inode) ||is_bad_inode (inode))continue ; start_bidx =start_bidx_of_node (nofs,F2FS_I (inode));
fs/f2fs/namei.c +4 -12
@@ -135,9 +135,7 @@ static int f2fs_create(struct inode *dirreturn 0 ; out:clear_nlink (inode); -unlock_new_inode (inode); -make_bad_inode (inode); -iput (inode); +iget_failed (inode);alloc_nid_failed (sbi, ino);return err; }
@@ -271,9 +269,7 @@ static int f2fs_symlink(struct inode *direturn err; out:clear_nlink (inode); -unlock_new_inode (inode); -make_bad_inode (inode); -iput (inode); +iget_failed (inode);alloc_nid_failed (sbi, inode->i_ino);return err; }
@@ -312,9 +308,7 @@ static int f2fs_mkdir(struct inode *dir, out_fail:clear_inode_flag (F2FS_I (inode),FI_INC_LINK );clear_nlink (inode); -unlock_new_inode (inode); -make_bad_inode (inode); -iput (inode); +iget_failed (inode);alloc_nid_failed (sbi, inode->i_ino);return err; }
@@ -359,9 +353,7 @@ static int f2fs_mknod(struct inode *dir,return 0 ; out:clear_nlink (inode); -unlock_new_inode (inode); -make_bad_inode (inode); -iput (inode); +iget_failed (inode);alloc_nid_failed (sbi, inode->i_ino);return err; }
PATCH 285/366 f2fs: call f2fs_unlock_op after error was handled
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jaegeuk Kim <[email protected]>
commit 44c16156512f33c81e382a1e1df9524e26a7026a upstream.
This patch relocates f2fs_unlock_op in every directory operations to be called after any error was processed.
Otherwise, the checkpoint can be entered with valid node ids without its dentry when -ENOSPC is occurred.
[bwh: Backported to 3.16:
- Drop changes in f2fs_tmpfile()
- Use F2FS_SB() instead of F2FS_I_SB()]
--- fs/f2fs/f2fs.h | 1 + fs/f2fs/inode.c | 23 +++++++++++++++++++++++ fs/f2fs/namei.c | 32 +++++++++++--------------------- 3 files changed, 35 insertions(+), 21 deletions(-)
fs/f2fs/f2fs.h +1 -0
@@ -1121,6 +1121,7 @@ void update_inode(struct inode *, structvoid update_inode_page (struct inode *);int f2fs_write_inode (struct inode *,struct writeback_control *);void f2fs_evict_inode (struct inode *); +void handle_failed_inode (struct inode *);/* * namei.c
fs/f2fs/inode.c +23 -0
@@ -299,3 +299,26 @@ no_delete:clear_inode (inode);invalidate_mapping_pages (NODE_MAPPING (sbi), inode->i_ino, inode->i_ino); } + +/* caller should call f2fs_lock_op() */ +void handle_failed_inode (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_SB (inode->i_sb); + +clear_nlink (inode); +make_bad_inode (inode); +unlock_new_inode (inode); + +i_size_write (inode,0 ); +if (F2FS_HAS_BLOCKS (inode)) +f2fs_truncate (inode); + +remove_inode_page (inode); +stat_dec_inline_inode (inode); + +alloc_nid_failed (sbi, inode->i_ino); +f2fs_unlock_op (sbi); + +/* iput will drop the inode object */ +iput (inode); +}
fs/f2fs/namei.c +10 -17
@@ -124,9 +124,9 @@ static int f2fs_create(struct inode *dirf2fs_lock_op (sbi); err =f2fs_add_link (dentry, inode); -f2fs_unlock_op (sbi);if (err) goto out; +f2fs_unlock_op (sbi);alloc_nid_done (sbi, ino);
@@ -134,9 +134,7 @@ static int f2fs_create(struct inode *dirunlock_new_inode (inode);return 0 ; out: -clear_nlink (inode); -iget_failed (inode); -alloc_nid_failed (sbi, ino); +handle_failed_inode (inode);return err; }
@@ -156,15 +154,16 @@ static int f2fs_link(struct dentry *old_set_inode_flag (F2FS_I (inode),FI_INC_LINK );f2fs_lock_op (sbi); err =f2fs_add_link (dentry, inode); -f2fs_unlock_op (sbi);if (err) goto out; +f2fs_unlock_op (sbi);d_instantiate (dentry, inode);return 0 ; out:clear_inode_flag (F2FS_I (inode),FI_INC_LINK );iput (inode); +f2fs_unlock_op (sbi);return err; }
@@ -257,9 +256,9 @@ static int f2fs_symlink(struct inode *dif2fs_lock_op (sbi); err =f2fs_add_link (dentry, inode); -f2fs_unlock_op (sbi);if (err) goto out; +f2fs_unlock_op (sbi); err =page_symlink (inode, symname, symlen);alloc_nid_done (sbi, inode->i_ino);
@@ -268,9 +267,7 @@ static int f2fs_symlink(struct inode *diunlock_new_inode (inode);return err; out: -clear_nlink (inode); -iget_failed (inode); -alloc_nid_failed (sbi, inode->i_ino); +handle_failed_inode (inode);return err; }
@@ -294,9 +291,9 @@ static int f2fs_mkdir(struct inode *dir,set_inode_flag (F2FS_I (inode),FI_INC_LINK );f2fs_lock_op (sbi); err =f2fs_add_link (dentry, inode); -f2fs_unlock_op (sbi);if (err) goto out_fail; +f2fs_unlock_op (sbi);alloc_nid_done (sbi, inode->i_ino);
@@ -307,9 +304,7 @@ static int f2fs_mkdir(struct inode *dir, out_fail:clear_inode_flag (F2FS_I (inode),FI_INC_LINK ); -clear_nlink (inode); -iget_failed (inode); -alloc_nid_failed (sbi, inode->i_ino); +handle_failed_inode (inode);return err; }
@@ -343,18 +338,16 @@ static int f2fs_mknod(struct inode *dir,f2fs_lock_op (sbi); err =f2fs_add_link (dentry, inode); -f2fs_unlock_op (sbi);if (err) goto out; +f2fs_unlock_op (sbi);alloc_nid_done (sbi, inode->i_ino);d_instantiate (dentry, inode);unlock_new_inode (inode);return 0 ; out: -clear_nlink (inode); -iget_failed (inode); -alloc_nid_failed (sbi, inode->i_ino); +handle_failed_inode (inode);return err; }
PATCH 286/366 f2fs: go out for insert_inode_locked failure
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jaegeuk Kim <[email protected]>
commit a21c20f0c812925085204fced932ac95f2a76bf0 upstream.
We should not call unlock_new_inode when insert_inode_locked failed.
--- fs/f2fs/namei.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/f2fs/namei.c +1 -4
@@ -52,15 +52,12 @@ static struct inode *f2fs_new_inode(struif (err) { err = -EINVAL ; nid_free = true; - goto out; + goto fail; }trace_f2fs_new_inode (inode,0 );mark_inode_dirty (inode);return inode; -out: -clear_nlink (inode); -unlock_new_inode (inode); fail:trace_f2fs_new_inode (inode, err);make_bad_inode (inode);
PATCH 287/366 udf: avoid unneeded up_write when fail to add entry in ->symlink
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
commit 85cd083b498572fb9fa575cce3ed910c8ee84294 upstream.
We have released the ->i_data_sem before invoking udf_add_entry(), so in following error path, we should not release this lock again.
--- fs/udf/namei.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/udf/namei.c +2 -1
@@ -1015,7 +1015,7 @@ static int udf_symlink(struct inode *dir fi =udf_add_entry (dir, dentry, &fibh, &cfi, &err);if (!fi) - goto out_no_entry; + goto out_fail; cfi.icb.extLength =cpu_to_le32 (sb->s_blocksize); cfi.icb.extLocation =cpu_to_lelb (iinfo->i_location);if (UDF_SB (inode->i_sb)->s_lvid_bh) {
@@ -1037,6 +1037,7 @@ out: out_no_entry:up_write (&iinfo->i_data_sem); +out_fail:inode_dec_link_count (inode);iput (inode); goto out;
PATCH 288/366 udf: merge the pieces inserting a new non-directory object into directory
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit d2be51cb34dc501791f3b8c01a99a3f2064bd8d1 upstream.
boilerplate code in udf_{create,mknod,symlink} taken to new helper
symlink case converted to unique id calculated by udf_new_inode() - no point finding a new one.
--- fs/udf/namei.c | 98 +++++++++++++++----------------------------------- 1 file changed, 29 insertions(+), 69 deletions(-)
fs/udf/namei.c +29 -69
@@ -551,31 +551,16 @@ static int udf_delete_entry(struct inodereturn udf_write_fi (inode, cfi, fi, fibh,NULL ,NULL ); } -static int udf_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int udf_add_nondir (struct dentry *dentry,struct inode *inode) { +struct udf_inode_info *iinfo =UDF_I (inode); +struct inode *dir = dentry->d_parent->d_inode;struct udf_fileident_bh fibh; -struct inode *inode;struct fileIdentDesc cfi, *fi;int err; -struct udf_inode_info *iinfo; - - inode =udf_new_inode (dir, mode, &err); -if (!inode) { -return err; - } - - iinfo =UDF_I (inode); -if (iinfo->i_alloc_type ==ICBTAG_FLAG_AD_IN_ICB ) - inode->i_data.a_ops = &udf_adinicb_aops; -else - inode->i_data.a_ops = &udf_aops; - inode->i_op = &udf_file_inode_operations; - inode->i_fop = &udf_file_operations; -mark_inode_dirty (inode); fi =udf_add_entry (dir, dentry, &fibh, &cfi, &err); -if (!fi) { +if (unlikely (!fi)) {inode_dec_link_count (inode);iput (inode);return err;
@@ -595,6 +580,28 @@ static int udf_create(struct inode *dir,return 0 ; } +static int udf_create (struct inode *dir,struct dentry *dentry,umode_t mode, +bool excl) +{ +struct inode *inode; +int err; + + inode =udf_new_inode (dir, mode, &err); +if (!inode) { +return err; + } + +if (UDF_I (inode)->i_alloc_type ==ICBTAG_FLAG_AD_IN_ICB ) + inode->i_data.a_ops = &udf_adinicb_aops; +else + inode->i_data.a_ops = &udf_aops; + inode->i_op = &udf_file_inode_operations; + inode->i_fop = &udf_file_operations; +mark_inode_dirty (inode); + +return udf_add_nondir (dentry, inode); +} +static int udf_tmpfile (struct inode *dir,struct dentry *dentry,umode_t mode) {struct inode *inode;
@@ -622,10 +629,7 @@ static int udf_mknod(struct inode *dir, dev_t rdev) {struct inode *inode; -struct udf_fileident_bh fibh; -struct fileIdentDesc cfi, *fi;int err; -struct udf_inode_info *iinfo;if (!old_valid_dev (rdev))return -EINVAL ;
@@ -633,33 +637,10 @@ static int udf_mknod(struct inode *dir, err = -EIO ; inode =udf_new_inode (dir, mode, &err);if (!inode) - goto out; - - iinfo =UDF_I (inode); -init_special_inode (inode, mode, rdev); - fi =udf_add_entry (dir, dentry, &fibh, &cfi, &err); -if (!fi) { -inode_dec_link_count (inode); -iput (inode);return err; - } - cfi.icb.extLength =cpu_to_le32 (inode->i_sb->s_blocksize); - cfi.icb.extLocation =cpu_to_lelb (iinfo->i_location); - *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = -cpu_to_le32 (iinfo->i_unique &0x00000000FFFFFFFFUL ); -udf_write_fi (dir, &cfi, fi, &fibh,NULL ,NULL ); -if (UDF_I (dir)->i_alloc_type ==ICBTAG_FLAG_AD_IN_ICB ) -mark_inode_dirty (dir); -mark_inode_dirty (inode); - -if (fibh.sbh != fibh.ebh) -brelse (fibh.ebh); -brelse (fibh.sbh); -d_instantiate (dentry, inode); - err =0 ; -out: -return err; +init_special_inode (inode, mode, rdev); +return udf_add_nondir (dentry, inode); }static int udf_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode)
@@ -880,11 +861,8 @@ static int udf_symlink(struct inode *dirstruct inode *inode;struct pathComponent *pc;const char *compstart; -struct udf_fileident_bh fibh;struct extent_position epos = {};int eoffset, elen =0 ; -struct fileIdentDesc *fi; -struct fileIdentDesc cfi;uint8_t *ea;int err;int block;
@@ -1013,31 +991,13 @@ static int udf_symlink(struct inode *dirmark_inode_dirty (inode);up_write (&iinfo->i_data_sem); - fi =udf_add_entry (dir, dentry, &fibh, &cfi, &err); -if (!fi) - goto out_fail; - cfi.icb.extLength =cpu_to_le32 (sb->s_blocksize); - cfi.icb.extLocation =cpu_to_lelb (iinfo->i_location); -if (UDF_SB (inode->i_sb)->s_lvid_bh) { - *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = -cpu_to_le32 (lvid_get_unique_id (sb)); - } -udf_write_fi (dir, &cfi, fi, &fibh,NULL ,NULL ); -if (UDF_I (dir)->i_alloc_type ==ICBTAG_FLAG_AD_IN_ICB ) -mark_inode_dirty (dir); -if (fibh.sbh != fibh.ebh) -brelse (fibh.ebh); -brelse (fibh.sbh); -d_instantiate (dentry, inode); - err =0 ; - + err =udf_add_nondir (dentry, inode); out:kfree (name);return err; out_no_entry:up_write (&iinfo->i_data_sem); -out_fail:inode_dec_link_count (inode);iput (inode); goto out;
PATCH 289/366 udf: fix the udf_iget() vs. udf_new_inode() races
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit b231509616feb911c2a7a8814d58c0014ef5b17f upstream.
Currently udf_iget() (triggered by NFS) can race with udf_new_inode() leading to two inode structures with the same inode number:
nfsd: iget_locked() creates inode
nfsd: try to read from disk, block on that. udf_new_inode(): allocate inode with that inumber udf_new_inode(): insert it into icache, set it up and dirty udf_write_inode(): write inode into buffer cache
nfsd: get CPU again, look into buffer cache, see nice and sane on-disk
inode, set the in-core inode from it
Fix the problem by putting inode into icache in locked state (I_NEW set) and unlocking it only after it's fully set up.
--- fs/udf/ialloc.c | 7 ++++++- fs/udf/namei.c | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
fs/udf/ialloc.c +6 -1
@@ -123,7 +123,12 @@ struct inode *udf_new_inode(struct inode iinfo->i_alloc_type =ICBTAG_FLAG_AD_LONG ; inode->i_mtime = inode->i_atime = inode->i_ctime = iinfo->i_crtime =current_fs_time (inode->i_sb); -insert_inode_hash (inode); +if (unlikely (insert_inode_locked (inode) <0 )) { +make_bad_inode (inode); +iput (inode); + *err = -EIO ; +return NULL ; + }mark_inode_dirty (inode); *err =0 ;
fs/udf/namei.c +7 -0
@@ -562,6 +562,7 @@ static int udf_add_nondir(struct dentry fi =udf_add_entry (dir, dentry, &fibh, &cfi, &err);if (unlikely (!fi)) {inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode);return err; }
@@ -575,6 +576,7 @@ static int udf_add_nondir(struct dentryif (fibh.sbh != fibh.ebh)brelse (fibh.ebh);brelse (fibh.sbh); +unlock_new_inode (inode);d_instantiate (dentry, inode);return 0 ;
@@ -622,6 +624,7 @@ static int udf_tmpfile(struct inode *dirmark_inode_dirty (inode);d_tmpfile (dentry, inode); +unlock_new_inode (inode);return 0 ; }
@@ -663,6 +666,7 @@ static int udf_mkdir(struct inode *dir, fi =udf_add_entry (inode,NULL , &fibh, &cfi, &err);if (!fi) {inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode); goto out; }
@@ -681,6 +685,7 @@ static int udf_mkdir(struct inode *dir,if (!fi) {clear_nlink (inode);mark_inode_dirty (inode); +unlock_new_inode (inode);iput (inode); goto out; }
@@ -692,6 +697,7 @@ static int udf_mkdir(struct inode *dir,udf_write_fi (dir, &cfi, fi, &fibh,NULL ,NULL );inc_nlink (dir);mark_inode_dirty (dir); +unlock_new_inode (inode);d_instantiate (dentry, inode);if (fibh.sbh != fibh.ebh)brelse (fibh.ebh);
@@ -999,6 +1005,7 @@ out: out_no_entry:up_write (&iinfo->i_data_sem);inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode); goto out; }
PATCH 290/366 ufs: deal with nfsd/iget races
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit e4502c63f56aeca887ced37f24e0def1ef11cec8 upstream.
--- fs/ufs/ialloc.c | 6 +++++- fs/ufs/namei.c | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-)
fs/ufs/ialloc.c +5 -1
@@ -298,7 +298,10 @@ cg_found: ufsi->i_oeftflag =0 ; ufsi->i_dir_start_lookup =0 ;memset (&ufsi->i_u1,0 ,sizeof (ufsi->i_u1)); -insert_inode_hash (inode); +if (insert_inode_locked (inode) <0 ) { + err = -EIO ; + goto failed; + }mark_inode_dirty (inode);if (uspi->fs_magic ==UFS2_MAGIC ) {
@@ -337,6 +340,7 @@ cg_found: fail_remove_inode:mutex_unlock (&sbi->s_lock);clear_nlink (inode); +unlock_new_inode (inode);iput (inode);UFSD ("EXIT (FAILED): err %d\n" , err);return ERR_PTR (err);
fs/ufs/namei.c +4 -0
@@ -38,10 +38,12 @@ static inline int ufs_add_nondir(struct {int err =ufs_add_link (dentry, inode);if (!err) { +unlock_new_inode (inode);d_instantiate (dentry, inode);return 0 ; }inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode);return err; }
@@ -155,6 +157,7 @@ out_notlocked: out_fail:inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode); goto out; }
@@ -211,6 +214,7 @@ out: out_fail:inode_dec_link_count (inode);inode_dec_link_count (inode); +unlock_new_inode (inode);iput (inode); out_dir:inode_dec_link_count (dir);
PATCH 291/366 ufs: Fix warning from unlock_new_inode()
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit 12ecbb4b1d765a5076920999298d9625439dbe58 upstream.
Commit e4502c63f56aeca88 (ufs: deal with nfsd/iget races) introduced unlock_new_inode() call into ufs_add_nondir(). However that function gets called also from ufs_link() which hands it already initialized inode and thus unlock_new_inode() complains. The problem is harmless but annoying.
Fix the problem by opencoding necessary stuff in ufs_link()
--- fs/ufs/namei.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/ufs/namei.c +6 -1
@@ -174,7 +174,12 @@ static int ufs_link (struct dentry * oldinode_inc_link_count (inode);ihold (inode); - error =ufs_add_nondir (dentry, inode); + error =ufs_add_link (dentry, inode); +if (error) { +inode_dec_link_count (inode); +iput (inode); + }else +d_instantiate (dentry, inode);unlock_ufs (dir->i_sb);return error; }
PATCH 292/366 ufs: Fix possible deadlock when looking up directories
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
commit 514d748f69c97a51a2645eb198ac5c6218f22ff9 upstream.
Commit e4502c63f56aeca88 (ufs: deal with nfsd/iget races) made ufs create inodes with I_NEW flag set. However ufs_mkdir() never cleared this flag. Thus if someone ever tried to lookup the directory by inode number, he would deadlock waiting for I_NEW to be cleared. Luckily this mostly happens only if the filesystem is exported over NFS since otherwise we have the inode attached to dentry and don't look it up by inode number. In rare cases dentry can get freed without inode being freed and then we'd hit the deadlock even without NFS export.
Fix the problem by clearing I_NEW before instantiating new directory inode.
--- fs/ufs/namei.c | 1 + 1 file changed, 1 insertion(+)
fs/ufs/namei.c +1 -0
@@ -212,6 +212,7 @@ static int ufs_mkdir(struct inode * dir, goto out_fail;unlock_ufs (dir->i_sb); +unlock_new_inode (inode);d_instantiate (dentry, inode); out:return err;
PATCH 293/366 do d_instantiate/unlock_new_inode combinations safely
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
commit 1e2e547a93a00ebc21582c06ca3c6cfea2a309ee upstream.
For anything NFS-exported we do _not_ want to unlock new inode before it has grown an alias; original set of fixes got the ordering right, but missed the nasty complication in case of lockdep being enabled - unlock_new_inode() does
lockdep_annotate_inode_mutex_key(inode)
which can only be done before anyone gets a chance to touch ->i_mutex. Unfortunately, flipping the order and doing unlock_new_inode() before d_instantiate() opens a window when mkdir can race with open-by-fhandle on a guessed fhandle, leading to multiple aliases for a directory inode and all the breakage that follows from that.
Correct solution: a new primitive (d_instantiate_new())
combining these two in the right order - lockdep annotate, then d_instantiate(), then the rest of unlock_new_inode(). All combinations of d_instantiate() with unlock_new_inode() should be converted to that.
[bwh: Backported to 3.16:
- Drop changes in orangefs
- Apply similar change to ext3
- Adjust context]
---
fs/btrfs/inode.c +4 -12
@@ -6019,8 +6019,7 @@ static int btrfs_mknod(struct inode *dir goto out_unlock_inode; }else {btrfs_update_inode (trans, root, inode); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); } out_unlock:
@@ -6096,8 +6095,7 @@ static int btrfs_create(struct inode *di goto out_unlock_inode;BTRFS_I (inode)->io_tree.ops = &btrfs_extent_io_ops; -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); out_unlock:btrfs_end_transaction (trans, root);
@@ -6238,12 +6236,7 @@ static int btrfs_mkdir(struct inode *dirif (err) goto out_fail_inode; -d_instantiate (dentry, inode); -/* -* mkdir is special. We're unlocking after we call d_instantiate -* to avoid a race with nfsd calling d_instantiate. -*/ -unlock_new_inode (inode); +d_instantiate_new (dentry, inode); drop_on_err =0 ; out_fail:
@@ -8926,8 +8919,7 @@ static int btrfs_symlink(struct inode *d goto out_unlock_inode; } -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); out_unlock:btrfs_end_transaction (trans, root);
fs/dcache.c +22 -0
@@ -1680,6 +1680,28 @@ void d_instantiate(struct dentry *entry, }EXPORT_SYMBOL (d_instantiate); +/* +* This should be equivalent to d_instantiate() + unlock_new_inode(), +* with lockdep-related part of unlock_new_inode() done before +* anything else. Use that instead of open-coding d_instantiate()/ +* unlock_new_inode() combinations. +*/ +void d_instantiate_new (struct dentry *entry,struct inode *inode) +{ +BUG_ON (!hlist_unhashed (&entry->d_u.d_alias)); +BUG_ON (!inode); +lockdep_annotate_inode_mutex_key (inode); +security_d_instantiate (entry, inode); +spin_lock (&inode->i_lock); +__d_instantiate (entry, inode); +WARN_ON (!(inode->i_state &I_NEW )); + inode->i_state &= ~I_NEW ; +smp_mb (); +wake_up_bit (&inode->i_state, __I_NEW); +spin_unlock (&inode->i_lock); +} +EXPORT_SYMBOL (d_instantiate_new); +/** * d_instantiate_unique - instantiate a non-aliased dentry * @entry: dentry to instantiate
fs/ecryptfs/inode.c +1 -2
@@ -298,8 +298,7 @@ ecryptfs_create(struct inode *directory_iput (ecryptfs_inode); goto out; } -unlock_new_inode (ecryptfs_inode); -d_instantiate (ecryptfs_dentry, ecryptfs_inode); +d_instantiate_new (ecryptfs_dentry, ecryptfs_inode); out:return rc; }
fs/ext2/namei.c +2 -4
@@ -41,8 +41,7 @@ static inline int ext2_add_nondir(struct {int err =ext2_add_link (dentry, inode);if (!err) { -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; }inode_dec_link_count (inode);
@@ -265,8 +264,7 @@ static int ext2_mkdir(struct inode * dirif (err) goto out_fail; -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); out:return err;
fs/ext3/namei.c +2 -4
@@ -1671,8 +1671,7 @@ static int ext3_add_nondir(handle_t *hanint err =ext3_add_entry (handle, dentry, inode);if (!err) {ext3_mark_inode_dirty (handle, inode); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; }drop_nlink (inode);
@@ -1873,8 +1872,7 @@ out_clear_inode:if (err) goto out_clear_inode; -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); out_stop:brelse (dir_block);ext3_journal_stop (handle);
fs/ext4/namei.c +2 -4
@@ -2227,8 +2227,7 @@ static int ext4_add_nondir(handle_t *hanint err =ext4_add_entry (handle, dentry, inode);if (!err) {ext4_mark_inode_dirty (handle, inode); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; }drop_nlink (inode);
@@ -2466,8 +2465,7 @@ out_clear_inode: err =ext4_mark_inode_dirty (handle, dir);if (err) goto out_clear_inode; -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir))ext4_handle_sync (handle);
fs/f2fs/namei.c +4 -8
@@ -127,8 +127,7 @@ static int f2fs_create(struct inode *diralloc_nid_done (sbi, ino); -d_instantiate (dentry, inode); -unlock_new_inode (inode); +d_instantiate_new (dentry, inode);return 0 ; out:handle_failed_inode (inode);
@@ -260,8 +259,7 @@ static int f2fs_symlink(struct inode *di err =page_symlink (inode, symname, symlen);alloc_nid_done (sbi, inode->i_ino); -d_instantiate (dentry, inode); -unlock_new_inode (inode); +d_instantiate_new (dentry, inode);return err; out:handle_failed_inode (inode);
@@ -294,8 +292,7 @@ static int f2fs_mkdir(struct inode *dir,alloc_nid_done (sbi, inode->i_ino); -d_instantiate (dentry, inode); -unlock_new_inode (inode); +d_instantiate_new (dentry, inode);return 0 ;
@@ -340,8 +337,7 @@ static int f2fs_mknod(struct inode *dir,f2fs_unlock_op (sbi);alloc_nid_done (sbi, inode->i_ino); -d_instantiate (dentry, inode); -unlock_new_inode (inode); +d_instantiate_new (dentry, inode);return 0 ; out:handle_failed_inode (inode);
fs/jffs2/dir.c +4 -8
@@ -207,8 +207,7 @@ static int jffs2_create(struct inode *di __func__, inode->i_ino, inode->i_mode, inode->i_nlink, f->inocache->pino_nlink, inode->i_mapping->nrpages); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; fail:
@@ -427,8 +426,7 @@ static int jffs2_symlink (struct inode *mutex_unlock (&dir_f->sem);jffs2_complete_reservation (c); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; fail:
@@ -572,8 +570,7 @@ static int jffs2_mkdir (struct inode *dimutex_unlock (&dir_f->sem);jffs2_complete_reservation (c); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; fail:
@@ -747,8 +744,7 @@ static int jffs2_mknod (struct inode *dimutex_unlock (&dir_f->sem);jffs2_complete_reservation (c); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; fail:
fs/jfs/namei.c +4 -8
@@ -176,8 +176,7 @@ static int jfs_create(struct inode *dip,unlock_new_inode (ip);iput (ip); }else { -unlock_new_inode (ip); -d_instantiate (dentry, ip); +d_instantiate_new (dentry, ip); } out2:
@@ -309,8 +308,7 @@ static int jfs_mkdir(struct inode *dip,unlock_new_inode (ip);iput (ip); }else { -unlock_new_inode (ip); -d_instantiate (dentry, ip); +d_instantiate_new (dentry, ip); } out2:
@@ -1043,8 +1041,7 @@ static int jfs_symlink(struct inode *dipunlock_new_inode (ip);iput (ip); }else { -unlock_new_inode (ip); -d_instantiate (dentry, ip); +d_instantiate_new (dentry, ip); } out2:
@@ -1424,8 +1421,7 @@ static int jfs_mknod(struct inode *dir,unlock_new_inode (ip);iput (ip); }else { -unlock_new_inode (ip); -d_instantiate (dentry, ip); +d_instantiate_new (dentry, ip); } out1:
fs/nilfs2/namei.c +2 -4
@@ -50,8 +50,7 @@ static inline int nilfs_add_nondir(struc {int err =nilfs_add_link (dentry, inode);if (!err) { -d_instantiate (dentry, inode); -unlock_new_inode (inode); +d_instantiate_new (dentry, inode);return 0 ; }inode_dec_link_count (inode);
@@ -249,8 +248,7 @@ static int nilfs_mkdir(struct inode *dir goto out_fail;nilfs_mark_inode_dirty (inode); -d_instantiate (dentry, inode); -unlock_new_inode (inode); +d_instantiate_new (dentry, inode); out:if (!err) err =nilfs_transaction_commit (dir->i_sb);
fs/reiserfs/namei.c +4 -8
@@ -682,8 +682,7 @@ static int reiserfs_create(struct inodereiserfs_update_inode_transaction (inode);reiserfs_update_inode_transaction (dir); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); retval =journal_end (&th); out_failed:
@@ -763,8 +762,7 @@ static int reiserfs_mknod(struct inode * goto out_failed; } -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); retval =journal_end (&th); out_failed:
@@ -857,8 +855,7 @@ static int reiserfs_mkdir(struct inode */* the above add_entry did not update dir's stat data */ reiserfs_update_sd (&th, dir); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); retval =journal_end (&th); out_failed:reiserfs_write_unlock (dir->i_sb);
@@ -1162,8 +1159,7 @@ static int reiserfs_symlink(struct inode goto out_failed; } -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); retval =journal_end (&th); out_failed:reiserfs_write_unlock (parent_dir->i_sb);
fs/udf/namei.c +2 -4
@@ -576,8 +576,7 @@ static int udf_add_nondir(struct dentryif (fibh.sbh != fibh.ebh)brelse (fibh.ebh);brelse (fibh.sbh); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; }
@@ -697,8 +696,7 @@ static int udf_mkdir(struct inode *dir,udf_write_fi (dir, &cfi, fi, &fibh,NULL ,NULL );inc_nlink (dir);mark_inode_dirty (dir); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);if (fibh.sbh != fibh.ebh)brelse (fibh.ebh);brelse (fibh.sbh);
fs/ufs/namei.c +2 -4
@@ -38,8 +38,7 @@ static inline int ufs_add_nondir(struct {int err =ufs_add_link (dentry, inode);if (!err) { -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);return 0 ; }inode_dec_link_count (inode);
@@ -212,8 +211,7 @@ static int ufs_mkdir(struct inode * dir, goto out_fail;unlock_ufs (dir->i_sb); -unlock_new_inode (inode); -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode); out:return err;
include/linux/dcache.h +1 -0
@@ -234,6 +234,7 @@ static inline int dname_external(const s* These are the low-level FS interfaces to the dcache.. */ extern void d_instantiate (struct dentry *,struct inode *); +extern void d_instantiate_new (struct dentry *,struct inode *);extern struct dentry *d_instantiate_unique (struct dentry *,struct inode *);extern struct dentry *d_materialise_unique (struct dentry *,struct inode *);extern int d_instantiate_no_diralias (struct dentry *,struct inode *);
PATCH 294/366 batman-adv: Fix TT sync flags for intermediate TT responses
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Linus Lüssing <[email protected]>
commit 7072337e52b3e9d5460500d8dc9cbc1ba2db084c upstream.
The previous TT sync fix so far only fixed TT responses issued by the target node directly. So far, TT responses issued by intermediate nodes still lead to the wrong flags being added, leading to CRC mismatches.
This behaviour was observed at Freifunk Hannover in a 800 nodes setup where a considerable amount of nodes were still infected with 'WI' TT flags even with (most) nodes having the previous TT sync fix applied.
I was able to reproduce the issue with intermediate TT responses in a four node test setup and this patch fixes this issue by ensuring to use the per originator instead of the summarized, OR'd ones.
[bwh: Backported to 3.16:
- Drop inapplicable comment changes
- Change return types of batadv_tt_{local,global}_valid() to bool, done as part of a larger conversion upstream
- Adjust context]
---
net/batman-adv/translation-table.c +54 -14
@@ -1219,7 +1219,8 @@ batadv_tt_global_orig_entry_find(const s*/ static bool batadv_tt_global_entry_has_orig (const struct batadv_tt_global_entry *entry, -const struct batadv_orig_node *orig_node) +const struct batadv_orig_node *orig_node, +u8 *flags) {struct batadv_tt_orig_list_entry *orig_entry;bool found = false;
@@ -1227,6 +1228,10 @@ batadv_tt_global_entry_has_orig(const st orig_entry =batadv_tt_global_orig_entry_find (entry, orig_node);if (orig_entry) { found = true; + +if (flags) + *flags = orig_entry->flags; +batadv_tt_orig_list_entry_free_ref (orig_entry); }
@@ -1403,7 +1408,7 @@ static bool batadv_tt_global_add(structif (!(common->flags &BATADV_TT_CLIENT_TEMP )) goto out;if (batadv_tt_global_entry_has_orig (tt_global_entry, - orig_node)) + orig_node,NULL )) goto out_remove;batadv_tt_global_del_orig_list (tt_global_entry); goto add_orig_entry;
@@ -2311,23 +2316,46 @@ unlock: }/** -* batadv_tt_local_valid - verify that given tt entry is a valid one +* batadv_tt_local_valid() - verify local tt entry and get flags * @entry_ptr: to be checked local tt entry * @data_ptr: not used but definition required to satisfy the callback prototype +* @flags: a pointer to store TT flags for this client to * -* Returns 1 if the entry is a valid, 0 otherwise. +* Checks the validity of the given local TT entry. If it is, then the provided +* flags pointer is updated. +* +* Return: true if the entry is a valid, false otherwise. */ -static int batadv_tt_local_valid (const void *entry_ptr,const void *data_ptr) +static bool batadv_tt_local_valid (const void *entry_ptr, +const void *data_ptr, +u8 *flags) {const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;if (tt_common_entry->flags &BATADV_TT_CLIENT_NEW ) -return 0 ; -return 1 ; +return false; + +if (flags) + *flags = tt_common_entry->flags; + +return true; } -static int batadv_tt_global_valid (const void *entry_ptr, -const void *data_ptr) +/** +* batadv_tt_global_valid() - verify global tt entry and get flags +* @entry_ptr: to be checked global tt entry +* @data_ptr: an orig_node object (may be NULL) +* @flags: a pointer to store TT flags for this client to +* +* Checks the validity of the given global TT entry. If it is, then the provided +* flags pointer is updated either with the common (summed) TT flags if data_ptr +* is NULL or the specific, per originator TT flags otherwise. +* +* Return: true if the entry is a valid, false otherwise. +*/ +static bool batadv_tt_global_valid (const void *entry_ptr, +const void *data_ptr, +u8 *flags) {const struct batadv_tt_common_entry *tt_common_entry = entry_ptr;const struct batadv_tt_global_entry *tt_global_entry;
@@ -2341,7 +2369,8 @@ static int batadv_tt_global_valid(const struct batadv_tt_global_entry, common); -return batadv_tt_global_entry_has_orig (tt_global_entry, orig_node); +return batadv_tt_global_entry_has_orig (tt_global_entry, orig_node, + flags); }/**
@@ -2351,24 +2380,34 @@ static int batadv_tt_global_valid(const* @hash: hash table containing the tt entries * @tt_len: expected tvlv tt data buffer length in number of bytes * @tvlv_buff: pointer to the buffer to fill with the TT data -* @valid_cb: function to filter tt change entries +* @valid_cb: function to filter tt change entries and to return TT flags * @cb_data: data passed to the filter function as argument +* +* Fills the tvlv buff with the tt entries from the specified hash. If valid_cb +* is not provided then this becomes a no-op. */ static void batadv_tt_tvlv_generate (struct batadv_priv *bat_priv,struct batadv_hashtable *hash,void *tvlv_buff,uint16_t tt_len, -int (*valid_cb)(const void *,const void *), +bool (*valid_cb)(const void *, +const void *, +u8 *flags),void *cb_data) {struct batadv_tt_common_entry *tt_common_entry;struct batadv_tvlv_tt_change *tt_change;struct hlist_head *head;uint16_t tt_tot, tt_num_entries =0 ; +u8 flags; +bool ret;uint32_t i; tt_tot =batadv_tt_entries (tt_len); tt_change = (struct batadv_tvlv_tt_change *)tvlv_buff; +if (!valid_cb) +return ; +rcu_read_lock ();for (i =0 ; i < hash->size; i++) { head = &hash->table[i];
@@ -2378,11 +2417,12 @@ static void batadv_tt_tvlv_generate(struif (tt_tot == tt_num_entries)break ; -if ((valid_cb) && (!valid_cb (tt_common_entry, cb_data))) + ret =valid_cb (tt_common_entry, cb_data, &flags); +if (!ret)continue ;ether_addr_copy (tt_change->addr, tt_common_entry->addr); - tt_change->flags = tt_common_entry->flags; + tt_change->flags = flags; tt_change->vid =htons (tt_common_entry->vid);memset (tt_change->reserved,0 ,sizeof (tt_change->reserved));
PATCH 295/366 batman-adv: prevent TT request storms by not sending inconsistent TT TLVLs
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Marek Lindner <[email protected]>
commit 16116dac23396e73c01eeee97b102e4833a4b205 upstream.
A translation table TVLV changset sent with an OGM consists of a number of headers (one per VLAN) plus the changeset itself (addition and/or deletion of entries).
The per-VLAN headers are used by OGM recipients for consistency checks. Said consistency check might determine that a full translation table request is needed to restore consistency. If the TT sender adds per-VLAN headers of empty VLANs into the OGM, recipients are led to believe to have reached an inconsistent state and thus request a full table update. The full table does not contain empty VLANs (due to missing entries) the cycle restarts when the next OGM is issued.
Consequently, when the translation table TVLV headers are composed, empty VLANs are to be excluded.
---
net/batman-adv/translation-table.c +14 -3
@@ -786,14 +786,21 @@ batadv_tt_prepare_tvlv_local_data(struct {struct batadv_tvlv_tt_vlan_data *tt_vlan;struct batadv_softif_vlan *vlan; -uint16_t num_vlan =0 , num_entries =0 , tvlv_len; +u16 num_vlan =0 ; +u16 vlan_entries =0 ; +u16 total_entries =0 ; +u16 tvlv_len;uint8_t *tt_change_ptr;int change_offset;spin_lock_bh (&bat_priv->softif_vlan_list_lock);hlist_for_each_entry_rcu (vlan, &bat_priv->softif_vlan_list, list) { + vlan_entries =atomic_read (&vlan->tt.num_entries); +if (vlan_entries <1 ) +continue ; + num_vlan++; - num_entries +=atomic_read (&vlan->tt.num_entries); + total_entries += vlan_entries; } change_offset =sizeof (**tt_data);
@@ -801,7 +808,7 @@ batadv_tt_prepare_tvlv_local_data(struct/* if tt_len is negative, allocate the space needed by the full table */ if (*tt_len <0 ) - *tt_len =batadv_tt_len (num_entries); + *tt_len =batadv_tt_len (total_entries); tvlv_len = *tt_len; tvlv_len += change_offset;
@@ -818,6 +825,10 @@ batadv_tt_prepare_tvlv_local_data(struct tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data +1 );hlist_for_each_entry_rcu (vlan, &bat_priv->softif_vlan_list, list) { + vlan_entries =atomic_read (&vlan->tt.num_entries); +if (vlan_entries <1 ) +continue ; + tt_vlan->vid =htons (vlan->vid); tt_vlan->crc =htonl (vlan->tt.crc);
PATCH 296/366 ALSA: control: fix a redundant-copy issue
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Wenwen Wang <[email protected]>
commit 3f12888dfae2a48741c4caa9214885b3aaf350f9 upstream.
In snd_ctl_elem_add_compat(), the fields of the struct 'data' need to be copied from the corresponding fields of the struct 'data32' in userspace. This is achieved by invoking copy_from_user() and get_user() functions. The problem here is that the 'type' field is copied twice. One is by copy_from_user() and one is by get_user(). Given that the 'type' field is not used between the two copies, the second copy is *completely* redundant and should be removed for better performance and cleanup. Also, these two copies can cause inconsistent data: as the struct 'data32' resides in userspace and a malicious userspace process can race to change the 'type' field between the two copies to cause inconsistent data. Depending on how the data is used in the future, such an inconsistency may cause potential security risks.
For above reasons, we should take out the second copy.
--- sound/core/control_compat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sound/core/control_compat.c +1 -2
@@ -400,8 +400,7 @@ static int snd_ctl_elem_add_compat(strucif (copy_from_user (&data->id, &data32->id,sizeof (data->id)) ||copy_from_user (&data->type, &data32->type,3 *sizeof (u32))) goto error; -if (get_user (data->owner, &data32->owner) || -get_user (data->type, &data32->type)) +if (get_user (data->owner, &data32->owner)) goto error;switch (data->type) {case SNDRV_CTL_ELEM_TYPE_BOOLEAN :
PATCH 297/366 ALSA: usb: mixer: volume quirk for CM102-A+/102S+
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Federico Cuello <[email protected]>
commit 21493316a3c4598f308d5a9fa31cc74639c4caff upstream.
Currently it's not possible to set volume lower than 26% (it just mutes).
Also fixes this warning:
Warning! Unlikely big volume range (=9472), cval->res is probably wrong.
[13] FU [PCM Playback Volume] ch = 2, val = -9473/-1/1
, and volume works fine for full range.
--- sound/usb/mixer.c | 8 ++++++++ 1 file changed, 8 insertions(+)
sound/usb/mixer.c +8 -0
@@ -885,6 +885,14 @@ static void volume_control_quirks(struct }break ; +case USB_ID (0x0d8c ,0x0103 ): +if (!strcmp (kctl->id.name,"PCM Playback Volume" )) { +usb_audio_info (chip, +"set volume quirk for CM102-A+/102S+\n" ); + cval->min =-256 ; + } +break ; +case USB_ID (0x0471 ,0x0101 ):case USB_ID (0x0471 ,0x0104 ):case USB_ID (0x0471 ,0x0105 ):
PATCH 298/366 x86/kexec: Avoid double free_page() upon do_kexec_load() failure
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
commit a466ef76b815b86748d9870ef2a430af7b39c710 upstream.
Quoted 1 line
From
ff82bedd3e12f0d3353282054ae48c3bd8c72012Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Wed, 9 May 2018 12:12:39 +0900
Subject: [PATCH v3] x86/kexec: avoid double free_page() upon do_kexec_load() failure.
syzbot is reporting crashes after memory allocation failure inside do_kexec_load() [1]. This is because free_transition_pgtable() is called by both init_transition_pgtable() and machine_kexec_cleanup() when memory allocation failed inside init_transition_pgtable().
Regarding 32bit code, machine_kexec_free_page_tables() is called by both machine_kexec_alloc_page_tables() and machine_kexec_cleanup() when memory allocation failed inside machine_kexec_alloc_page_tables().
Fix this by leaving the error handling to machine_kexec_cleanup() (and optionally setting NULL after free_page()).
[1] https://syzkaller.appspot.com/bug?id=91e52396168cf2bdd572fe1e1bc0bc645c1c6b40
---
arch/x86/kernel/machine_kexec_32.c +5 -1
@@ -70,12 +70,17 @@ static void load_segments(void)static void machine_kexec_free_page_tables (struct kimage *image) {free_page ((unsigned long )image->arch.pgd); + image->arch.pgd =NULL ;#ifdef CONFIG_X86_PAE free_page ((unsigned long )image->arch.pmd0); + image->arch.pmd0 =NULL ;free_page ((unsigned long )image->arch.pmd1); + image->arch.pmd1 =NULL ;#endif free_page ((unsigned long )image->arch.pte0); + image->arch.pte0 =NULL ;free_page ((unsigned long )image->arch.pte1); + image->arch.pte1 =NULL ; }static int machine_kexec_alloc_page_tables (struct kimage *image)
@@ -92,7 +97,6 @@ static int machine_kexec_alloc_page_tabl !image->arch.pmd0 || !image->arch.pmd1 || #endif !image->arch.pte0 || !image->arch.pte1) { -machine_kexec_free_page_tables (image);return -ENOMEM ; }return 0 ;
arch/x86/kernel/machine_kexec_64.c +3 -1
@@ -25,8 +25,11 @@static void free_transition_pgtable (struct kimage *image) {free_page ((unsigned long )image->arch.pud); + image->arch.pud =NULL ;free_page ((unsigned long )image->arch.pmd); + image->arch.pmd =NULL ;free_page ((unsigned long )image->arch.pte); + image->arch.pte =NULL ; }static int init_transition_pgtable (struct kimage *image,pgd_t *pgd)
@@ -67,7 +70,6 @@ static int init_transition_pgtable(strucset_pte (pte,pfn_pte (paddr >>PAGE_SHIFT ,PAGE_KERNEL_EXEC ));return 0 ; err: -free_transition_pgtable (image);return result; }
PATCH 299/366 efi: Avoid potential crashes, fix the 'struct efi_pci_io_protocol_32' definition for mixed mode
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
commit 0b3225ab9407f557a8e20f23f37aa7236c10a9b1 upstream.
Mixed mode allows a kernel built for x86_64 to interact with 32-bit EFI firmware, but requires us to define all struct definitions carefully when it comes to pointer sizes.
'struct efi_pci_io_protocol_32' currently uses a 'void *' for the 'romimage' field, which will be interpreted as a 64-bit field on such kernels, potentially resulting in bogus memory references and subsequent crashes.
--- arch/x86/boot/compressed/eboot.c | 6 ++++-- include/linux/efi.h | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/boot/compressed/eboot.c +4 -2
@@ -358,7 +358,8 @@ __setup_efi_pci32(efi_pci_io_protocol_32if (status !=EFI_SUCCESS ) goto free_struct; -memcpy (rom->romdata, pci->romimage, pci->romsize); +memcpy (rom->romdata, (void *)(unsigned long )pci->romimage, + pci->romsize);return status; free_struct:
@@ -460,7 +461,8 @@ __setup_efi_pci64(efi_pci_io_protocol_64if (status !=EFI_SUCCESS ) goto free_struct; -memcpy (rom->romdata, pci->romimage, pci->romsize); +memcpy (rom->romdata, (void *)(unsigned long )pci->romimage, + pci->romsize);return status; free_struct:
include/linux/efi.h +4 -4
@@ -368,8 +368,8 @@ typedef struct {u32 attributes;u32 get_bar_attributes;u32 set_bar_attributes; -uint64_t romsize; -void *romimage; +u64 romsize; +u32 romimage; } efi_pci_io_protocol_32; typedef struct {
@@ -388,8 +388,8 @@ typedef struct {u64 attributes;u64 get_bar_attributes;u64 set_bar_attributes; -uint64_t romsize; -void *romimage; +u64 romsize; +u64 romimage; } efi_pci_io_protocol_64; typedef struct {
PATCH 301/366 drm/i915/userptr: reject zero user_size
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Auld <[email protected]>
commit 20943f984967477c906522112d2b6b5a29f94684 upstream.
Operating on a zero sized GEM userptr object will lead to explosions.
Testcase: igt/gem_userptr_blits/input-checking
--- drivers/gpu/drm/i915/i915_gem_userptr.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/i915/i915_gem_userptr.c +3 -0
@@ -657,6 +657,9 @@ i915_gem_userptr_ioctl(struct drm_device I915_USERPTR_UNSYNCHRONIZED))return -EINVAL ; +if (!args->user_size) +return -EINVAL ; +if (offset_in_page (args->user_ptr | args->user_size))return -EINVAL ;
PATCH 302/366 Btrfs: send, fix invalid access to commit roots due to concurrent snapshotting
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Robbie Ko <[email protected]>
commit 6f2f0b394b54e2b159ef969a0b5274e9bbf82ff2 upstream.
[BUG]
btrfs incremental send BUG happens when creating a snapshot of snapshot that is being used by send.
[REASON]
The problem can happen if while we are doing a send one of the snapshots used (parent or send) is snapshotted, because snapshoting implies COWing the root of the source subvolume/snapshot.
1. When doing an incremental send, the send process will get the commit roots from the parent and send snapshots, and add references to them through extent_buffer_get().
2. When a snapshot/subvolume is snapshotted, its root node is COWed (transaction.c:create_pending_snapshot()).
3. COWing releases the space used by the node immediately, through:
__btrfs_cow_block()
--btrfs_free_tree_block()
----btrfs_add_free_space(bytenr of node)
4. Because send doesn't hold a transaction open, it's possible that the transaction used to create the snapshot commits, switches the commit root and the old space used by the previous root node gets assigned to some other node allocation. Allocation of a new node will use the existing extent buffer found in memory, which we previously got a reference through extent_buffer_get(), and allow the extent buffer's content (pages) to be modified:
btrfs_alloc_tree_block --btrfs_reserve_extent ----find_free_extent (get bytenr of old node) --btrfs_init_new_buffer (use bytenr of old node) ----btrfs_find_create_tree_block ------alloc_extent_buffer --------find_extent_buffer (get old node)
5. So send can access invalid memory content and have unpredictable behaviour.
[FIX]
So we fix the problem by copying the commit roots of the send and parent snapshots and use those copies.
CallTrace looks like this:
------------[ cut here ]------------ kernel BUG at fs/btrfs/ctree.c:1861! invalid opcode: 0000 [#1] SMP CPU: 6 PID: 24235 Comm: btrfs Tainted: P O 3.10.105 #23721 ffff88046652d680 ti: ffff88041b720000 task.ti: ffff88041b720000 RIP: 0010:[<ffffffffa08dd0e8>] read_node_slot+0x108/0x110 [btrfs] RSP: 0018:ffff88041b723b68 EFLAGS: 00010246 RAX: ffff88043ca6b000 RBX: ffff88041b723c50 RCX: ffff880000000000 RDX: 000000000000004c RSI: ffff880314b133f8 RDI: ffff880458b24000 RBP: 0000000000000000 R08: 0000000000000001 R09: ffff88041b723c66 R10: 0000000000000001 R11: 0000000000001000 R12: ffff8803f3e48890 R13: ffff8803f3e48880 R14: ffff880466351800 R15: 0000000000000001 FS: 00007f8c321dc8c0(0000) GS:ffff88047fcc0000(0000) CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 R2: 00007efd1006d000 CR3: 0000000213a24000 CR4: 00000000003407e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Stack: ffff88041b723c50 ffff8803f3e48880 ffff8803f3e48890 ffff8803f3e48880 ffff880466351800 0000000000000001 ffffffffa08dd9d7 ffff88041b723c50 ffff8803f3e48880 ffff88041b723c66 ffffffffa08dde85 a9ff88042d2c4400 Call Trace: [<ffffffffa08dd9d7>] ? tree_move_down.isra.33+0x27/0x50 [btrfs] [<ffffffffa08dde85>] ? tree_advance+0xb5/0xc0 [btrfs] [<ffffffffa08e83d4>] ? btrfs_compare_trees+0x2d4/0x760 [btrfs] [<ffffffffa0982050>] ? finish_inode_if_needed+0x870/0x870 [btrfs] [<ffffffffa09841ea>] ? btrfs_ioctl_send+0xeda/0x1050 [btrfs] [<ffffffffa094bd3d>] ? btrfs_ioctl+0x1e3d/0x33f0 [btrfs] [<ffffffff81111133>] ? handle_pte_fault+0x373/0x990 [<ffffffff8153a096>] ? atomic_notifier_call_chain+0x16/0x20 [<ffffffff81063256>] ? set_task_cpu+0xb6/0x1d0 [<ffffffff811122c3>] ? handle_mm_fault+0x143/0x2a0 [<ffffffff81539cc0>] ? __do_page_fault+0x1d0/0x500 [<ffffffff81062f07>] ? check_preempt_curr+0x57/0x90 [<ffffffff8115075a>] ? do_vfs_ioctl+0x4aa/0x990 [<ffffffff81034f83>] ? do_fork+0x113/0x3b0 [<ffffffff812dd7d7>] ? trace_hardirqs_off_thunk+0x3a/0x6c [<ffffffff81150cc8>] ? SyS_ioctl+0x88/0xa0 [<ffffffff8153e422>] ? system_call_fastpath+0x16/0x1b ---[ end trace 29576629ee80b2e1 ]---
--- fs/btrfs/ctree.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
fs/btrfs/ctree.c +14 -2
@@ -5406,12 +5406,24 @@ int btrfs_compare_trees(struct btrfs_roodown_read (&left_root->fs_info->commit_root_sem); left_level =btrfs_header_level (left_root->commit_root); left_root_level = left_level; - left_path->nodes[left_level] = left_root->commit_root; + left_path->nodes[left_level] = +btrfs_clone_extent_buffer (left_root->commit_root); +if (!left_path->nodes[left_level]) { +up_read (&left_root->fs_info->commit_root_sem); + ret = -ENOMEM ; + goto out; + }extent_buffer_get (left_path->nodes[left_level]); right_level =btrfs_header_level (right_root->commit_root); right_root_level = right_level; - right_path->nodes[right_level] = right_root->commit_root; + right_path->nodes[right_level] = +btrfs_clone_extent_buffer (right_root->commit_root); +if (!right_path->nodes[right_level]) { +up_read (&left_root->fs_info->commit_root_sem); + ret = -ENOMEM ; + goto out; + }extent_buffer_get (right_path->nodes[right_level]);up_read (&left_root->fs_info->commit_root_sem);
PATCH 303/366 ARM: keystone: fix platform_domain_notifier array overrun
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Russell King <[email protected]>
commit 9954b80b8c0e8abc98e17bba0fccd9876211ceaa upstream.
platform_domain_notifier contains a variable sized array, which the pm_clk_notify() notifier treats as a NULL terminated array:
for (con_id = clknb->con_ids; *con_id; con_id++)
pm_clk_add(dev, *con_id);Omitting the initialiser for con_ids means that the array is zero sized, and there is no NULL terminator. This leads to pm_clk_notify() overrunning into what ever structure follows, which may not be NULL. This leads to an oops:
Unable to handle kernel NULL pointer dereference at virtual address 0000008c pgd = c0003000 [0000008c] *pgd=80000800004003c, *pmd=00000000c Internal error: Oops: 206 [#1] PREEMPT SMP ARM Modules linked in:c CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.16.0+ #9 Hardware name: Keystone PC is at strlen+0x0/0x34 LR is at kstrdup+0x18/0x54 pc : [<c0623340>] lr : [<c0111d6c>] psr: 20000013
sp : eec73dc0 ip : eed780c0 fp : 00000001
r10: 00000000 r9 : 00000000 r8 : eed71e10
r7 : 0000008c r6 : 0000008c r5 : 014000c0 r4 : c03a6ff4 r3 : c09445d0 r2 : 00000000 r1 : 014000c0 r0 : 0000008c
Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
Control: 30c5387d Table: 00003000 DAC: fffffffd Process swapper/0 (pid: 1, stack limit = 0xeec72210)
Stack: (0xeec73dc0 to 0xeec74000)
...
[<c0623340>] (strlen) from [<c0111d6c>] (kstrdup+0x18/0x54)
[<c0111d6c>] (kstrdup) from [<c03a6ff4>] (__pm_clk_add+0x58/0x120)
[<c03a6ff4>] (__pm_clk_add) from [<c03a731c>] (pm_clk_notify+0x64/0xa8)
[<c03a731c>] (pm_clk_notify) from [<c004614c>] (notifier_call_chain+0x44/0x84) [<c004614c>] (notifier_call_chain) from [<c0046320>] (__blocking_notifier_call_chain+0x48/0x60) [<c0046320>] (__blocking_notifier_call_chain) from [<c0046350>] (blocking_notifier_call_chain+0x18/0x20) [<c0046350>] (blocking_notifier_call_chain) from [<c0390234>] (device_add+0x36c/0x534) [<c0390234>] (device_add) from [<c047fc00>] (of_platform_device_create_pdata+0x70/0xa4) [<c047fc00>] (of_platform_device_create_pdata) from [<c047fea0>] (of_platform_bus_create+0xf0/0x1ec) [<c047fea0>] (of_platform_bus_create) from [<c047fff8>] (of_platform_populate+0x5c/0xac) [<c047fff8>] (of_platform_populate) from [<c08b1f04>] (of_platform_default_populate_init+0x8c/0xa8) [<c08b1f04>] (of_platform_default_populate_init) from [<c000a78c>] (do_one_initcall+0x3c/0x164) [<c000a78c>] (do_one_initcall) from [<c087bd9c>] (kernel_init_freeable+0x10c/0x1d0) [<c087bd9c>] (kernel_init_freeable) from [<c0628db0>] (kernel_init+0x8/0xf0) [<c0628db0>] (kernel_init) from [<c00090d8>] (ret_from_fork+0x14/0x3c)
Exception stack(0xeec73fb0 to 0xeec73ff8) 3fa0: 00000000 00000000 00000000 00000000 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 Code: e3520000 1afffff7 e12fff1e c0801730 (e5d02000) ---[ end trace cafa8f148e262e80 ]---
Fix this by adding the necessary initialiser.
--- arch/arm/mach-keystone/pm_domain.c | 1 + 1 file changed, 1 insertion(+)
arch/arm/mach-keystone/pm_domain.c +1 -0
@@ -59,6 +59,7 @@ static struct dev_pm_domain keystone_pm_static struct pm_clk_notifier_block platform_domain_notifier = { .pm_domain = &keystone_pm_domain, + .con_ids = {NULL }, };static struct of_device_id of_keystone_table[] = {
PATCH 304/366 net/mlx4_core: Fix error handling in mlx4_init_port_info.
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Tarick Bedeir <[email protected]>
commit 57f6f99fdad9984801cde05c1db68fe39b474a10 upstream.
Avoid exiting the function with a lingering sysfs file (if the first call to device_create_file() fails while the second succeeds), and avoid calling devlink_port_unregister() twice.
In other words, either mlx4_init_port_info() succeeds and returns zero, or it fails, returns non-zero, and requires no cleanup.
--- drivers/net/ethernet/mellanox/mlx4/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/main.c +3 -1
@@ -2048,6 +2048,7 @@ static int mlx4_init_port_info(struct mlif (err) {mlx4_err (dev,"Failed to create file for port %d\n" , port); info->port =-1 ; +return err; }sprintf (info->dev_mtu_name,"mlx4_port%d_mtu" , port);
@@ -2066,9 +2067,10 @@ static int mlx4_init_port_info(struct mlmlx4_err (dev,"Failed to create mtu file for port %d\n" , port);device_remove_file (&info->dev->pdev->dev, &info->port_attr); info->port =-1 ; +return err; } -return err; +return 0 ; }static void mlx4_cleanup_port_info (struct mlx4_port_info *info)
PATCH 305/366 tracing/x86/xen: Remove zero data size trace events trace_xen_mmu_flush_tlb{_all}
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Steven Rostedt (VMware)" <[email protected]>
commit 45dd9b0666a162f8e4be76096716670cf1741f0e upstream.
Doing an audit of trace events, I discovered two trace events in the xen subsystem that use a hack to create zero data size trace events. This is not what trace events are for. Trace events add memory footprint overhead, and if all you need to do is see if a function is hit or not, simply make that function noinline and use function tracer filtering.
Worse yet, the hack used was:
__array(char, x, 0)
Which creates a static string of zero in length. There's assumptions about such constructs in ftrace that this is a dynamic string that is nul terminated. This is not the case with these tracepoints and can cause problems in various parts of ftrace.
Nuke the trace events!
---
arch/x86/xen/mmu.c +1 -5
@@ -1283,8 +1283,6 @@ void xen_flush_tlb_all(void)struct mmuext_op *op;struct multicall_space mcs; -trace_xen_mmu_flush_tlb_all (0 ); -preempt_disable (); mcs =xen_mc_entry (sizeof (*op));
@@ -1297,13 +1295,11 @@ void xen_flush_tlb_all(void)preempt_enable (); } -static void xen_flush_tlb (void ) +static noinline void xen_flush_tlb(void) {struct mmuext_op *op;struct multicall_space mcs; -trace_xen_mmu_flush_tlb (0 ); -preempt_disable (); mcs =xen_mc_entry (sizeof (*op));
include/trace/events/xen.h +0 -16
@@ -377,22 +377,6 @@ DECLARE_EVENT_CLASS(xen_mmu_pgd,DEFINE_XEN_MMU_PGD_EVENT (xen_mmu_pgd_pin);DEFINE_XEN_MMU_PGD_EVENT (xen_mmu_pgd_unpin); -TRACE_EVENT (xen_mmu_flush_tlb_all, - TP_PROTO(int x), -TP_ARGS (x), -TP_STRUCT__entry (__array (char, x,0 )), -TP_fast_assign ((void )x), -TP_printk ("%s" ,"" ) - ); - -TRACE_EVENT (xen_mmu_flush_tlb, - TP_PROTO(int x), -TP_ARGS (x), -TP_STRUCT__entry (__array (char, x,0 )), -TP_fast_assign ((void )x), -TP_printk ("%s" ,"" ) - ); - TRACE_EVENT(xen_mmu_flush_tlb_single, TP_PROTO(unsigned long addr), TP_ARGS(addr),
PATCH 306/366 MIPS: ptrace: Expose FIR register through FP regset
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: "Maciej W. Rozycki" <[email protected]>
commit 71e909c0cdad28a1df1fa14442929e68615dee45 upstream.
Correct commit 7aeb753b5353 ("MIPS: Implement task_user_regset_view.") and expose the FIR register using the unused 4 bytes at the end of the NT_PRFPREG regset. Without that register included clients cannot use the PTRACE_GETREGSET request to retrieve the complete FPU register set and have to resort to one of the older interfaces, either PTRACE_PEEKUSR or PTRACE_GETFPREGS, to retrieve the missing piece of data. Also the register is irreversibly missing from core dumps.
This register is architecturally hardwired and read-only so the write path does not matter. Ignore data supplied on writes then.
Patchwork: https://patchwork.linux-mips.org/patch/19273/
--- arch/mips/kernel/ptrace.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
arch/mips/kernel/ptrace.c +16 -2
@@ -481,7 +481,7 @@ static int fpr_get_msa(struct task_struc/* * Copy the floating-point context to the supplied NT_PRFPREG buffer. * Choose the appropriate helper for general registers, and then copy -* the FCSR register separately. +* the FCSR and FIR registers separately. */ static int fpr_get(struct task_struct *target, const struct user_regset *regset,
@@ -489,6 +489,7 @@ static int fpr_get(struct task_struct *t void *kbuf, void __user *ubuf) {const int fcr31_pos =NUM_FPU_REGS *sizeof (elf_fpreg_t); +const int fir_pos = fcr31_pos +sizeof (u32);int err;if (sizeof (target->thread.fpu.fpr[0 ]) ==sizeof (elf_fpreg_t))
@@ -501,6 +502,12 @@ static int fpr_get(struct task_struct *t err =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &target->thread.fpu.fcr31, fcr31_pos, fcr31_pos +sizeof (u32)); +if (err) +return err; + + err =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + &boot_cpu_data.fpu_id, + fir_pos, fir_pos +sizeof (u32));return err; }
@@ -549,7 +556,8 @@ static int fpr_set_msa(struct task_struc/* * Copy the supplied NT_PRFPREG buffer to the floating-point context. * Choose the appropriate helper for general registers, and then copy -* the FCSR register separately. +* the FCSR register separately. Ignore the incoming FIR register +* contents though, as the register is read-only. * * We optimize for the case where `count % sizeof(elf_fpreg_t) == 0', * which is supposed to have been guaranteed by the kernel before
@@ -563,6 +571,7 @@ static int fpr_set(struct task_struct *t const void *kbuf, const void __user *ubuf) { const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t); +const int fir_pos = fcr31_pos +sizeof (u32);u32 fcr31;int err;
@@ -590,6 +599,11 @@ static int fpr_set(struct task_struct *tptrace_setfcr31 (target, fcr31); } +if (count >0 ) + err =user_regset_copyin_ignore (&pos, &count, &kbuf, &ubuf, + fir_pos, + fir_pos +sizeof (u32)); +return err; }
PATCH 307/366 KVM: Fix spelling mistake: "cop_unsuable" -> "cop_unusable"
In reply to Ben Hutchings3.16.60-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Colin Ian King <[email protected]>
commit ba3696e94d9d590d9a7e55f68e81c25dba515191 upstream.
Trivial fix to spelling mistake in debugfs_entries text.
--- arch/mips/kvm/kvm_mips.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kvm/kvm_mips.c +1 -1
@@ -38,7 +38,7 @@ struct kvm_stats_debugfs_item debugfs_en { "cache", VCPU_STAT(cache_exits) }, { "signal", VCPU_STAT(signal_exits) }, { "interrupt", VCPU_STAT(int_exits) }, - { "cop_unsuable", VCPU_STAT(cop_unusable_exits) }, + { "cop_unusable", VCPU_STAT(cop_unusable_exits) }, { "tlbmod", VCPU_STAT(tlbmod_exits) }, { "tlbmiss_ld", VCPU_STAT(tlbmiss_ld_exits) }, { "tlbmiss_st", VCPU_STAT(tlbmiss_st_exits) },