From: Greg Kroah-Hartman Date: Thu, 11 Mar 2021 18:30:58 +0000 (+0100) Subject: 4.9-stable patches X-Git-Tag: v4.4.262~132 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1cbc1d34915d066f514cfa96943996adb65b093b;p=thirdparty%2Fkernel%2Fstable-queue.git 4.9-stable patches added patches: can-flexcan-assert-frz-bit-in-flexcan_chip_freeze.patch can-flexcan-enable-rx-fifo-after-frz-halt-valid.patch can-skb-can_skb_set_owner-fix-ref-counting-if-socket-was-closed-before-setting-skb-ownership.patch netfilter-x_tables-gpf-inside-xt_find_revision.patch --- diff --git a/queue-4.9/can-flexcan-assert-frz-bit-in-flexcan_chip_freeze.patch b/queue-4.9/can-flexcan-assert-frz-bit-in-flexcan_chip_freeze.patch new file mode 100644 index 00000000000..c98ae8d8ff5 --- /dev/null +++ b/queue-4.9/can-flexcan-assert-frz-bit-in-flexcan_chip_freeze.patch @@ -0,0 +1,35 @@ +From 449052cfebf624b670faa040245d3feed770d22f Mon Sep 17 00:00:00 2001 +From: Joakim Zhang +Date: Thu, 18 Feb 2021 19:00:35 +0800 +Subject: can: flexcan: assert FRZ bit in flexcan_chip_freeze() + +From: Joakim Zhang + +commit 449052cfebf624b670faa040245d3feed770d22f upstream. + +Assert HALT bit to enter freeze mode, there is a premise that FRZ bit is +asserted. This patch asserts FRZ bit in flexcan_chip_freeze, although +the reset value is 1b'1. This is a prepare patch, later patch will +invoke flexcan_chip_freeze() to enter freeze mode, which polling freeze +mode acknowledge. + +Fixes: b1aa1c7a2165b ("can: flexcan: fix transition from and to freeze mode in chip_{,un}freeze") +Link: https://lore.kernel.org/r/20210218110037.16591-2-qiangqing.zhang@nxp.com +Signed-off-by: Joakim Zhang +Signed-off-by: Marc Kleine-Budde +Signed-off-by: Greg Kroah-Hartman +--- + drivers/net/can/flexcan.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/net/can/flexcan.c ++++ b/drivers/net/can/flexcan.c +@@ -383,7 +383,7 @@ static int flexcan_chip_freeze(struct fl + u32 reg; + + reg = flexcan_read(®s->mcr); +- reg |= FLEXCAN_MCR_HALT; ++ reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT; + flexcan_write(reg, ®s->mcr); + + while (timeout-- && !(flexcan_read(®s->mcr) & FLEXCAN_MCR_FRZ_ACK)) diff --git a/queue-4.9/can-flexcan-enable-rx-fifo-after-frz-halt-valid.patch b/queue-4.9/can-flexcan-enable-rx-fifo-after-frz-halt-valid.patch new file mode 100644 index 00000000000..a9e529bf055 --- /dev/null +++ b/queue-4.9/can-flexcan-enable-rx-fifo-after-frz-halt-valid.patch @@ -0,0 +1,53 @@ +From ec15e27cc8904605846a354bb1f808ea1432f853 Mon Sep 17 00:00:00 2001 +From: Joakim Zhang +Date: Thu, 18 Feb 2021 19:00:36 +0800 +Subject: can: flexcan: enable RX FIFO after FRZ/HALT valid + +From: Joakim Zhang + +commit ec15e27cc8904605846a354bb1f808ea1432f853 upstream. + +RX FIFO enable failed could happen when do system reboot stress test: + +[ 0.303958] flexcan 5a8d0000.can: 5a8d0000.can supply xceiver not found, using dummy regulator +[ 0.304281] flexcan 5a8d0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core +[ 0.314640] flexcan 5a8d0000.can: registering netdev failed +[ 0.320728] flexcan 5a8e0000.can: 5a8e0000.can supply xceiver not found, using dummy regulator +[ 0.320991] flexcan 5a8e0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core +[ 0.331360] flexcan 5a8e0000.can: registering netdev failed +[ 0.337444] flexcan 5a8f0000.can: 5a8f0000.can supply xceiver not found, using dummy regulator +[ 0.337716] flexcan 5a8f0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core +[ 0.348117] flexcan 5a8f0000.can: registering netdev failed + +RX FIFO should be enabled after the FRZ/HALT are valid. But the current +code enable RX FIFO and FRZ/HALT at the same time. + +Fixes: e955cead03117 ("CAN: Add Flexcan CAN controller driver") +Link: https://lore.kernel.org/r/20210218110037.16591-3-qiangqing.zhang@nxp.com +Signed-off-by: Joakim Zhang +Signed-off-by: Marc Kleine-Budde +Signed-off-by: Greg Kroah-Hartman +--- + drivers/net/can/flexcan.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +--- a/drivers/net/can/flexcan.c ++++ b/drivers/net/can/flexcan.c +@@ -1098,10 +1098,14 @@ static int register_flexcandev(struct ne + if (err) + goto out_chip_disable; + +- /* set freeze, halt and activate FIFO, restrict register access */ ++ /* set freeze, halt */ ++ err = flexcan_chip_freeze(priv); ++ if (err) ++ goto out_chip_disable; ++ ++ /* activate FIFO, restrict register access */ + reg = flexcan_read(®s->mcr); +- reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT | +- FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV; ++ reg |= FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV; + flexcan_write(reg, ®s->mcr); + + /* Currently we only support newer versions of this core diff --git a/queue-4.9/can-skb-can_skb_set_owner-fix-ref-counting-if-socket-was-closed-before-setting-skb-ownership.patch b/queue-4.9/can-skb-can_skb_set_owner-fix-ref-counting-if-socket-was-closed-before-setting-skb-ownership.patch new file mode 100644 index 00000000000..e0284cd23d5 --- /dev/null +++ b/queue-4.9/can-skb-can_skb_set_owner-fix-ref-counting-if-socket-was-closed-before-setting-skb-ownership.patch @@ -0,0 +1,71 @@ +From e940e0895a82c6fbaa259f2615eb52b57ee91a7e Mon Sep 17 00:00:00 2001 +From: Oleksij Rempel +Date: Fri, 26 Feb 2021 10:24:56 +0100 +Subject: can: skb: can_skb_set_owner(): fix ref counting if socket was closed before setting skb ownership + +From: Oleksij Rempel + +commit e940e0895a82c6fbaa259f2615eb52b57ee91a7e upstream. + +There are two ref count variables controlling the free()ing of a socket: +- struct sock::sk_refcnt - which is changed by sock_hold()/sock_put() +- struct sock::sk_wmem_alloc - which accounts the memory allocated by + the skbs in the send path. + +In case there are still TX skbs on the fly and the socket() is closed, +the struct sock::sk_refcnt reaches 0. In the TX-path the CAN stack +clones an "echo" skb, calls sock_hold() on the original socket and +references it. This produces the following back trace: + +| WARNING: CPU: 0 PID: 280 at lib/refcount.c:25 refcount_warn_saturate+0x114/0x134 +| refcount_t: addition on 0; use-after-free. +| Modules linked in: coda_vpu(E) v4l2_jpeg(E) videobuf2_vmalloc(E) imx_vdoa(E) +| CPU: 0 PID: 280 Comm: test_can.sh Tainted: G E 5.11.0-04577-gf8ff6603c617 #203 +| Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree) +| Backtrace: +| [<80bafea4>] (dump_backtrace) from [<80bb0280>] (show_stack+0x20/0x24) r7:00000000 r6:600f0113 r5:00000000 r4:81441220 +| [<80bb0260>] (show_stack) from [<80bb593c>] (dump_stack+0xa0/0xc8) +| [<80bb589c>] (dump_stack) from [<8012b268>] (__warn+0xd4/0x114) r9:00000019 r8:80f4a8c2 r7:83e4150c r6:00000000 r5:00000009 r4:80528f90 +| [<8012b194>] (__warn) from [<80bb09c4>] (warn_slowpath_fmt+0x88/0xc8) r9:83f26400 r8:80f4a8d1 r7:00000009 r6:80528f90 r5:00000019 r4:80f4a8c2 +| [<80bb0940>] (warn_slowpath_fmt) from [<80528f90>] (refcount_warn_saturate+0x114/0x134) r8:00000000 r7:00000000 r6:82b44000 r5:834e5600 r4:83f4d540 +| [<80528e7c>] (refcount_warn_saturate) from [<8079a4c8>] (__refcount_add.constprop.0+0x4c/0x50) +| [<8079a47c>] (__refcount_add.constprop.0) from [<8079a57c>] (can_put_echo_skb+0xb0/0x13c) +| [<8079a4cc>] (can_put_echo_skb) from [<8079ba98>] (flexcan_start_xmit+0x1c4/0x230) r9:00000010 r8:83f48610 r7:0fdc0000 r6:0c080000 r5:82b44000 r4:834e5600 +| [<8079b8d4>] (flexcan_start_xmit) from [<80969078>] (netdev_start_xmit+0x44/0x70) r9:814c0ba0 r8:80c8790c r7:00000000 r6:834e5600 r5:82b44000 r4:82ab1f00 +| [<80969034>] (netdev_start_xmit) from [<809725a4>] (dev_hard_start_xmit+0x19c/0x318) r9:814c0ba0 r8:00000000 r7:82ab1f00 r6:82b44000 r5:00000000 r4:834e5600 +| [<80972408>] (dev_hard_start_xmit) from [<809c6584>] (sch_direct_xmit+0xcc/0x264) r10:834e5600 r9:00000000 r8:00000000 r7:82b44000 r6:82ab1f00 r5:834e5600 r4:83f27400 +| [<809c64b8>] (sch_direct_xmit) from [<809c6c0c>] (__qdisc_run+0x4f0/0x534) + +To fix this problem, only set skb ownership to sockets which have still +a ref count > 0. + +Fixes: 0ae89beb283a ("can: add destructor for self generated skbs") +Cc: Oliver Hartkopp +Cc: Andre Naujoks +Link: https://lore.kernel.org/r/20210226092456.27126-1-o.rempel@pengutronix.de +Suggested-by: Eric Dumazet +Signed-off-by: Oleksij Rempel +Reviewed-by: Oliver Hartkopp +Signed-off-by: Marc Kleine-Budde +Signed-off-by: Greg Kroah-Hartman +--- + include/linux/can/skb.h | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +--- a/include/linux/can/skb.h ++++ b/include/linux/can/skb.h +@@ -48,8 +48,12 @@ static inline void can_skb_reserve(struc + + static inline void can_skb_set_owner(struct sk_buff *skb, struct sock *sk) + { +- if (sk) { +- sock_hold(sk); ++ /* If the socket has already been closed by user space, the ++ * refcount may already be 0 (and the socket will be freed ++ * after the last TX skb has been freed). So only increase ++ * socket refcount if the refcount is > 0. ++ */ ++ if (sk && atomic_inc_not_zero(&sk->sk_refcnt)) { + skb->destructor = sock_efree; + skb->sk = sk; + } diff --git a/queue-4.9/netfilter-x_tables-gpf-inside-xt_find_revision.patch b/queue-4.9/netfilter-x_tables-gpf-inside-xt_find_revision.patch new file mode 100644 index 00000000000..71d697dc7cd --- /dev/null +++ b/queue-4.9/netfilter-x_tables-gpf-inside-xt_find_revision.patch @@ -0,0 +1,89 @@ +From 8e24edddad152b998b37a7f583175137ed2e04a5 Mon Sep 17 00:00:00 2001 +From: Vasily Averin +Date: Sat, 27 Feb 2021 11:27:45 +0300 +Subject: netfilter: x_tables: gpf inside xt_find_revision() + +From: Vasily Averin + +commit 8e24edddad152b998b37a7f583175137ed2e04a5 upstream. + +nested target/match_revfn() calls work with xt[NFPROTO_UNSPEC] lists +without taking xt[NFPROTO_UNSPEC].mutex. This can race with module unload +and cause host to crash: + +general protection fault: 0000 [#1] +Modules linked in: ... [last unloaded: xt_cluster] +CPU: 0 PID: 542455 Comm: iptables +RIP: 0010:[] [] strcmp+0x18/0x40 +RDX: 0000000000000003 RSI: ffff9a5a5d9abe10 RDI: dead000000000111 +R13: ffff9a5a5d9abe10 R14: ffff9a5a5d9abd8c R15: dead000000000100 +(VvS: %R15 -- &xt_match, %RDI -- &xt_match.name, +xt_cluster unregister match in xt[NFPROTO_UNSPEC].match list) +Call Trace: + [] match_revfn+0x54/0xc0 + [] match_revfn+0xaf/0xc0 + [] xt_find_revision+0x6e/0xf0 + [] do_ipt_get_ctl+0x100/0x420 [ip_tables] + [] nf_getsockopt+0x4f/0x70 + [] ip_getsockopt+0xde/0x100 + [] raw_getsockopt+0x25/0x50 + [] sock_common_getsockopt+0x1a/0x20 + [] SyS_getsockopt+0x7d/0xf0 + [] system_call_fastpath+0x25/0x2a + +Fixes: 656caff20e1 ("netfilter 04/09: x_tables: fix match/target revision lookup") +Signed-off-by: Vasily Averin +Reviewed-by: Florian Westphal +Signed-off-by: Pablo Neira Ayuso +Signed-off-by: Greg Kroah-Hartman +--- + net/netfilter/x_tables.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +--- a/net/netfilter/x_tables.c ++++ b/net/netfilter/x_tables.c +@@ -272,6 +272,7 @@ static int match_revfn(u8 af, const char + const struct xt_match *m; + int have_rev = 0; + ++ mutex_lock(&xt[af].mutex); + list_for_each_entry(m, &xt[af].match, list) { + if (strcmp(m->name, name) == 0) { + if (m->revision > *bestp) +@@ -280,6 +281,7 @@ static int match_revfn(u8 af, const char + have_rev = 1; + } + } ++ mutex_unlock(&xt[af].mutex); + + if (af != NFPROTO_UNSPEC && !have_rev) + return match_revfn(NFPROTO_UNSPEC, name, revision, bestp); +@@ -292,6 +294,7 @@ static int target_revfn(u8 af, const cha + const struct xt_target *t; + int have_rev = 0; + ++ mutex_lock(&xt[af].mutex); + list_for_each_entry(t, &xt[af].target, list) { + if (strcmp(t->name, name) == 0) { + if (t->revision > *bestp) +@@ -300,6 +303,7 @@ static int target_revfn(u8 af, const cha + have_rev = 1; + } + } ++ mutex_unlock(&xt[af].mutex); + + if (af != NFPROTO_UNSPEC && !have_rev) + return target_revfn(NFPROTO_UNSPEC, name, revision, bestp); +@@ -313,12 +317,10 @@ int xt_find_revision(u8 af, const char * + { + int have_rev, best = -1; + +- mutex_lock(&xt[af].mutex); + if (target == 1) + have_rev = target_revfn(af, name, revision, &best); + else + have_rev = match_revfn(af, name, revision, &best); +- mutex_unlock(&xt[af].mutex); + + /* Nothing at all? Return 0 to try loading module. */ + if (best == -1) { diff --git a/queue-4.9/series b/queue-4.9/series index 38c2d091634..48d32c170f6 100644 --- a/queue-4.9/series +++ b/queue-4.9/series @@ -3,3 +3,7 @@ ethernet-alx-fix-order-of-calls-on-resume.patch ath9k-fix-transmitting-to-stations-in-dynamic-smps-mode.patch net-fix-gro-aggregation-for-udp-encaps-with-zero-csum.patch net-avoid-infinite-loop-in-mpls_gso_segment-when-mpls_hlen-0.patch +can-skb-can_skb_set_owner-fix-ref-counting-if-socket-was-closed-before-setting-skb-ownership.patch +can-flexcan-assert-frz-bit-in-flexcan_chip_freeze.patch +can-flexcan-enable-rx-fifo-after-frz-halt-valid.patch +netfilter-x_tables-gpf-inside-xt_find_revision.patch