6.1.175-rc1 review
Subsystems (7)
Greg Kroah-Hartman
maintainerPATCH 684/969 net/sched: taprio: rename close_time to end_time
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Oltean <[email protected]>
[ Upstream commit e5517551112ff2395611e552443932152f83672d ]
There is a confusion in terms in taprio which makes what is called "close_time" to be actually used for 2 things:
1. determining when an entry "closes" such that transmitted skbs are never allowed to overrun that time (?!)
2. an aid for determining when to advance and/or restart the schedule using the hrtimer
It makes more sense to call this so-called "close_time" "end_time", because it's not clear at all to me what "closes". Future patches will hopefully make better use of the term "to close".
This is an absolutely mechanical change.
Stable-dep-of: 105425b1969c ("net/sched: taprio: fix use-after-free in advance_sched() on schedule switch")
--- net/sched/sch_taprio.c | 52 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-)
net/sched/sch_taprio.c +26 -26
@@ -37,11 +37,11 @@ static LIST_HEAD(taprio_list);struct sched_entry {struct list_head list; -/* The instant that this entry "closes" and the next one +/* The instant that this entry ends and the next one * should open, the qdisc will make some effort so that no * packet leaves after this time. */ -ktime_t close_time; +ktime_t end_time;ktime_t next_txtime;atomic_t budget;int index;
@@ -54,7 +54,7 @@ struct sched_gate_list {struct rcu_head rcu;struct list_head entries;size_t num_entries; -ktime_t cycle_close_time; +ktime_t cycle_end_time;s64 cycle_time;s64 cycle_time_extension;s64 base_time;
@@ -591,7 +591,7 @@ static struct sk_buff *taprio_dequeue_from_txq(struct Qdisc *sch, int txq,* guard band ... */ if (gate_mask !=TAPRIO_ALL_GATES_OPEN && -ktime_after (guard, entry->close_time)) +ktime_after (guard, entry->end_time))return NULL ;/* ... and no budget. */
@@ -653,7 +653,7 @@ static bool should_restart_cycle(const struct sched_gate_list *oper,if (list_is_last (&entry->list, &oper->entries))return true; -if (ktime_compare (entry->close_time, oper->cycle_close_time) ==0 ) +if (ktime_compare (entry->end_time, oper->cycle_end_time) ==0 )return true;return false;
@@ -661,7 +661,7 @@ static bool should_restart_cycle(const struct sched_gate_list *oper,static bool should_change_schedules (const struct sched_gate_list *admin,const struct sched_gate_list *oper, -ktime_t close_time) +ktime_t end_time) {ktime_t next_base_time, extension_time;
@@ -670,18 +670,18 @@ static bool should_change_schedules(const struct sched_gate_list *admin, next_base_time =sched_base_time (admin); -/* This is the simple case, the close_time would fall after +/* This is the simple case, the end_time would fall after * the next schedule base_time. */ -if (ktime_compare (next_base_time, close_time) <=0 ) +if (ktime_compare (next_base_time, end_time) <=0 )return true; -/* This is the cycle_time_extension case, if the close_time +/* This is the cycle_time_extension case, if the end_time * plus the amount that can be extended would fall after the * next schedule base_time, we can extend the current schedule * for that amount. */ - extension_time =ktime_add_ns (close_time, oper->cycle_time_extension); + extension_time =ktime_add_ns (end_time, oper->cycle_time_extension);/* FIXME: the IEEE 802.1Q-2018 Specification isn't clear about * how precisely the extension should be made. So after
@@ -700,7 +700,7 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer)struct sched_gate_list *oper, *admin;struct sched_entry *entry, *next;struct Qdisc *sch = q->root; -ktime_t close_time; +ktime_t end_time;spin_lock (&q->current_entry_lock); entry = rcu_dereference_protected(q->current_entry,
@@ -719,41 +719,41 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer)* entry of all schedules are pre-calculated during the * schedule initialization. */ -if (unlikely (!entry || entry->close_time == oper->base_time)) { +if (unlikely (!entry || entry->end_time == oper->base_time)) { next = list_first_entry(&oper->entries, struct sched_entry, list); - close_time = next->close_time; + end_time = next->end_time; goto first_run; }if (should_restart_cycle (oper, entry)) { next = list_first_entry(&oper->entries, struct sched_entry, list); - oper->cycle_close_time =ktime_add_ns (oper->cycle_close_time, - oper->cycle_time); + oper->cycle_end_time =ktime_add_ns (oper->cycle_end_time, + oper->cycle_time); }else { next =list_next_entry (entry, list); } - close_time =ktime_add_ns (entry->close_time, next->interval); - close_time =min_t (ktime_t, close_time, oper->cycle_close_time); + end_time =ktime_add_ns (entry->end_time, next->interval); + end_time =min_t (ktime_t, end_time, oper->cycle_end_time); -if (should_change_schedules (admin, oper, close_time)) { +if (should_change_schedules (admin, oper, end_time)) {/* Set things so the next time this runs, the new * schedule runs. */ - close_time =sched_base_time (admin); + end_time =sched_base_time (admin);switch_schedules (q, &admin, &oper); } - next->close_time = close_time; + next->end_time = end_time;taprio_set_budget (q, next); first_run:rcu_assign_pointer (q->current_entry, next);spin_unlock (&q->current_entry_lock); -hrtimer_set_expires (&q->advance_timer, close_time); +hrtimer_set_expires (&q->advance_timer, end_time);rcu_read_lock ();__netif_schedule (sch);
@@ -1033,8 +1033,8 @@ static int taprio_get_start_time(struct Qdisc *sch,return 0 ; } -static void setup_first_close_time (struct taprio_sched *q, -struct sched_gate_list *sched,ktime_t base) +static void setup_first_end_time (struct taprio_sched *q, +struct sched_gate_list *sched,ktime_t base) {struct sched_entry *first;ktime_t cycle;
@@ -1045,9 +1045,9 @@ static void setup_first_close_time(struct taprio_sched *q, cycle = sched->cycle_time;/* FIXME: find a better place to do this */ - sched->cycle_close_time =ktime_add_ns (base, cycle); + sched->cycle_end_time =ktime_add_ns (base, cycle); - first->close_time =ktime_add_ns (base, first->interval); + first->end_time =ktime_add_ns (base, first->interval);taprio_set_budget (q, first);rcu_assign_pointer (q->current_entry,NULL ); }
@@ -1679,7 +1679,7 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,if (admin)call_rcu (&admin->rcu, taprio_free_sched_cb); }else { -setup_first_close_time (q, new_admin, start); +setup_first_end_time (q, new_admin, start);/* Protects against advance_sched() */ spin_lock_irqsave (&q->current_entry_lock, flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 685/969 net/sched: taprio: fix use-after-free in advance_sched() on schedule switch
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vinicius Costa Gomes <[email protected]>
[ Upstream commit 105425b1969c5affe532713cfac1c0b320d7ac2b ]
In advance_sched(), when should_change_schedules() returns true, switch_schedules() is called to promote the admin schedule to oper. switch_schedules() queues the old oper schedule for RCU freeing via call_rcu(), but 'next' still points into an entry of the old oper schedule. The subsequent 'next->end_time = end_time' and rcu_assign_pointer(q->current_entry, next) are use-after-free.
Fix this by selecting 'next' from the new oper schedule immediately after switch_schedules(), and using its pre-calculated end_time. setup_first_end_time() sets the first entry's end_time to base_time + interval when the schedule is installed, so the value is already correct.
The deleted 'end_time = sched_base_time(admin)' assignment was also harmful independently: it would overwrite the new first entry's pre-calculated end_time with just base_time.
--- net/sched/sch_taprio.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/sched/sch_taprio.c +5 -4
@@ -739,11 +739,12 @@ static enum hrtimer_restart advance_sched(struct hrtimer *timer) end_time =min_t (ktime_t, end_time, oper->cycle_end_time);if (should_change_schedules (admin, oper, end_time)) { -/* Set things so the next time this runs, the new -* schedule runs. -*/ - end_time =sched_base_time (admin);switch_schedules (q, &admin, &oper); +/* After changing schedules, the next entry is the first one +* in the new schedule, with a pre-calculated end_time. +*/ + next = list_first_entry(&oper->entries, struct sched_entry, list); + end_time = next->end_time; } next->end_time = end_time;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 686/969 container_of: remove container_of_safe()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit 848dba781f1951636c966c9f3a6a41a5b2f8b572 ]
It came in from a staging driver that has been long removed from the tree, and there are no in-kernel users of the macro, and it's very dubious if anyone should ever use this thing, so just remove it entirely.
Stable-dep-of: 21e92a38cfd8 ("tcp: add data-race annotations around tp->data_segs_out and tp->total_retrans")
--- include/linux/container_of.h | 16 ---------------- 1 file changed, 16 deletions(-)
include/linux/container_of.h +0 -16
@@ -21,20 +21,4 @@ "pointer type mismatch in container_of()"); \ ((type *)(__mptr - offsetof(type, member))); }) -/** -* container_of_safe - cast a member of a structure out to the containing structure -* @ptr: the pointer to the member. -* @type: the type of the container struct this is embedded in. -* @member: the name of the member within the struct. -* -* If IS_ERR_OR_NULL(ptr), ptr is returned unchanged. -*/ -#define container_of_safe (ptr, type, member) ({ \ - void *__mptr = (void *)(ptr); \ - static_assert(__same_type(*(ptr), ((type *)0)->member) || \ - __same_type(*(ptr), void), \ - "pointer type mismatch in container_of_safe()"); \ - IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) : \ - ((type *)(__mptr - offsetof(type, member))); }) -#endif /* _LINUX_CONTAINER_OF_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 687/969 container_of: add container_of_const() that preserves const-ness of the pointer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit 64f6a5d1922bf6d2b2d845de20d4563a6f328e2d ]
container_of does not preserve the const-ness of a pointer that is passed into it, which can cause C code that passes in a const pointer to get a pointer back that is not const and then scribble all over the data in it. To prevent this, container_of_const() will preserve the const status of the pointer passed into it using the newly available _Generic() method.
Stable-dep-of: 21e92a38cfd8 ("tcp: add data-race annotations around tp->data_segs_out and tp->total_retrans")
--- include/linux/container_of.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/container_of.h +13 -0
@@ -21,4 +21,17 @@ "pointer type mismatch in container_of()"); \ ((type *)(__mptr - offsetof(type, member))); }) +/** +* container_of_const - cast a member of a structure out to the containing +* structure and preserve the const-ness of the pointer +* @ptr: the pointer to the member +* @type: the type of the container struct this is embedded in. +* @member: the name of the member within the struct. +*/ +#define container_of_const (ptr, type, member) \ + _Generic(ptr, \ + const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\ + default: ((type *)container_of(ptr, type, member)) \ + ) +#endif /* _LINUX_CONTAINER_OF_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 688/969 tcp: preserve const qualifier in tcp_sk()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit e9d9da91548b21e189fcd0259a0f2d26d1afc509 ]
We can change tcp_sk() to propagate its argument const qualifier, thanks to container_of_const().
We have two places where a const sock pointer has to be upgraded to a write one. We have been using const qualifier for lockless listeners to clearly identify points where writes could happen.
Add tcp_sk_rw() helper to better document these.
tcp_inbound_md5_hash(), __tcp_grow_window(), tcp_reset_check() and tcp_rack_reo_wnd() get an additional const qualififer for their @tp local variables.
smc_check_reset_syn_req() also needs a similar change.
Stable-dep-of: 21e92a38cfd8 ("tcp: add data-race annotations around tp->data_segs_out and tp->total_retrans")
--- include/linux/tcp.h | 10 ++++++---- include/net/tcp.h | 2 +- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_input.c | 4 ++-- net/ipv4/tcp_minisocks.c | 5 +++-- net/ipv4/tcp_output.c | 9 +++++++-- net/ipv4/tcp_recovery.c | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-)
include/linux/tcp.h +6 -4
@@ -471,10 +471,12 @@ enum tsq_flags { TCPF_MTU_REDUCED_DEFERRED = (1UL << TCP_MTU_REDUCED_DEFERRED), }; -static inline struct tcp_sock *tcp_sk (const struct sock *sk) -{ -return (struct tcp_sock *)sk; -} +#define tcp_sk (ptr) container_of_const(ptr, struct tcp_sock, inet_conn.icsk_inet.sk) + +/* Variant of tcp_sk() upgrading a const sock to a read/write tcp socket. +* Used in context of (lockless) tcp listeners. +*/ +#define tcp_sk_rw (ptr) container_of(ptr, struct tcp_sock, inet_conn.icsk_inet.sk)struct tcp_timewait_sock {struct inet_timewait_sock tw_sk;
include/net/tcp.h +1 -1
@@ -535,7 +535,7 @@ static inline void tcp_synq_overflow(const struct sock *sk) last_overflow =READ_ONCE (tcp_sk (sk)->rx_opt.ts_recent_stamp);if (!time_between32 (now, last_overflow, last_overflow +HZ )) -WRITE_ONCE (tcp_sk (sk)->rx_opt.ts_recent_stamp, now); +WRITE_ONCE (tcp_sk_rw (sk)->rx_opt.ts_recent_stamp, now); }/* syncookies: no recent synqueue overflow on this listening socket? */
net/ipv4/tcp.c +1 -1
@@ -4642,7 +4642,7 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,const __u8 *hash_location =NULL ;struct tcp_md5sig_key *hash_expected;const struct tcphdr *th =tcp_hdr (skb); -struct tcp_sock *tp =tcp_sk (sk); +const struct tcp_sock *tp =tcp_sk (sk);int genhash, l3index;u8 newhash[16 ];
net/ipv4/tcp_input.c +2 -2
@@ -484,7 +484,7 @@ static void tcp_sndbuf_expand(struct sock *sk)static int __tcp_grow_window (const struct sock *sk,const struct sk_buff *skb,unsigned int skbtruesize) { -struct tcp_sock *tp =tcp_sk (sk); +const struct tcp_sock *tp =tcp_sk (sk);/* Optimize this! */ int truesize =tcp_win_from_space (sk, skbtruesize) >>1 ;int window =tcp_win_from_space (sk,READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_rmem[2 ])) >>1 ;
@@ -5783,7 +5783,7 @@ static void tcp_urg(struct sock *sk, struct sk_buff *skb, const struct tcphdr *t*/ static bool tcp_reset_check(const struct sock *sk, const struct sk_buff *skb) { - struct tcp_sock *tp = tcp_sk(sk); + const struct tcp_sock *tp = tcp_sk(sk); return unlikely(TCP_SKB_CB(skb)->seq == (tp->rcv_nxt - 1) && (1 << sk->sk_state) & (TCPF_CLOSE_WAIT | TCPF_LAST_ACK |
net/ipv4/tcp_minisocks.c +3 -2
@@ -441,7 +441,7 @@ void tcp_ca_openreq_child(struct sock *sk, const struct dst_entry *dst) }EXPORT_SYMBOL_GPL (tcp_ca_openreq_child); -static void smc_check_reset_syn_req (struct tcp_sock *oldtp, +static void smc_check_reset_syn_req (const struct tcp_sock *oldtp,struct request_sock *req,struct tcp_sock *newtp) {
@@ -470,7 +470,8 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,const struct inet_request_sock *ireq =inet_rsk (req);struct tcp_request_sock *treq =tcp_rsk (req);struct inet_connection_sock *newicsk; -struct tcp_sock *oldtp, *newtp; +const struct tcp_sock *oldtp; +struct tcp_sock *newtp;u32 seq;if (!newsk)
net/ipv4/tcp_output.c +7 -2
@@ -4203,8 +4203,13 @@ int tcp_rtx_synack(const struct sock *sk, struct request_sock *req)if (!res) {TCP_INC_STATS (sock_net (sk),TCP_MIB_RETRANSSEGS );NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPSYNRETRANS ); -if (unlikely (tcp_passive_fastopen (sk))) -tcp_sk (sk)->total_retrans++; +if (unlikely (tcp_passive_fastopen (sk))) { +/* sk has const attribute because listeners are lockless. +* However in this case, we are dealing with a passive fastopen +* socket thus we can change total_retrans value. +*/ +tcp_sk_rw (sk)->total_retrans++; + }trace_tcp_retransmit_synack (sk, req); }return res;
net/ipv4/tcp_recovery.c +1 -1
@@ -4,7 +4,7 @@static u32 tcp_rack_reo_wnd (const struct sock *sk) { -struct tcp_sock *tp =tcp_sk (sk); +const struct tcp_sock *tp =tcp_sk (sk);if (!tp->reord_seen) {/* If reordering has not been observed, be aggressive during
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 689/969 tcp: add data-race annotations around tp->data_segs_out and tp->total_retrans
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 21e92a38cfd891538598ba8f805e0165a820d532 ]
tcp_get_timestamping_opt_stats() intentionally runs lockless, we must add READ_ONCE() and WRITE_ONCE() annotations to keep KCSAN happy.
--- net/ipv4/tcp.c | 4 ++-- net/ipv4/tcp_output.c | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-)
net/ipv4/tcp.c +2 -2
@@ -4084,9 +4084,9 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,nla_put_u64_64bit (stats,TCP_NLA_SNDBUF_LIMITED , info.tcpi_sndbuf_limited,TCP_NLA_PAD );nla_put_u64_64bit (stats,TCP_NLA_DATA_SEGS_OUT , - tp->data_segs_out,TCP_NLA_PAD ); +READ_ONCE (tp->data_segs_out),TCP_NLA_PAD );nla_put_u64_64bit (stats,TCP_NLA_TOTAL_RETRANS , - tp->total_retrans,TCP_NLA_PAD ); +READ_ONCE (tp->total_retrans),TCP_NLA_PAD ); rate =READ_ONCE (sk->sk_pacing_rate); rate64 = (rate != ~0UL ) ? rate : ~0ULL ;
net/ipv4/tcp_output.c +5 -3
@@ -1380,7 +1380,8 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,if (skb->len != tcp_header_size) {tcp_event_data_sent (tp, sk); - tp->data_segs_out +=tcp_skb_pcount (skb); +WRITE_ONCE (tp->data_segs_out, + tp->data_segs_out +tcp_skb_pcount (skb)); tp->bytes_sent += skb->len - tcp_header_size; }
@@ -3286,7 +3287,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)TCP_ADD_STATS (sock_net (sk),TCP_MIB_RETRANSSEGS , segs);if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_SYN )__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPSYNRETRANS ); - tp->total_retrans += segs; +WRITE_ONCE (tp->total_retrans, tp->total_retrans + segs); tp->bytes_retrans += skb->len;/* make sure skb->data is aligned on arches that require it
@@ -4208,7 +4209,8 @@ int tcp_rtx_synack(const struct sock *sk, struct request_sock *req)* However in this case, we are dealing with a passive fastopen * socket thus we can change total_retrans value. */ -tcp_sk_rw (sk)->total_retrans++; +WRITE_ONCE (tcp_sk_rw (sk)->total_retrans, +tcp_sk_rw (sk)->total_retrans +1 ); }trace_tcp_retransmit_synack (sk, req); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 690/969 tcp: annotate data-races around tp->bytes_sent
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit ee43e957ce2ec77b2ec47fef28f3c0df6ab01a31 ]
tcp_get_timestamping_opt_stats() intentionally runs lockless, we must add READ_ONCE() and WRITE_ONCE() annotations to keep KCSAN happy.
--- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_output.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +1 -1
@@ -4108,7 +4108,7 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,nla_put_u32 (stats,TCP_NLA_SNDQ_SIZE , tp->write_seq - tp->snd_una);nla_put_u8 (stats,TCP_NLA_CA_STATE ,inet_csk (sk)->icsk_ca_state); -nla_put_u64_64bit (stats,TCP_NLA_BYTES_SENT , tp->bytes_sent, +nla_put_u64_64bit (stats,TCP_NLA_BYTES_SENT ,READ_ONCE (tp->bytes_sent),TCP_NLA_PAD );nla_put_u64_64bit (stats,TCP_NLA_BYTES_RETRANS , tp->bytes_retrans,TCP_NLA_PAD );
net/ipv4/tcp_output.c +2 -1
@@ -1382,7 +1382,8 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,tcp_event_data_sent (tp, sk);WRITE_ONCE (tp->data_segs_out, tp->data_segs_out +tcp_skb_pcount (skb)); - tp->bytes_sent += skb->len - tcp_header_size; +WRITE_ONCE (tp->bytes_sent, + tp->bytes_sent + skb->len - tcp_header_size); }if (after (tcb->end_seq, tp->snd_nxt) || tcb->seq == tcb->end_seq)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 691/969 tcp: annotate data-races around tp->bytes_retrans
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 5efc7b9f7cbd43401f1af81d3d7f2be00f93390d ]
tcp_get_timestamping_opt_stats() intentionally runs lockless, we must add READ_ONCE() and WRITE_ONCE() annotations to keep KCSAN happy.
--- net/ipv4/tcp.c | 4 ++-- net/ipv4/tcp_output.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
net/ipv4/tcp.c +2 -2
@@ -4110,8 +4110,8 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,nla_put_u64_64bit (stats,TCP_NLA_BYTES_SENT ,READ_ONCE (tp->bytes_sent),TCP_NLA_PAD ); -nla_put_u64_64bit (stats,TCP_NLA_BYTES_RETRANS , tp->bytes_retrans, -TCP_NLA_PAD ); +nla_put_u64_64bit (stats,TCP_NLA_BYTES_RETRANS , +READ_ONCE (tp->bytes_retrans),TCP_NLA_PAD );nla_put_u32 (stats,TCP_NLA_DSACK_DUPS , tp->dsack_dups);nla_put_u32 (stats,TCP_NLA_REORD_SEEN , tp->reord_seen);nla_put_u32 (stats,TCP_NLA_SRTT , tp->srtt_us >>3 );
net/ipv4/tcp_output.c +1 -1
@@ -3289,7 +3289,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_SYN )__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPSYNRETRANS );WRITE_ONCE (tp->total_retrans, tp->total_retrans + segs); - tp->bytes_retrans += skb->len; +WRITE_ONCE (tp->bytes_retrans, tp->bytes_retrans + skb->len);/* make sure skb->data is aligned on arches that require it * and check if ack-trimming & collapsing extended the headroom
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 692/969 tcp: annotate data-races around tp->dsack_dups
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit a984705ca88b976bf1087978fd98b7f3993da88c ]
tcp_get_timestamping_opt_stats() intentionally runs lockless, we must add READ_ONCE() and WRITE_ONCE() annotations to keep KCSAN happy.
--- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_input.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +1 -1
@@ -4112,7 +4112,7 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk, TCP_NLA_PAD);nla_put_u64_64bit (stats,TCP_NLA_BYTES_RETRANS ,READ_ONCE (tp->bytes_retrans),TCP_NLA_PAD ); -nla_put_u32 (stats,TCP_NLA_DSACK_DUPS , tp->dsack_dups); +nla_put_u32 (stats,TCP_NLA_DSACK_DUPS ,READ_ONCE (tp->dsack_dups));nla_put_u32 (stats,TCP_NLA_REORD_SEEN , tp->reord_seen);nla_put_u32 (stats,TCP_NLA_SRTT , tp->srtt_us >>3 );nla_put_u16 (stats,TCP_NLA_TIMEOUT_REHASH , tp->timeout_rehash);
net/ipv4/tcp_input.c +1 -1
@@ -1023,7 +1023,7 @@ static u32 tcp_dsack_seen(struct tcp_sock *tp, u32 start_seq,else if (tp->tlp_high_seq && tp->tlp_high_seq == end_seq) state->flag |=FLAG_DSACK_TLP ; - tp->dsack_dups += dup_segs; +WRITE_ONCE (tp->dsack_dups, tp->dsack_dups + dup_segs);/* Skip the DSACK if dup segs weren't retransmitted by sender */ if (tp->dsack_dups > tp->total_retrans)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 693/969 tcp: annotate data-races around (tp->write_seq - tp->snd_nxt)
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 3a63b3d160560ef51e43fb4c880a5cde8078053c ]
tcp_get_timestamping_opt_stats() intentionally runs lockless, we must add READ_ONCE() annotations to keep KCSAN happy.
WRITE_ONCE() annotations are already present.
--- net/ipv4/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/tcp.c +2 -1
@@ -4117,7 +4117,8 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,nla_put_u32 (stats,TCP_NLA_SRTT , tp->srtt_us >>3 );nla_put_u16 (stats,TCP_NLA_TIMEOUT_REHASH , tp->timeout_rehash);nla_put_u32 (stats,TCP_NLA_BYTES_NOTSENT , -max_t (int,0 , tp->write_seq - tp->snd_nxt)); +max_t (int,0 , +READ_ONCE (tp->write_seq) -READ_ONCE (tp->snd_nxt)));nla_put_u64_64bit (stats,TCP_NLA_EDT , orig_skb->skb_mstamp_ns,TCP_NLA_PAD );if (ack_skb)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 694/969 i40e: dont advertise IFF_SUPP_NOFCS
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kohei Enju <[email protected]>
[ Upstream commit a24162f18825684ad04e3a5d0531f8a50d679347 ]
i40e advertises IFF_SUPP_NOFCS, allowing users to use the SO_NOFCS socket option. However, this option is silently ignored, as the driver does not check skb->no_fcs, and always enables FCS insertion offload.
Fix this by removing the advertisement of IFF_SUPP_NOFCS.
This behavior can be reproduced with a simple AF_PACKET socket:
import socket
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW) s.setsockopt(socket.SOL_SOCKET, 43, 1) # SO_NOFCS s.bind(("eth0", 0))
s.send(b'\xff' * 64)
Previously, send() succeeds but the driver ignores SO_NOFCS. With this change, send() fails with -EPROTONOSUPPORT, as expected.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +0 -1
@@ -13864,7 +13864,6 @@ static int i40e_config_netdev(struct i40e_vsi *vsi) netdev->neigh_priv_len =sizeof (u32) *4 ; netdev->priv_flags |=IFF_UNICAST_FLT ; - netdev->priv_flags |=IFF_SUPP_NOFCS ;/* Setup netdev TC information */ i40e_vsi_config_netdev_tc (vsi, vsi->tc_config.enabled_tc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 695/969 e1000e: Unroll PTP in probe error handling
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Vollrath <[email protected]>
[ Upstream commit aa3f7fe409350857c25d050482a2eef2cfd69b58 ]
If probe fails after registering the PTP clock and its delayed work, these resources must be released.
This was not an issue until a 2016 fix moved the e1000e_ptp_init() call before the jump to err_register.
--- drivers/net/ethernet/intel/e1000e/netdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/e1000e/netdev.c +1 -0
@@ -7695,6 +7695,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_register:if (!(adapter->flags &FLAG_HAS_AMT ))e1000e_release_hw_control (adapter); +e1000e_ptp_remove (adapter); err_eeprom:if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block (hw))e1000_phy_hw_reset (&adapter->hw);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 696/969 ipv6: fix possible UAF in icmpv6_rcv()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit f996edd7615e686ada141b7f3395025729ff8ccb ]
Caching saddr and daddr before pskb_pull() is problematic since skb->head can change.
Remove these temporary variables:
- We only access &ipv6_hdr(skb)->saddr and &ipv6_hdr(skb)->daddr when net_dbg_ratelimited() is called in the slow path.
- Avoid potential future misuse after pskb_pull() call.
--- net/ipv6/icmp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
net/ipv6/icmp.c +4 -6
@@ -889,7 +889,6 @@ static int icmpv6_rcv(struct sk_buff *skb)struct net *net =dev_net (skb->dev);struct net_device *dev =icmp6_dev (skb);struct inet6_dev *idev =__in6_dev_get (dev); -const struct in6_addr *saddr, *daddr;struct icmp6hdr *hdr;u8 type;
@@ -920,12 +919,10 @@ static int icmpv6_rcv(struct sk_buff *skb)__ICMP6_INC_STATS (dev_net (dev), idev,ICMP6_MIB_INMSGS ); - saddr = &ipv6_hdr (skb)->saddr; - daddr = &ipv6_hdr (skb)->daddr; -if (skb_checksum_validate (skb,IPPROTO_ICMPV6 , ip6_compute_pseudo)) {net_dbg_ratelimited ("ICMPv6 checksum failed [%pI6c > %pI6c]\n" , - saddr, daddr); + &ipv6_hdr (skb)->saddr, + &ipv6_hdr (skb)->daddr); goto csum_error; }
@@ -1007,7 +1004,8 @@ static int icmpv6_rcv(struct sk_buff *skb)break ;net_dbg_ratelimited ("icmpv6: msg of unknown type [%pI6c > %pI6c]\n" , - saddr, daddr); + &ipv6_hdr (skb)->saddr, + &ipv6_hdr (skb)->daddr);/* * error of unknown type.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 697/969 sctp: fix OOB write to userspace in sctp_getsockopt_peer_auth_chunks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit 0cf004ffb61cd32d140531c3a84afe975f9fc7ea ]
sctp_getsockopt_peer_auth_chunks() checks that the caller's optval buffer is large enough for the peer AUTH chunk list with
if (len < num_chunks)
return -EINVAL;
but then writes num_chunks bytes to p->gauth_chunks, which lives at offset offsetof(struct sctp_authchunks, gauth_chunks) == 8 inside optval. The check is missing the sizeof(struct sctp_authchunks) = 8-byte header. When the caller supplies len == num_chunks (for any num_chunks > 0) the test passes but copy_to_user() writes sizeof(struct sctp_authchunks) = 8 bytes past the declared buffer.
The sibling function sctp_getsockopt_local_auth_chunks() at the next line already has the correct check:
if (len < sizeof(struct sctp_authchunks) + num_chunks)
return -EINVAL;
Align the peer variant with its sibling.
Reproducer confirms on v7.0-13-generic: an unprivileged userspace caller that opens a loopback SCTP association with AUTH enabled, queries num_chunks with a short optval, then issues the real getsockopt with len == num_chunks and sentinel bytes painted past the buffer observes those sentinel bytes overwritten with the peer's AUTH chunk type. The bytes written are under the peer's control but land in the caller's own userspace; this is not a kernel memory corruption, but it is a kernel-side contract violation that can silently corrupt adjacent userspace data.
--- net/sctp/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/socket.c +1 -1
@@ -6995,7 +6995,7 @@ static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len,/* See if the user provided enough room for all the data */ num_chunks =ntohs (ch->param_hdr.length) -sizeof (struct sctp_paramhdr ); -if (len < num_chunks) +if (len <sizeof (struct sctp_authchunks ) + num_chunks)return -EINVAL ;if (copy_to_user (to, ch->chunks, num_chunks))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 698/969 pppoe: drop PFC frames
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingfang Deng <[email protected]>
[ Upstream commit cc1ff87bce1ccd38410ab10960f576dcd17db679 ]
RFC 2516 Section 7 states that Protocol Field Compression (PFC) is NOT RECOMMENDED for PPPoE. In practice, pppd does not support negotiating PFC for PPPoE sessions, and the current PPPoE driver assumes an uncompressed (2-byte) protocol field. However, the generic PPP layer function ppp_input() is not aware of the negotiation result, and still accepts PFC frames.
If a peer with a broken implementation or an attacker sends a frame with a compressed (1-byte) protocol field, the subsequent PPP payload is shifted by one byte. This causes the network header to be 4-byte misaligned, which may trigger unaligned access exceptions on some architectures.
To reduce the attack surface, drop PPPoE PFC frames. Introduce ppp_skb_is_compressed_proto() helper function to be used in both ppp_generic.c and pppoe.c to avoid open-coding.
--- drivers/net/ppp/ppp_generic.c | 2 +- drivers/net/ppp/pppoe.c | 8 +++++++- include/linux/ppp_defs.h | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-)
drivers/net/ppp/ppp_generic.c +1 -1
@@ -2245,7 +2245,7 @@ ppp_do_recv(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)*/ static void __ppp_decompress_proto (struct sk_buff *skb) { -if (skb->data[0 ] &0x01 ) +if (ppp_skb_is_compressed_proto (skb)) *(u8 *)skb_push (skb,1 ) =0x00 ; }
drivers/net/ppp/pppoe.c +7 -1
@@ -425,7 +425,7 @@ static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,if (skb_mac_header_len (skb) <ETH_HLEN ) goto drop; -if (!pskb_may_pull (skb,sizeof (struct pppoe_hdr ))) +if (!pskb_may_pull (skb,PPPOE_SES_HLEN )) goto drop; ph =pppoe_hdr (skb);
@@ -435,6 +435,12 @@ static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,if (skb->len < len) goto drop; +/* skb->data points to the PPP protocol header after skb_pull_rcsum. +* Drop PFC frames. +*/ +if (ppp_skb_is_compressed_proto (skb)) + goto drop; +if (pskb_trim_rcsum (skb, len)) goto drop;
include/linux/ppp_defs.h +16 -0
@@ -8,6 +8,7 @@#define _PPP_DEFS_H_#include <linux/crc-ccitt.h> +#include <linux/skbuff.h> #include <uapi/linux/ppp_defs.h> #define PPP_FCS (fcs, c) crc_ccitt_byte(fcs, c)
@@ -25,4 +26,19 @@ static inline bool ppp_proto_is_valid(u16 proto) return !!((proto & 0x0101) == 0x0001); } +/** +* ppp_skb_is_compressed_proto - checks if PPP protocol in a skb is compressed +* @skb: skb to check +* +* Check if the PPP protocol field is compressed (the least significant +* bit of the most significant octet is 1). skb->data must point to the PPP +* protocol header. +* +* Return: Whether the PPP protocol field is compressed. +*/ +static inline bool ppp_skb_is_compressed_proto (const struct sk_buff *skb) +{ +return unlikely (skb->data[0 ] &0x01 ); +} +#endif /* _PPP_DEFS_H_ */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 699/969 openvswitch: cap upcall PID array size and pre-size vport replies
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 2091c6aa0df6aba47deb5c8ab232b1cb60af3519 ]
The vport netlink reply helpers allocate a fixed-size skb with nlmsg_new(NLMSG_DEFAULT_SIZE, ...) but serialize the full upcall PID array via ovs_vport_get_upcall_portids(). Since ovs_vport_set_upcall_portids() accepts any non-zero multiple of sizeof(u32) with no upper bound, a CAP_NET_ADMIN user can install a PID array large enough to overflow the reply buffer, causing nla_put() to fail with -EMSGSIZE and hitting BUG_ON(err < 0). On systems with unprivileged user namespaces enabled (e.g., Ubuntu default), this is reachable via unshare -Urn since OVS vport mutation operations use GENL_UNS_ADMIN_PERM.
kernel BUG at net/openvswitch/datapath.c:2414!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI CPU: 1 UID: 0 PID: 65 Comm: poc Not tainted 7.0.0-rc7-00195-geb216e422044 #1 RIP: 0010:ovs_vport_cmd_set+0x34c/0x400 Call Trace: <TASK> genl_family_rcv_msg_doit (net/netlink/genetlink.c:1116) genl_rcv_msg (net/netlink/genetlink.c:1194) netlink_rcv_skb (net/netlink/af_netlink.c:2550) genl_rcv (net/netlink/genetlink.c:1219) netlink_unicast (net/netlink/af_netlink.c:1344) netlink_sendmsg (net/netlink/af_netlink.c:1894) __sys_sendto (net/socket.c:2206) __x64_sys_sendto (net/socket.c:2209) do_syscall_64 (arch/x86/entry/syscall_64.c:63) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130) </TASK> Kernel panic - not syncing: Fatal exception
Reject attempts to set more PIDs than nr_cpu_ids in ovs_vport_set_upcall_portids(), and pre-compute the worst-case reply size in ovs_vport_cmd_msg_size() based on that bound, similar to the existing ovs_dp_cmd_msg_size(). nr_cpu_ids matches the cap already used by the per-CPU dispatch configuration on the datapath side (ovs_dp_cmd_fill_info() serialises at most nr_cpu_ids PIDs), so the two sides stay consistent.
--- net/openvswitch/datapath.c | 35 +++++++++++++++++++++++++++++++++-- net/openvswitch/vport.c | 3 +++ 2 files changed, 36 insertions(+), 2 deletions(-)
net/openvswitch/datapath.c +33 -2
@@ -2128,9 +2128,40 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,return err; } +static size_t ovs_vport_cmd_msg_size (void ) +{ +size_t msgsize =NLMSG_ALIGN (sizeof (struct ovs_header )); + + msgsize +=nla_total_size (sizeof (u32));/* OVS_VPORT_ATTR_PORT_NO */ + msgsize +=nla_total_size (sizeof (u32));/* OVS_VPORT_ATTR_TYPE */ + msgsize +=nla_total_size (IFNAMSIZ );/* OVS_VPORT_ATTR_NAME */ + msgsize +=nla_total_size (sizeof (u32));/* OVS_VPORT_ATTR_IFINDEX */ + msgsize +=nla_total_size (sizeof (s32));/* OVS_VPORT_ATTR_NETNSID */ + +/* OVS_VPORT_ATTR_STATS */ + msgsize +=nla_total_size_64bit (sizeof (struct ovs_vport_stats )); + +/* OVS_VPORT_ATTR_UPCALL_STATS(OVS_VPORT_UPCALL_ATTR_SUCCESS + +* OVS_VPORT_UPCALL_ATTR_FAIL) +*/ + msgsize +=nla_total_size (nla_total_size_64bit (sizeof (u64)) + +nla_total_size_64bit (sizeof (u64))); + +/* OVS_VPORT_ATTR_UPCALL_PID */ + msgsize +=nla_total_size (nr_cpu_ids *sizeof (u32)); + +/* OVS_VPORT_ATTR_OPTIONS(OVS_TUNNEL_ATTR_DST_PORT + +* OVS_TUNNEL_ATTR_EXTENSION(OVS_VXLAN_EXT_GBP)) +*/ + msgsize +=nla_total_size (nla_total_size (sizeof (u16)) + +nla_total_size (nla_total_size (0 ))); + +return msgsize; +} +static struct sk_buff *ovs_vport_cmd_alloc_info (void ) { -return nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +return genlmsg_new (ovs_vport_cmd_msg_size (),GFP_KERNEL ); }/* Called with ovs_mutex, only via ovs_dp_notify_wq(). */
@@ -2140,7 +2171,7 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,struct sk_buff *skb;int retval; - skb =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); + skb =ovs_vport_cmd_alloc_info ();if (!skb)return ERR_PTR (-ENOMEM );
net/openvswitch/vport.c +3 -0
@@ -342,6 +342,9 @@ int ovs_vport_set_upcall_portids(struct vport *vport, const struct nlattr *ids)if (!nla_len (ids) ||nla_len (ids) %sizeof (u32))return -EINVAL ; +if (nla_len (ids) /sizeof (u32) > nr_cpu_ids) +return -EINVAL ; + old =ovsl_dereference (vport->upcall_portids); vport_portids = kmalloc(sizeof(*vport_portids) + nla_len(ids),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 700/969 netfilter: nft_osf: restrict it to ipv4
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit b336fdbb7103fb1484e1dcb6741151d4b5a41e35 ]
This expression only supports for ipv4, restrict it.
--- net/netfilter/nft_osf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/nft_osf.c +5 -1
@@ -28,6 +28,11 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,struct nf_osf_data data;struct tcphdr _tcph; +if (nft_pf (pkt) !=NFPROTO_IPV4 ) { + regs->verdict.code =NFT_BREAK ; +return ; + } +if (pkt->tprot !=IPPROTO_TCP ) { regs->verdict.code =NFT_BREAK ;return ;
@@ -119,7 +124,6 @@ static int nft_osf_validate(const struct nft_ctx *ctx,switch (ctx->family) {case NFPROTO_IPV4 : -case NFPROTO_IPV6 :case NFPROTO_INET : hooks = (1 <<NF_INET_LOCAL_IN ) | (1 << NF_INET_PRE_ROUTING) |
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 701/969 netfilter: nfnetlink_osf: fix divide-by-zero in OSF_WSS_MODULO
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 2195574dc6d9017d32ac346987e12659f931d932 ]
nf_osf_match_one() computes ctx->window % f->wss.val in the OSF_WSS_MODULO branch with no guard for f->wss.val == 0. A CAP_NET_ADMIN user can add such a fingerprint via nfnetlink; a subsequent matching TCP SYN divides by zero and panics the kernel.
Reject the bogus fingerprint in nfnl_osf_add_callback() above the per-option for-loop. f->wss is per-fingerprint, not per-option, so the check must run regardless of f->opt_num (including 0). Also reject wss.wc >= OSF_WSS_MAX; nf_osf_match_one() already treats that as "should not happen".
Crash:
Oops: divide error: 0000 [#1] SMP KASAN NOPTI RIP: 0010:nf_osf_match_one (net/netfilter/nfnetlink_osf.c:98) Call Trace: <IRQ> nf_osf_match (net/netfilter/nfnetlink_osf.c:220) xt_osf_match_packet (net/netfilter/xt_osf.c:32) ipt_do_table (net/ipv4/netfilter/ip_tables.c:348) nf_hook_slow (net/netfilter/core.c:622) ip_local_deliver (net/ipv4/ip_input.c:265) ip_rcv (include/linux/skbuff.h:1162) __netif_receive_skb_one_core (net/core/dev.c:6181) process_backlog (net/core/dev.c:6642) __napi_poll (net/core/dev.c:7710) net_rx_action (net/core/dev.c:7945) handle_softirqs (kernel/softirq.c:622)
--- net/netfilter/nfnetlink_osf.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/nfnetlink_osf.c +4 -0
@@ -320,6 +320,10 @@ static int nfnl_osf_add_callback(struct sk_buff *skb,if (f->opt_num >ARRAY_SIZE (f->opt))return -EINVAL ; +if (f->wss.wc >=OSF_WSS_MAX || + (f->wss.wc ==OSF_WSS_MODULO && f->wss.val ==0 )) +return -EINVAL ; +for (i =0 ; i < f->opt_num; i++) {if (!f->opt[i].length || f->opt[i].length >MAX_IPOPTLEN )return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 702/969 netfilter: conntrack: remove sprintf usage
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 6e7066bdb481a87fe88c4fa563e348c03b2d373d ]
Replace it with scnprintf, the buffer sizes are expected to be large enough to hold the result, no need for snprintf+overflow check.
Increase buffer size in mangle_content_len() while at it.
BUG: KASAN: stack-out-of-bounds in vsnprintf+0xea5/0x1270 Write of size 1 at addr [..] vsnprintf+0xea5/0x1270 sprintf+0xb1/0xe0 mangle_content_len+0x1ac/0x280 nf_nat_sdp_session+0x1cc/0x240 process_sdp+0x8f8/0xb80 process_invite_request+0x108/0x2b0 process_sip_msg+0x5da/0xf50 sip_help_tcp+0x45e/0x780 nf_confirm+0x34d/0x990 [..]
--- net/netfilter/nf_nat_amanda.c | 2 +- net/netfilter/nf_nat_sip.c | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-)
net/netfilter/nf_nat_amanda.c +1 -1
@@ -50,7 +50,7 @@ static unsigned int help(struct sk_buff *skb,return NF_DROP ; } -sprintf (buffer,"%u" , port); +snprintf (buffer,sizeof (buffer),"%u" , port);if (!nf_nat_mangle_udp_packet (skb, exp->master, ctinfo, protoff, matchoff, matchlen, buffer,strlen (buffer))) {
net/netfilter/nf_nat_sip.c +18 -15
@@ -68,25 +68,27 @@ static unsigned int mangle_packet(struct sk_buff *skb, unsigned int protoff, }static int sip_sprintf_addr (const struct nf_conn *ct,char *buffer, +size_t size,const union nf_inet_addr *addr,bool delim) {if (nf_ct_l3num (ct) ==NFPROTO_IPV4 ) -return sprintf (buffer,"%pI4" , &addr->ip); +return scnprintf (buffer, size,"%pI4" , &addr->ip);else {if (delim) -return sprintf (buffer,"[%pI6c]" , &addr->ip6); +return scnprintf (buffer, size,"[%pI6c]" , &addr->ip6);else -return sprintf (buffer,"%pI6c" , &addr->ip6); +return scnprintf (buffer, size,"%pI6c" , &addr->ip6); } }static int sip_sprintf_addr_port (const struct nf_conn *ct,char *buffer, +size_t size,const union nf_inet_addr *addr,u16 port) {if (nf_ct_l3num (ct) ==NFPROTO_IPV4 ) -return sprintf (buffer,"%pI4:%u" , &addr->ip, port); +return scnprintf (buffer, size,"%pI4:%u" , &addr->ip, port);else -return sprintf (buffer,"[%pI6c]:%u" , &addr->ip6, port); +return scnprintf (buffer, size,"[%pI6c]:%u" , &addr->ip6, port); } static int map_addr(struct sk_buff *skb, unsigned int protoff,
@@ -119,7 +121,7 @@ static int map_addr(struct sk_buff *skb, unsigned int protoff,if (nf_inet_addr_cmp (&newaddr, addr) && newport == port)return 1 ; - buflen =sip_sprintf_addr_port (ct, buffer, &newaddr,ntohs (newport)); + buflen =sip_sprintf_addr_port (ct, buffer,sizeof (buffer), &newaddr,ntohs (newport));return mangle_packet (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, buffer, buflen); }
@@ -212,7 +214,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff, &addr, true) > 0 && nf_inet_addr_cmp(&addr, &ct->tuplehash[dir].tuple.src.u3) && !nf_inet_addr_cmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3)) { - buflen = sip_sprintf_addr(ct, buffer, + buflen = sip_sprintf_addr(ct, buffer, sizeof(buffer), &ct->tuplehash[!dir].tuple.dst.u3, true); if (!mangle_packet(skb, protoff, dataoff, dptr, datalen,
@@ -229,7 +231,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff, &addr, false) > 0 && nf_inet_addr_cmp(&addr, &ct->tuplehash[dir].tuple.dst.u3) && !nf_inet_addr_cmp(&addr, &ct->tuplehash[!dir].tuple.src.u3)) { - buflen = sip_sprintf_addr(ct, buffer, + buflen = sip_sprintf_addr(ct, buffer, sizeof(buffer), &ct->tuplehash[!dir].tuple.src.u3, false); if (!mangle_packet(skb, protoff, dataoff, dptr, datalen,
@@ -247,7 +249,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff, htons(n) == ct->tuplehash[dir].tuple.dst.u.udp.port && htons(n) != ct->tuplehash[!dir].tuple.src.u.udp.port) {__be16 p = ct->tuplehash[!dir].tuple.src.u.udp.port; - buflen =sprintf (buffer,"%u" ,ntohs (p)); + buflen =scnprintf (buffer,sizeof (buffer),"%u" ,ntohs (p));if (!mangle_packet (skb, protoff, dataoff, dptr, datalen, poff, plen, buffer, buflen)) {nf_ct_helper_log (skb, ct,"cannot mangle rport" );
@@ -418,7 +420,8 @@ static unsigned int nf_nat_sip_expect(struct sk_buff *skb, unsigned int protoff,if (!nf_inet_addr_cmp (&exp->tuple.dst.u3, &exp->saved_addr) || exp->tuple.dst.u.udp.port != exp->saved_proto.udp.port) { - buflen =sip_sprintf_addr_port (ct, buffer, &newaddr, port); + buflen =sip_sprintf_addr_port (ct, buffer,sizeof (buffer), + &newaddr, port);if (!mangle_packet (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, buffer, buflen)) {nf_ct_helper_log (skb, ct,"cannot mangle packet" );
@@ -438,8 +441,8 @@ static int mangle_content_len(struct sk_buff *skb, unsigned int protoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); +char buffer[sizeof ("4294967295" )];unsigned int matchoff, matchlen; -char buffer[sizeof ("65536" )];int buflen, c_len;/* Get actual SDP length */
@@ -454,7 +457,7 @@ static int mangle_content_len(struct sk_buff *skb, unsigned int protoff, &matchoff, &matchlen) <= 0)return 0 ; - buflen =sprintf (buffer,"%u" , c_len); + buflen =scnprintf (buffer,sizeof (buffer),"%u" , c_len);return mangle_packet (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, buffer, buflen); }
@@ -491,7 +494,7 @@ static unsigned int nf_nat_sdp_addr(struct sk_buff *skb, unsigned int protoff,char buffer[INET6_ADDRSTRLEN ];unsigned int buflen; - buflen =sip_sprintf_addr (ct, buffer, addr, false); + buflen =sip_sprintf_addr (ct, buffer,sizeof (buffer), addr, false);if (mangle_sdp_packet (skb, protoff, dataoff, dptr, datalen, sdpoff, type, term, buffer, buflen))return 0 ;
@@ -509,7 +512,7 @@ static unsigned int nf_nat_sdp_port(struct sk_buff *skb, unsigned int protoff,char buffer[sizeof ("nnnnn" )];unsigned int buflen; - buflen =sprintf (buffer,"%u" , port); + buflen =scnprintf (buffer,sizeof (buffer),"%u" , port);if (!mangle_packet (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, buffer, buflen))return 0 ;
@@ -529,7 +532,7 @@ static unsigned int nf_nat_sdp_session(struct sk_buff *skb, unsigned int protoffunsigned int buflen;/* Mangle session description owner and contact addresses */ - buflen =sip_sprintf_addr (ct, buffer, addr, false); + buflen =sip_sprintf_addr (ct, buffer,sizeof (buffer), addr, false);if (mangle_sdp_packet (skb, protoff, dataoff, dptr, datalen, sdpoff,SDP_HDR_OWNER ,SDP_HDR_MEDIA , buffer, buflen))return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 703/969 netfilter: xtables: restrict several matches to inet family
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit b6fe26f86a1649f84e057f3f15605b08eda15497 ]
This is a partial revert of:
commit ab4f21e6fb1c ("netfilter: xtables: use NFPROTO_UNSPEC in more extensions")
to allow ipv4 and ipv6 only.
- xt_mac
- xt_owner
- xt_physdev
These extensions are not used by ebtables in userspace.
Moreover, xt_realm is only for ipv4, since dst->tclassid is ipv4 specific.
--- net/netfilter/xt_mac.c | 34 +++++++++++++++++++++++----------- net/netfilter/xt_owner.c | 37 +++++++++++++++++++++++++------------ net/netfilter/xt_physdev.c | 29 +++++++++++++++++++---------- net/netfilter/xt_realm.c | 2 +- 4 files changed, 68 insertions(+), 34 deletions(-)
net/netfilter/xt_mac.c +23 -11
@@ -38,25 +38,37 @@ static bool mac_mt(const struct sk_buff *skb, struct xt_action_param *par)return ret; } -static struct xt_match mac_mt_reg__read_mostly = { - .name ="mac" , - .revision =0 , - .family =NFPROTO_UNSPEC , - .match = mac_mt, - .matchsize =sizeof (struct xt_mac_info ), - .hooks = (1 <<NF_INET_PRE_ROUTING ) | (1 <<NF_INET_LOCAL_IN ) | - (1 <<NF_INET_FORWARD ), - .me =THIS_MODULE , +static struct xt_match mac_mt_reg[]__read_mostly = { + { + .name ="mac" , + .family =NFPROTO_IPV4 , + .match = mac_mt, + .matchsize =sizeof (struct xt_mac_info ), + .hooks = (1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_FORWARD ), + .me =THIS_MODULE , + }, + { + .name ="mac" , + .family =NFPROTO_IPV6 , + .match = mac_mt, + .matchsize =sizeof (struct xt_mac_info ), + .hooks = (1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_FORWARD ), + .me =THIS_MODULE , + }, };static int __init mac_mt_init (void ) { -return xt_register_match (&mac_mt_reg); +return xt_register_matches (mac_mt_reg,ARRAY_SIZE (mac_mt_reg)); } static void __exit mac_mt_exit(void) { -xt_unregister_match (&mac_mt_reg); +xt_unregister_matches (mac_mt_reg,ARRAY_SIZE (mac_mt_reg)); }module_init (mac_mt_init);
net/netfilter/xt_owner.c +25 -12
@@ -127,26 +127,39 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par)return true; } -static struct xt_match owner_mt_reg__read_mostly = { - .name ="owner" , - .revision =1 , - .family =NFPROTO_UNSPEC , - .checkentry = owner_check, - .match = owner_mt, - .matchsize =sizeof (struct xt_owner_match_info ), - .hooks = (1 <<NF_INET_LOCAL_OUT ) | - (1 <<NF_INET_POST_ROUTING ), - .me =THIS_MODULE , +static struct xt_match owner_mt_reg[]__read_mostly = { + { + .name ="owner" , + .revision =1 , + .family =NFPROTO_IPV4 , + .checkentry = owner_check, + .match = owner_mt, + .matchsize =sizeof (struct xt_owner_match_info ), + .hooks = (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_POST_ROUTING ), + .me =THIS_MODULE , + }, + { + .name ="owner" , + .revision =1 , + .family =NFPROTO_IPV6 , + .checkentry = owner_check, + .match = owner_mt, + .matchsize =sizeof (struct xt_owner_match_info ), + .hooks = (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_POST_ROUTING ), + .me =THIS_MODULE , + } };static int __init owner_mt_init (void ) { -return xt_register_match (&owner_mt_reg); +return xt_register_matches (owner_mt_reg,ARRAY_SIZE (owner_mt_reg)); } static void __exit owner_mt_exit(void) { -xt_unregister_match (&owner_mt_reg); +xt_unregister_matches (owner_mt_reg,ARRAY_SIZE (owner_mt_reg)); }module_init (owner_mt_init);
net/netfilter/xt_physdev.c +19 -10
@@ -115,24 +115,33 @@ static int physdev_mt_check(const struct xt_mtchk_param *par)return 0 ; } -static struct xt_match physdev_mt_reg__read_mostly = { - .name ="physdev" , - .revision =0 , - .family =NFPROTO_UNSPEC , - .checkentry = physdev_mt_check, - .match = physdev_mt, - .matchsize =sizeof (struct xt_physdev_info ), - .me =THIS_MODULE , +static struct xt_match physdev_mt_reg[]__read_mostly = { + { + .name ="physdev" , + .family =NFPROTO_IPV4 , + .checkentry = physdev_mt_check, + .match = physdev_mt, + .matchsize =sizeof (struct xt_physdev_info ), + .me =THIS_MODULE , + }, + { + .name ="physdev" , + .family =NFPROTO_IPV6 , + .checkentry = physdev_mt_check, + .match = physdev_mt, + .matchsize =sizeof (struct xt_physdev_info ), + .me =THIS_MODULE , + }, };static int __init physdev_mt_init (void ) { -return xt_register_match (&physdev_mt_reg); +return xt_register_matches (physdev_mt_reg,ARRAY_SIZE (physdev_mt_reg)); } static void __exit physdev_mt_exit(void) { -xt_unregister_match (&physdev_mt_reg); +xt_unregister_matches (physdev_mt_reg,ARRAY_SIZE (physdev_mt_reg)); }module_init (physdev_mt_init);
net/netfilter/xt_realm.c +1 -1
@@ -33,7 +33,7 @@ static struct xt_match realm_mt_reg __read_mostly = { .matchsize = sizeof(struct xt_realm_info), .hooks = (1 <<NF_INET_POST_ROUTING ) | (1 <<NF_INET_FORWARD ) | (1 << NF_INET_LOCAL_OUT) | (1 << NF_INET_LOCAL_IN), - .family = NFPROTO_UNSPEC, + .family = NFPROTO_IPV4, .me =THIS_MODULE };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 704/969 ipvs: fix MTU check for GSO packets in tunnel mode
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingnan Zhang <[email protected]>
[ Upstream commit 67bf42cae41d847fd6e5749eb68278ca5d748b25 ]
Currently, IPVS skips MTU checks for GSO packets by excluding them with the !skb_is_gso(skb) condition. This creates problems when IPVS tunnel mode encapsulates GSO packets with IPIP headers.
The issue manifests in two ways:
1. MTU violation after encapsulation:
When a GSO packet passes through IPVS tunnel mode, the original MTU check is bypassed. After adding the IPIP tunnel header, the packet size may exceed the outgoing interface MTU, leading to unexpected fragmentation at the IP layer.
2. Fragmentation with problematic IP IDs:
When net.ipv4.vs.pmtu_disc=1 and a GSO packet with multiple segments is fragmented after encapsulation, each segment gets a sequentially incremented IP ID (0, 1, 2, ...). This happens because:
a) The GSO packet bypasses MTU check and gets encapsulated
b) At __ip_finish_output, the oversized GSO packet is split into separate SKBs (one per segment), with IP IDs incrementing
c) Each SKB is then fragmented again based on the actual MTU
This sequential IP ID allocation differs from the expected behavior and can cause issues with fragment reassembly and packet tracking.
Fix this by properly validating GSO packets using skb_gso_validate_network_len(). This function correctly validates whether the GSO segments will fit within the MTU after segmentation. If validation fails, send an ICMP Fragmentation Needed message to enable proper PMTU discovery.
--- net/netfilter/ipvs/ip_vs_xmit.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +15 -4
@@ -103,6 +103,18 @@ __ip_vs_dst_check(struct ip_vs_dest *dest)return dest_dst; } +/* Based on ip_exceeds_mtu(). */ +static bool ip_vs_exceeds_mtu (const struct sk_buff *skb,unsigned int mtu) +{ +if (skb->len <= mtu) +return false; + +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu)) +return false; + +return true; +} +static inline bool __mtu_check_toobig_v6 (const struct sk_buff *skb,u32 mtu) {
@@ -112,10 +124,9 @@ __mtu_check_toobig_v6(const struct sk_buff *skb, u32 mtu)*/ if (IP6CB (skb)->frag_max_size > mtu)return true;/* largest fragment violate MTU */ - } -else if (skb->len > mtu && !skb_is_gso (skb)) { + }else if (ip_vs_exceeds_mtu (skb, mtu))return true;/* Packet size violate MTU size */ - } +return false; }
@@ -233,7 +244,7 @@ static inline bool ensure_mtu_is_adequate(struct netns_ipvs *ipvs, int skb_af,return true;if (unlikely (ip_hdr (skb)->frag_off &htons (IP_DF ) && - skb->len > mtu && !skb_is_gso (skb) && +ip_vs_exceeds_mtu (skb, mtu) && !ip_vs_iph_icmp (ipvsh))) {icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 705/969 netfilter: nfnetlink_osf: fix out-of-bounds read on option matching
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit f5ca450087c3baf3651055e7a6de92600f827af3 ]
In nf_osf_match(), the nf_osf_hdr_ctx structure is initialized once and passed by reference to nf_osf_match_one() for each fingerprint checked. During TCP option parsing, nf_osf_match_one() advances the shared ctx->optp pointer.
If a fingerprint perfectly matches, the function returns early without restoring ctx->optp to its initial state. If the user has configured NF_OSF_LOGLEVEL_ALL, the loop continues to the next fingerprint. However, because ctx->optp was not restored, the next call to nf_osf_match_one() starts parsing from the end of the options buffer. This causes subsequent matches to read garbage data and fail immediately, making it impossible to log more than one match or logging incorrect matches.
Instead of using a shared ctx->optp pointer, pass the context as a constant pointer and use a local pointer (optp) for TCP option traversal. This makes nf_osf_match_one() strictly stateless from the caller's perspective, ensuring every fingerprint check starts at the correct option offset.
--- net/netfilter/nfnetlink_osf.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
net/netfilter/nfnetlink_osf.c +8 -11
@@ -64,9 +64,9 @@ struct nf_osf_hdr_ctx {static bool nf_osf_match_one (const struct sk_buff *skb,const struct nf_osf_user_finger *f,int ttl_check, -struct nf_osf_hdr_ctx *ctx) +const struct nf_osf_hdr_ctx *ctx) { -const __u8 *optpinit = ctx->optp; +const __u8 *optp = ctx->optp;unsigned int check_WSS =0 ;int fmatch =FMATCH_WRONG ;int foptsize, optnum;
@@ -95,17 +95,17 @@ static bool nf_osf_match_one(const struct sk_buff *skb, check_WSS = f->wss.wc;for (optnum =0 ; optnum < f->opt_num; ++optnum) { -if (f->opt[optnum].kind == *ctx->optp) { +if (f->opt[optnum].kind == *optp) {__u32 len = f->opt[optnum].length; -const __u8 *optend = ctx->optp + len; +const __u8 *optend = optp + len; fmatch =FMATCH_OK ; -switch (*ctx->optp) { +switch (*optp) {case OSFOPT_MSS : - mss = ctx->optp[3 ]; + mss = optp[3 ]; mss <<=8 ; - mss |= ctx->optp[2 ]; + mss |= optp[2 ]; mss =ntohs ((__force __be16 )mss);break ;
@@ -113,7 +113,7 @@ static bool nf_osf_match_one(const struct sk_buff *skb,break ; } - ctx->optp = optend; + optp = optend; }else fmatch =FMATCH_OPT_WRONG ;
@@ -156,9 +156,6 @@ static bool nf_osf_match_one(const struct sk_buff *skb, } } -if (fmatch !=FMATCH_OK ) - ctx->optp = optpinit; -return fmatch ==FMATCH_OK ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 706/969 netfilter: nfnetlink_osf: fix potential NULL dereference in ttl check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit 711987ba281fd806322a7cd244e98e2a81903114 ]
The nf_osf_ttl() function accessed skb->dev to perform a local interface address lookup without verifying that the device pointer was valid.
Additionally, the implementation utilized an in_dev_for_each_ifa_rcu loop to match the packet source address against local interface addresses. It assumed that packets from the same subnet should not see a decrement on the initial TTL. A packet might appear it is from the same subnet but it actually isn't especially in modern environments with containers and virtual switching.
Remove the device dereference and interface loop. Replace the logic with a switch statement that evaluates the TTL according to the ttl_check.
--- net/netfilter/nfnetlink_osf.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
net/netfilter/nfnetlink_osf.c +7 -15
@@ -31,26 +31,18 @@ EXPORT_SYMBOL_GPL(nf_osf_fingers);static inline int nf_osf_ttl (const struct sk_buff *skb,int ttl_check,unsigned char f_ttl) { -struct in_device *in_dev =__in_dev_get_rcu (skb->dev);const struct iphdr *ip =ip_hdr (skb); -const struct in_ifaddr *ifa; -int ret =0 ; -if (ttl_check ==NF_OSF_TTL_TRUE ) +switch (ttl_check) { +case NF_OSF_TTL_TRUE :return ip->ttl == f_ttl; -if (ttl_check ==NF_OSF_TTL_NOCHECK ) -return 1 ; -else if (ip->ttl <= f_ttl) +break ; +case NF_OSF_TTL_NOCHECK :return 1 ; - -in_dev_for_each_ifa_rcu (ifa, in_dev) { -if (inet_ifa_match (ip->saddr, ifa)) { - ret = (ip->ttl == f_ttl); -break ; - } +case NF_OSF_TTL_LESS : +default : +return ip->ttl <= f_ttl; } - -return ret; }struct nf_osf_hdr_ctx {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 707/969 slip: reject VJ receive packets on instances with no rstate array
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit e76607442d5b73e1ba6768f501ef815bb58c2c0e ]
slhc_init() accepts rslots == 0 as a valid configuration, with the documented meaning of 'no receive compression'. In that case the allocation loop in slhc_init() is skipped, so comp->rstate stays NULL and comp->rslot_limit stays 0 (from the kzalloc of struct slcompress).
The receive helpers do not defend against that configuration. slhc_uncompress() dereferences comp->rstate[x] when the VJ header carries an explicit connection ID, and slhc_remember() later assigns cs = &comp->rstate[...] after only comparing the packet's slot number to comp->rslot_limit. Because rslot_limit is 0, slot 0 passes the range check, and the code dereferences a NULL rstate.
The configuration is reachable in-tree through PPP. PPPIOCSMAXCID stores its argument in a signed int, and (val >> 16) uses arithmetic shift. Passing 0xffff0000 therefore sign-extends to -1, so val2 + 1 is 0 and ppp_generic.c ends up calling slhc_init(0, 1). Because /dev/ppp open is gated by ns_capable(CAP_NET_ADMIN), the whole path is reachable from an unprivileged user namespace. Once the malformed VJ state is installed, any inbound VJ-compressed or VJ-uncompressed frame that selects slot 0 crashes the kernel in softirq context:
Oops: general protection fault, probably for non-canonical
address 0xdffffc0000000000: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
RIP: 0010:slhc_uncompress (drivers/net/slip/slhc.c:519)
Call Trace:
<TASK>
ppp_receive_nonmp_frame (drivers/net/ppp/ppp_generic.c:2466)
ppp_input (drivers/net/ppp/ppp_generic.c:2359)
ppp_async_process (drivers/net/ppp/ppp_async.c:492)
tasklet_action_common (kernel/softirq.c:926)
handle_softirqs (kernel/softirq.c:623)
run_ksoftirqd (kernel/softirq.c:1055)
smpboot_thread_fn (kernel/smpboot.c:160)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/x86/kernel/process.c:164)
</TASK>Reject the receive side on such instances instead of touching rstate. slhc_uncompress() falls through to its existing 'bad' label, which bumps sls_i_error and enters the toss state. slhc_remember() mirrors that with an explicit sls_i_error increment followed by slhc_toss(); the sls_i_runt counter is not used here because a missing rstate is an internal configuration state, not a runt packet.
The transmit path is unaffected: the only in-tree caller that picks rslots from userspace (ppp_generic.c) still supplies tslots >= 1, and slip.c always calls slhc_init(16, 16), so comp->tstate remains valid and slhc_compress() continues to work.
--- drivers/net/slip/slhc.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/slip/slhc.c +6 -0
@@ -506,6 +506,8 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize) comp->sls_i_error++;return 0 ; } +if (!comp->rstate) + goto bad; changes = *cp++;if (changes &NEW_C ){/* Make sure the state index is in range, then grab the state.
@@ -649,6 +651,10 @@ slhc_remember(struct slcompress *comp, unsigned char *icp, int isize)struct cstate *cs;unsigned int ihl; +if (!comp->rstate) { + comp->sls_i_error++; +return slhc_toss (comp); + }/* The packet is shorter than a legal IP header. * Also make sure isize is positive. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 708/969 slip: bound decode() reads against the compressed packet length
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 4c1367a2d7aad643a6f87c6931b13cc1a25e8ca7 ]
slhc_uncompress() parses a VJ-compressed TCP header by advancing a pointer through the packet via decode() and pull16(). Neither helper bounds-checks against isize, and decode() masks its return with & 0xffff so it can never return the -1 that callers test for -- those error paths are dead code.
A short compressed frame whose change byte requests optional fields lets decode() read past the end of the packet. The over-read bytes are folded into the cached cstate and reflected into subsequent reconstructed packets.
Make decode() and pull16() take the packet end pointer and return -1 when exhausted. Add a bounds check before the TCP-checksum read. The existing == -1 tests now do what they were always meant to.
--- drivers/net/slip/slhc.c | 43 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-)
drivers/net/slip/slhc.c +25 -18
@@ -80,9 +80,9 @@#include <asm/unaligned.h> static unsigned char *encode (unsigned char *cp,unsigned short n); -static long decode (unsigned char **cpp); +static long decode (unsigned char **cpp,const unsigned char *end);static unsigned char *put16 (unsigned char *cp,unsigned short x); -static unsigned short pull16 (unsigned char **cpp); +static long pull16 (unsigned char **cpp,const unsigned char *end);/* Allocate compression data structure * slots must be in range 0 to 255 (zero meaning no compression)
@@ -190,30 +190,34 @@ encode(unsigned char *cp, unsigned short n)return cp; } -/* Pull a 16-bit integer in host order from buffer in network byte order */ -static unsigned short -pull16 (unsigned char **cpp) +/* Pull a 16-bit integer in host order from buffer in network byte order. +* Returns -1 if the buffer is exhausted, otherwise the 16-bit value. +*/ +static long +pull16 (unsigned char **cpp,const unsigned char *end) { -short rval; +long rval; +if (*cpp +2 > end) +return -1 ; rval = *(*cpp)++; rval <<=8 ; rval |= *(*cpp)++;return rval; } -/* Decode a number */ +/* Decode a number. Returns -1 if the buffer is exhausted. */ static long -decode (unsigned char **cpp) +decode (unsigned char **cpp,const unsigned char *end) {int x; +if (*cpp >= end) +return -1 ; x = *(*cpp)++; -if (x ==0 ){ -return pull16 (cpp) &0xffff ;/* pull16 returns -1 on error */ - }else { -return x &0xff ;/* -1 if PULLCHAR returned error */ - } +if (x ==0 ) +return pull16 (cpp, end); +return x &0xff ; }/*
@@ -499,6 +503,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)struct cstate *cs;int len, hdrlen;unsigned char *cp = icp; +const unsigned char *end = icp + isize;/* We've got a compressed packet; read the change byte */ comp->sls_i_compressed++;
@@ -536,6 +541,8 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize) thp = &cs->cs_tcp; ip = &cs->cs_ip; +if (cp +2 > end) + goto bad; thp->check = *(__sum16 *)cp; cp +=2 ;
@@ -566,26 +573,26 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)default :if (changes &NEW_U ){ thp->urg =1 ; -if ((x =decode (&cp)) ==-1 ) { +if ((x =decode (&cp, end)) ==-1 ) { goto bad; } thp->urg_ptr =htons (x); }else thp->urg =0 ;if (changes &NEW_W ){ -if ((x =decode (&cp)) ==-1 ) { +if ((x =decode (&cp, end)) ==-1 ) { goto bad; } thp->window =htons (ntohs (thp->window) + x); }if (changes &NEW_A ){ -if ((x =decode (&cp)) ==-1 ) { +if ((x =decode (&cp, end)) ==-1 ) { goto bad; } thp->ack_seq =htonl (ntohl (thp->ack_seq) + x); }if (changes &NEW_S ){ -if ((x =decode (&cp)) ==-1 ) { +if ((x =decode (&cp, end)) ==-1 ) { goto bad; } thp->seq =htonl (ntohl (thp->seq) + x);
@@ -593,7 +600,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)break ; }if (changes &NEW_I ){ -if ((x =decode (&cp)) ==-1 ) { +if ((x =decode (&cp, end)) ==-1 ) { goto bad; } ip->id =htons (ntohs (ip->id) + x);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 709/969 arm64: dts: meson-gxl-p230: fix ethernet PHY interrupt number
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jun Yan <[email protected]>
[ Upstream commit 174a0ef3b33434f475c87e66f37980e39b73805a ]
Correct the interrupt number assigned to the Realtek PHY in the p230
following the same logic as commit 3106507e1004 ("ARM64: dts: meson-gxm:
fix q200 interrupt number"),as reported in [PATCH 0/2] Ethernet PHY interrupt improvements [1].
[1] https://lore.kernel.org/all/[email protected]/
--- arch/arm64/boot/dts/amlogic/meson-gxl-s905d-p230.dts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/amlogic/meson-gxl-s905d-p230.dts +2 -1
@@ -84,7 +84,8 @@ external_phy: ethernet-phy@0 { reset-gpios = <&gpio GPIOZ_14 GPIO_ACTIVE_LOW>; interrupt-parent = <&gpio_intc>; - interrupts = <29 IRQ_TYPE_LEVEL_LOW>; + /* MAC_INTR on GPIOZ_15 */ + interrupts = <25 IRQ_TYPE_LEVEL_LOW>; eee-broken-1000t; }; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 710/969 ksmbd: destroy tree_conn_ida in ksmbd_session_destroy()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
[ Upstream commit c049ee14eb4343b69b6f7755563f961f5e153423 ]
When per-session tree_conn_ida was converted from a dynamically allocated ksmbd_ida to an embedded struct ida, ksmbd_ida_free() was removed from ksmbd_session_destroy() but no matching ida_destroy() was added. The session is therefore freed with the IDA's backing xarray still intact.
The kernel IDA API expects ida_init() and ida_destroy() to be paired over an object's lifetime, so add the missing cleanup before the enclosing session is freed.
Also move ida_init() to right after the session is allocated so that it is always paired with the destroy call even on the early error paths of __session_create() (ksmbd_init_file_table() or __init_smb2_session() failures), both of which jump to the error label and invoke ksmbd_session_destroy() on a partially initialised session.
No leak has been observed in testing; this is a pairing fix to match the IDA lifetime rules, not a response to a reproduced regression.
--- fs/smb/server/mgmt/user_session.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/smb/server/mgmt/user_session.c +3 -2
@@ -168,6 +168,7 @@ void ksmbd_session_destroy(struct ksmbd_session *sess)free_channel_list (sess);kfree (sess->Preauth_HashValue);ksmbd_release_id (&session_ida, sess->id); +ida_destroy (&sess->tree_conn_ida);kfree (sess); }
@@ -404,6 +405,8 @@ static struct ksmbd_session *__session_create(int protocol)if (!sess)return NULL ; +ida_init (&sess->tree_conn_ida); +if (ksmbd_init_file_table (&sess->file_table)) goto error;
@@ -422,8 +425,6 @@ static struct ksmbd_session *__session_create(int protocol)if (ret) goto error; -ida_init (&sess->tree_conn_ida); -down_write (&sessions_table_lock);hash_add (sessions_table, &sess->hlist, sess->id);up_write (&sessions_table_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 711/969 ksmbd: scope conn->binding slowpath to bound sessions only
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunwoo Kim <[email protected]>
[ Upstream commit b0da97c034b6107d14e537e212d4ce8b22109a58 ]
When the binding SESSION_SETUP sets conn->binding = true, the flag stays set after the call so that the global session lookup in ksmbd_session_lookup_all() can find the session, which was not added to conn->sessions. Because the flag is connection-wide, the global lookup path will also resolve any other session by id if asked.
Tighten the global lookup so that the returned session must have this connection registered in its channel xarray (sess->ksmbd_chann_list). The channel entry is installed by the existing binding_session path in ntlm_authenticate()/krb5_authenticate() when a SESSION_SETUP completes successfully, so this condition is a strict equivalent of "this connection has been accepted as a channel of this session". Connections that have not bound to a given session cannot reach it via the global table.
The existing conn->binding gate for entering the slowpath is preserved so that non-binding connections keep the fast-path-only behavior, and the session->state check is unchanged.
--- fs/smb/server/mgmt/user_session.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/smb/server/mgmt/user_session.c +6 -1
@@ -323,8 +323,13 @@ struct ksmbd_session *ksmbd_session_lookup_all(struct ksmbd_conn *conn,struct ksmbd_session *sess; sess =ksmbd_session_lookup (conn, id); -if (!sess && conn->binding) +if (!sess && conn->binding) { sess =ksmbd_session_lookup_slowpath (id); +if (sess && !xa_load (&sess->ksmbd_chann_list, (long )conn)) { +ksmbd_user_session_put (sess); + sess =NULL ; + } + }if (sess && sess->state !=SMB2_SESSION_VALID ) {ksmbd_user_session_put (sess); sess =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 712/969 net/rds: zero per-item info buffer before handing it to visitors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit c88eb7e8d8397a8c1db59c425332c5a30b2a1682 ]
rds_for_each_conn_info() and rds_walk_conn_path_info() both hand a caller-allocated on-stack u64 buffer to a per-connection visitor and then copy the full item_len bytes back to user space via rds_info_copy() regardless of how much of the buffer the visitor actually wrote.
rds_ib_conn_info_visitor() and rds6_ib_conn_info_visitor() only write a subset of their output struct when the underlying rds_connection is not in state RDS_CONN_UP (src/dst addr, tos, sl and the two GIDs via explicit memsets). Several u32 fields (max_send_wr, max_recv_wr, max_send_sge, rdma_mr_max, rdma_mr_size, cache_allocs) and the 2-byte alignment hole between sl and cache_allocs remain as whatever stack contents preceded the visitor call and are then memcpy_to_user()'d out to user space.
struct rds_info_rdma_connection and struct rds6_info_rdma_connection are the only rds_info_* structs in include/uapi/linux/rds.h that are not marked __attribute__((packed)), so they have a real alignment hole. The other info visitors (rds_conn_info_visitor, rds6_conn_info_visitor, rds_tcp_tc_info, ...) write all fields of their packed output struct today and are not known to be vulnerable, but a future visitor that adds a conditional write-path would have the same bug.
Reproduction on a kernel built without CONFIG_INIT_STACK_ALL_ZERO=y:
a local unprivileged user opens AF_RDS, sets SO_RDS_TRANSPORT=IB, binds to a local address on an RDMA-capable netdev (rxe soft-RoCE on any netdev is sufficient), sendto()'s any peer on the same subnet (fails cleanly but installs an rds_connection in the global hash in RDS_CONN_CONNECTING), then calls getsockopt(SOL_RDS, RDS_INFO_IB_CONNECTIONS). The returned 68-byte item contains 26 bytes of stack garbage including kernel text/data pointers:
0..7 0a 63 00 01 0a 63 00 02 src=10.99.0.1 dst=10.99.0.2
8..39 00 ... gids (memset-zeroed)
40..47 e0 92 a3 81 ff ff ff ff kernel pointer (max_send_wr)
48..55 7f 37 b5 81 ff ff ff ff kernel pointer (rdma_mr_max)
56..59 01 00 08 00 rdma_mr_size (garbage)
60..61 00 00 tos, sl
62..63 00 00 alignment padding
64..67 18 00 00 00 cache_allocs (garbage)Fix by zeroing the per-item buffer in both rds_for_each_conn_info() and rds_walk_conn_path_info() before invoking the visitor. This covers the IPv4/IPv6 IB visitors and hardens all current and future visitors against the same class of bug.
No functional change for visitors that fully populate their output.
Changes in v2:
- retarget at the net tree (subject prefix "[PATCH net v2]", net/rds: prefix in the title)
- pick up Reviewed-by tags from Sharath Srinivasan and Allison Henderson
--- net/rds/connection.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/rds/connection.c +14 -0
@@ -673,6 +673,13 @@ void rds_for_each_conn_info(struct socket *sock, unsigned int len, i++, head++) {hlist_for_each_entry_rcu (conn, head, c_hash_node) { +/* Zero the per-item buffer before handing it to the +* visitor so any field the visitor does not write - +* including implicit alignment padding - cannot leak +* stack contents to user space via rds_info_copy(). +*/ +memset (buffer,0 , item_len); +/* XXX no c_lock usage.. */ if (!visitor (conn, buffer))continue ;
@@ -722,6 +729,13 @@ static void rds_walk_conn_path_info(struct socket *sock, unsigned int len,*/ cp = conn->c_path; +/* Zero the per-item buffer for the same reason as +* rds_for_each_conn_info(): any byte the visitor +* does not write (including alignment padding) must +* not leak stack contents via rds_info_copy(). +*/ +memset (buffer,0 , item_len); +/* XXX no cp_lock usage.. */ if (!visitor (cp, buffer))continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 713/969 net_sched: sch_hhf: annotate data-races in hhf_dump_stats()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit a6edf2cd4156b71e07258876b7626692e158f7e8 ]
hhf_dump_stats() only runs with RTNL held, reading fields that can be changed in qdisc fast path.
Add READ_ONCE()/WRITE_ONCE() annotations.
--- net/sched/sch_hhf.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
net/sched/sch_hhf.c +10 -9
@@ -198,7 +198,8 @@ static struct hh_flow_state *seek_list(const u32 hash,return NULL ;list_del (&flow->flowchain);kfree (flow); - q->hh_flows_current_cnt--; +WRITE_ONCE (q->hh_flows_current_cnt, + q->hh_flows_current_cnt -1 ); }else if (flow->hash_id == hash) {return flow; }
@@ -226,7 +227,7 @@ static struct hh_flow_state *alloc_new_hh(struct list_head *head, }if (q->hh_flows_current_cnt >= q->hh_flows_limit) { - q->hh_flows_overlimit++; +WRITE_ONCE (q->hh_flows_overlimit, q->hh_flows_overlimit +1 );return NULL ; }/* Create new entry. */
@@ -234,7 +235,7 @@ static struct hh_flow_state *alloc_new_hh(struct list_head *head,if (!flow)return NULL ; - q->hh_flows_current_cnt++; +WRITE_ONCE (q->hh_flows_current_cnt, q->hh_flows_current_cnt +1 );INIT_LIST_HEAD (&flow->flowchain);list_add_tail (&flow->flowchain, head);
@@ -309,7 +310,7 @@ static enum wdrr_bucket_idx hhf_classify(struct sk_buff *skb, struct Qdisc *sch)return WDRR_BUCKET_FOR_NON_HH ; flow->hash_id = hash; flow->hit_timestamp = now; - q->hh_flows_total_cnt++; +WRITE_ONCE (q->hh_flows_total_cnt, q->hh_flows_total_cnt +1 );/* By returning without updating counters in q->hhf_arrays, * we implicitly implement "shielding" (see Optimization O1).
@@ -403,7 +404,7 @@ static int hhf_enqueue(struct sk_buff *skb, struct Qdisc *sch,return NET_XMIT_SUCCESS ; prev_backlog = sch->qstats.backlog; - q->drop_overlimit++; +WRITE_ONCE (q->drop_overlimit, q->drop_overlimit +1 );/* Return Congestion Notification only if we dropped a packet from this * bucket. */
@@ -678,10 +679,10 @@ static int hhf_dump_stats(struct Qdisc *sch, struct gnet_dump *d) {struct hhf_sched_data *q =qdisc_priv (sch);struct tc_hhf_xstats st = { - .drop_overlimit = q->drop_overlimit, - .hh_overlimit = q->hh_flows_overlimit, - .hh_tot_count = q->hh_flows_total_cnt, - .hh_cur_count = q->hh_flows_current_cnt, + .drop_overlimit =READ_ONCE (q->drop_overlimit), + .hh_overlimit =READ_ONCE (q->hh_flows_overlimit), + .hh_tot_count =READ_ONCE (q->hh_flows_total_cnt), + .hh_cur_count =READ_ONCE (q->hh_flows_current_cnt), };return gnet_stats_copy_app (d, &st,sizeof (st));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 714/969 net/sched: sch_pie: annotate data-races in pie_dump_stats()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 5154561d9b119f781249f8e845fecf059b38b483 ]
pie_dump_stats() only runs with RTNL held, reading fields that can be changed in qdisc fast path.
Add READ_ONCE()/WRITE_ONCE() annotations.
Alternative would be to acquire the qdisc spinlock, but our long-term goal is to make qdisc dump operations lockless as much as we can.
tc_pie_xstats fields don't need to be latched atomically, otherwise this bug would have been caught earlier.
--- include/net/pie.h | 2 +- net/sched/sch_pie.c | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-)
include/net/pie.h +1 -1
@@ -104,7 +104,7 @@ static inline void pie_vars_init(struct pie_vars *vars) vars->dq_tstamp =DTIME_INVALID ; vars->accu_prob =0 ; vars->dq_count =DQCOUNT_INVALID ; - vars->avg_dq_rate =0 ; +WRITE_ONCE (vars->avg_dq_rate,0 ); }static inline struct pie_skb_cb *get_pie_cb (const struct sk_buff *skb)
net/sched/sch_pie.c +19 -19
@@ -89,7 +89,7 @@ static int pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,bool enqueue = false;if (unlikely (qdisc_qlen (sch) >= sch->limit)) { - q->stats.overlimit++; +WRITE_ONCE (q->stats.overlimit, q->stats.overlimit +1 ); goto out; }
@@ -101,7 +101,7 @@ static int pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,/* If packet is ecn capable, mark it if drop probability * is lower than 10%, else drop it. */ - q->stats.ecn_mark++; +WRITE_ONCE (q->stats.ecn_mark, q->stats.ecn_mark +1 ); enqueue = true; }
@@ -111,15 +111,15 @@ static int pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,if (!q->params.dq_rate_estimator)pie_set_enqueue_time (skb); - q->stats.packets_in++; +WRITE_ONCE (q->stats.packets_in, q->stats.packets_in +1 );if (qdisc_qlen (sch) > q->stats.maxq) - q->stats.maxq =qdisc_qlen (sch); +WRITE_ONCE (q->stats.maxq,qdisc_qlen (sch));return qdisc_enqueue_tail (skb, sch); } out: - q->stats.dropped++; +WRITE_ONCE (q->stats.dropped, q->stats.dropped +1 ); q->vars.accu_prob =0 ;return qdisc_drop (skb, sch, to_free); }
@@ -260,11 +260,11 @@ void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params, count = count / dtime;if (vars->avg_dq_rate ==0 ) - vars->avg_dq_rate = count; +WRITE_ONCE (vars->avg_dq_rate, count);else - vars->avg_dq_rate = +WRITE_ONCE (vars->avg_dq_rate, (vars->avg_dq_rate - - (vars->avg_dq_rate >>3 )) + (count >>3 ); + (vars->avg_dq_rate >>3 )) + (count >>3 ));/* If the queue has receded below the threshold, we hold * on to the last drain rate calculated, else we reset
@@ -374,7 +374,7 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,if (delta >0 ) {/* prevent overflow */ if (vars->prob < oldprob) { - vars->prob =MAX_PROB ; +WRITE_ONCE (vars->prob,MAX_PROB );/* Prevent normalization error. If probability is at * maximum value already, we normalize it here, and * skip the check to do a non-linear drop in the next
@@ -385,7 +385,7 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars, }else {/* prevent underflow */ if (vars->prob > oldprob) - vars->prob =0 ; +WRITE_ONCE (vars->prob,0 ); }/* Non-linear drop in probability: Reduce drop probability quickly if
@@ -396,7 +396,7 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,/* Reduce drop probability to 98.4% */ vars->prob -= vars->prob /64 ; - vars->qdelay = qdelay; +WRITE_ONCE (vars->qdelay, qdelay); vars->backlog_old = backlog;/* We restart the measurement cycle if the following conditions are met
@@ -494,21 +494,21 @@ static int pie_dump_stats(struct Qdisc *sch, struct gnet_dump *d)struct pie_sched_data *q =qdisc_priv (sch);struct tc_pie_xstats st = { .prob = q->vars.prob <<BITS_PER_BYTE , - .delay = ((u32 )PSCHED_TICKS2NS (q->vars.qdelay)) / + .delay = ((u32 )PSCHED_TICKS2NS (READ_ONCE (q->vars.qdelay))) /NSEC_PER_USEC , - .packets_in = q->stats.packets_in, - .overlimit = q->stats.overlimit, - .maxq = q->stats.maxq, - .dropped = q->stats.dropped, - .ecn_mark = q->stats.ecn_mark, + .packets_in =READ_ONCE (q->stats.packets_in), + .overlimit =READ_ONCE (q->stats.overlimit), + .maxq =READ_ONCE (q->stats.maxq), + .dropped =READ_ONCE (q->stats.dropped), + .ecn_mark =READ_ONCE (q->stats.ecn_mark), };/* avg_dq_rate is only valid if dq_rate_estimator is enabled */ st.dq_rate_estimating = q->params.dq_rate_estimator;/* unscale and return dq_rate in bytes per sec */ -if (q->params.dq_rate_estimator) - st.avg_dq_rate = q->vars.avg_dq_rate * +if (st.dq_rate_estimating) + st.avg_dq_rate =READ_ONCE (q->vars.avg_dq_rate) * (PSCHED_TICKS_PER_SEC ) >>PIE_SCALE ;return gnet_stats_copy_app (d, &st,sizeof (st));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 715/969 net/sched: sch_fq_codel: remove data-races from fq_codel_dump_stats()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit bbfaa73ea6871db03dc05d7f05f00557a8981f25 ]
fq_codel_dump_stats() acquires the qdisc spinlock a bit too late.
Move this acquisition before we fill st.qdisc_stats with live data.
--- net/sched/sch_fq_codel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/sched/sch_fq_codel.c +2 -1
@@ -568,6 +568,8 @@ static int fq_codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d) };struct list_head *pos; +sch_tree_lock (sch); + st.qdisc_stats.maxpacket = q->cstats.maxpacket; st.qdisc_stats.drop_overlimit = q->drop_overlimit; st.qdisc_stats.ecn_mark = q->cstats.ecn_mark;
@@ -576,7 +578,6 @@ static int fq_codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d) st.qdisc_stats.memory_usage = q->memory_usage; st.qdisc_stats.drop_overmemory = q->drop_overmemory; -sch_tree_lock (sch);list_for_each (pos, &q->new_flows) st.qdisc_stats.new_flows_len++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 716/969 net/sched: sch_red: annotate data-races in red_dump_stats()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit a8f5192809caf636d05ba47c144f282cfd0e3839 ]
red_dump_stats() only runs with RTNL held, reading fields that can be changed in qdisc fast path.
Add READ_ONCE()/WRITE_ONCE() annotations.
Alternative would be to acquire the qdisc spinlock, but our long-term goal is to make qdisc dump operations lockless as much as we can.
tc_red_xstats fields don't need to be latched atomically, otherwise this bug would have been caught earlier.
--- net/sched/sch_red.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)
net/sched/sch_red.c +21 -10
@@ -89,17 +89,20 @@ static int red_enqueue(struct sk_buff *skb, struct Qdisc *sch,case RED_PROB_MARK :qdisc_qstats_overlimit (sch);if (!red_use_ecn (q)) { - q->stats.prob_drop++; +WRITE_ONCE (q->stats.prob_drop, + q->stats.prob_drop +1 ); goto congestion_drop; }if (INET_ECN_set_ce (skb)) { - q->stats.prob_mark++; +WRITE_ONCE (q->stats.prob_mark, + q->stats.prob_mark +1 ); skb =tcf_qevent_handle (&q->qe_mark, sch, skb, to_free, &ret);if (!skb)return NET_XMIT_CN | ret; }else if (!red_use_nodrop (q)) { - q->stats.prob_drop++; +WRITE_ONCE (q->stats.prob_drop, + q->stats.prob_drop +1 ); goto congestion_drop; }
@@ -109,17 +112,20 @@ static int red_enqueue(struct sk_buff *skb, struct Qdisc *sch,case RED_HARD_MARK :qdisc_qstats_overlimit (sch);if (red_use_harddrop (q) || !red_use_ecn (q)) { - q->stats.forced_drop++; +WRITE_ONCE (q->stats.forced_drop, + q->stats.forced_drop +1 ); goto congestion_drop; }if (INET_ECN_set_ce (skb)) { - q->stats.forced_mark++; +WRITE_ONCE (q->stats.forced_mark, + q->stats.forced_mark +1 ); skb =tcf_qevent_handle (&q->qe_mark, sch, skb, to_free, &ret);if (!skb)return NET_XMIT_CN | ret; }else if (!red_use_nodrop (q)) { - q->stats.forced_drop++; +WRITE_ONCE (q->stats.forced_drop, + q->stats.forced_drop +1 ); goto congestion_drop; }
@@ -133,7 +139,8 @@ static int red_enqueue(struct sk_buff *skb, struct Qdisc *sch, sch->qstats.backlog += len; sch->q.qlen++; }else if (net_xmit_drop_count (ret)) { - q->stats.pdrop++; +WRITE_ONCE (q->stats.pdrop, + q->stats.pdrop +1 );qdisc_qstats_drop (sch); }return ret;
@@ -461,9 +468,13 @@ static int red_dump_stats(struct Qdisc *sch, struct gnet_dump *d) dev->netdev_ops->ndo_setup_tc (dev,TC_SETUP_QDISC_RED , &hw_stats_request); } - st.early = q->stats.prob_drop + q->stats.forced_drop; - st.pdrop = q->stats.pdrop; - st.marked = q->stats.prob_mark + q->stats.forced_mark; + st.early =READ_ONCE (q->stats.prob_drop) + +READ_ONCE (q->stats.forced_drop); + + st.pdrop =READ_ONCE (q->stats.pdrop); + + st.marked =READ_ONCE (q->stats.prob_mark) + +READ_ONCE (q->stats.forced_mark);return gnet_stats_copy_app (d, &st,sizeof (st)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 717/969 net/sched: sch_sfb: annotate data-races in sfb_dump_stats()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 1ada03fdef82d3d7d2edb9dcd3acc91917675e48 ]
sfb_dump_stats() only runs with RTNL held, reading fields that can be changed in qdisc fast path.
Add READ_ONCE()/WRITE_ONCE() annotations.
Alternative would be to acquire the qdisc spinlock, but our long-term goal is to make qdisc dump operations lockless as much as we can.
tc_sfb_xstats fields don't need to be latched atomically, otherwise this bug would have been caught earlier.
--- net/sched/sch_sfb.c | 54 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 22 deletions(-)
net/sched/sch_sfb.c +32 -22
@@ -130,7 +130,7 @@ static void increment_one_qlen(u32 sfbhash, u32 slot, struct sfb_sched_data *q) sfbhash >>=SFB_BUCKET_SHIFT ;if (b[hash].qlen <0xFFFF ) - b[hash].qlen++; +WRITE_ONCE (b[hash].qlen, b[hash].qlen +1 ); b +=SFB_NUMBUCKETS ;/* next level */ } }
@@ -159,7 +159,7 @@ static void decrement_one_qlen(u32 sfbhash, u32 slot, sfbhash >>=SFB_BUCKET_SHIFT ;if (b[hash].qlen >0 ) - b[hash].qlen--; +WRITE_ONCE (b[hash].qlen, b[hash].qlen -1 ); b +=SFB_NUMBUCKETS ;/* next level */ } }
@@ -179,12 +179,12 @@ static void decrement_qlen(const struct sk_buff *skb, struct sfb_sched_data *q)static void decrement_prob (struct sfb_bucket *b,struct sfb_sched_data *q) { - b->p_mark =prob_minus (b->p_mark, q->decrement); +WRITE_ONCE (b->p_mark,prob_minus (b->p_mark, q->decrement)); }static void increment_prob (struct sfb_bucket *b,struct sfb_sched_data *q) { - b->p_mark =prob_plus (b->p_mark, q->increment); +WRITE_ONCE (b->p_mark,prob_plus (b->p_mark, q->increment)); }static void sfb_zero_all_buckets (struct sfb_sched_data *q)
@@ -202,11 +202,14 @@ static u32 sfb_compute_qlen(u32 *prob_r, u32 *avgpm_r, const struct sfb_sched_daconst struct sfb_bucket *b = &q->bins[q->slot].bins[0 ][0 ];for (i =0 ; i <SFB_LEVELS *SFB_NUMBUCKETS ; i++) { -if (qlen < b->qlen) - qlen = b->qlen; - totalpm += b->p_mark; -if (prob < b->p_mark) - prob = b->p_mark; +u32 b_qlen =READ_ONCE (b->qlen); +u32 b_mark =READ_ONCE (b->p_mark); + +if (qlen < b_qlen) + qlen = b_qlen; + totalpm += b_mark; +if (prob < b_mark) + prob = b_mark; b++; } *prob_r = prob;
@@ -294,7 +297,8 @@ static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch,if (unlikely (sch->q.qlen >= q->limit)) {qdisc_qstats_overlimit (sch); - q->stats.queuedrop++; +WRITE_ONCE (q->stats.queuedrop, + q->stats.queuedrop +1 ); goto drop; }
@@ -347,7 +351,8 @@ static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch,if (unlikely (minqlen >= q->max)) {qdisc_qstats_overlimit (sch); - q->stats.bucketdrop++; +WRITE_ONCE (q->stats.bucketdrop, + q->stats.bucketdrop +1 ); goto drop; }
@@ -373,7 +378,8 @@ static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch, }if (sfb_rate_limit (skb, q)) {qdisc_qstats_overlimit (sch); - q->stats.penaltydrop++; +WRITE_ONCE (q->stats.penaltydrop, + q->stats.penaltydrop +1 ); goto drop; } goto enqueue;
@@ -388,14 +394,17 @@ static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch,* In either case, we want to start dropping packets. */ if (r < (p_min -SFB_MAX_PROB /2 ) *2 ) { - q->stats.earlydrop++; +WRITE_ONCE (q->stats.earlydrop, + q->stats.earlydrop +1 ); goto drop; } }if (INET_ECN_set_ce (skb)) { - q->stats.marked++; +WRITE_ONCE (q->stats.marked, + q->stats.marked +1 ); }else { - q->stats.earlydrop++; +WRITE_ONCE (q->stats.earlydrop, + q->stats.earlydrop +1 ); goto drop; } }
@@ -408,7 +417,8 @@ static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch, sch->q.qlen++;increment_qlen (&cb, q); }else if (net_xmit_drop_count (ret)) { - q->stats.childdrop++; +WRITE_ONCE (q->stats.childdrop, + q->stats.childdrop +1 );qdisc_qstats_drop (sch); }return ret;
@@ -597,12 +607,12 @@ static int sfb_dump_stats(struct Qdisc *sch, struct gnet_dump *d) {struct sfb_sched_data *q =qdisc_priv (sch);struct tc_sfb_xstats st = { - .earlydrop = q->stats.earlydrop, - .penaltydrop = q->stats.penaltydrop, - .bucketdrop = q->stats.bucketdrop, - .queuedrop = q->stats.queuedrop, - .childdrop = q->stats.childdrop, - .marked = q->stats.marked, + .earlydrop =READ_ONCE (q->stats.earlydrop), + .penaltydrop =READ_ONCE (q->stats.penaltydrop), + .bucketdrop =READ_ONCE (q->stats.bucketdrop), + .queuedrop =READ_ONCE (q->stats.queuedrop), + .childdrop =READ_ONCE (q->stats.childdrop), + .marked =READ_ONCE (q->stats.marked), }; st.maxqlen =sfb_compute_qlen (&st.maxprob, &st.avgprob, q);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 718/969 net: dsa: realtek: rtl8365mb: fix mode mask calculation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mieczyslaw Nalewaj <[email protected]>
[ Upstream commit 0c078021d3861966614d5e594ee03587f0c9e74d ]
The RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK macro was shifting the 4-bit mask (0xF) by only (_extint % 2) bits instead of (_extint % 2) * 4. This caused the mask to overlap with the adjacent nibble when configuring odd-numbered external interfaces, selecting the wrong bits entirely.
Align the shift calculation with the existing ...MODE_OFFSET macro.
--- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/realtek/rtl8365mb.c +1 -1
@@ -212,7 +212,7 @@ (_extint) == 2 ? RTL8365MB_DIGITAL_INTERFACE_SELECT_REG1 : \ 0x0)#define RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK (_extint) \ - (0xF << (((_extint) % 2))) + (0xF << (((_extint) % 2) * 4))#define RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET (_extint) \ (((_extint) % 2) * 4)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 719/969 nfp: fix swapped arguments in nfp_encode_basic_qdr() calls
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Kodanev <[email protected]>
[ Upstream commit 4078c5611d7585548b249377ebd60c272e410490 ]
There is a mismatch between the passed arguments and the actual nfp_encode_basic_qdr() function parameter names:
static int nfp_encode_basic_qdr(u64 addr, int dest_island, int cpp_tgt,
int mode, bool addr40, int isld1, int isld0)
{
...But "dest_island" and "cpp_tgt" are swapped at every call-site. For example:
return nfp_encode_basic_qdr(*addr, cpp_tgt, dest_island,
mode, addr40, isld1, isld0);
As a result, nfp_encode_basic_qdr() receives "dest_island" as CPP target type, which is always NFP_CPP_TARGET_QDR(2) for these calls, and "cpp_tgt" as the destination island ID, which can accidentally match or be outside the valid NFP_CPP_TARGET_* types (e.g. '-1' for any destination).
Since code already worked for years, also add extra pr_warn() to error paths in nfp_encode_basic_qdr() to help identify any potential address verification failures.
Detected using the static analysis tool - Svace.
--- .../ethernet/netronome/nfp/nfpcore/nfp_target.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_target.c +11 -6
@@ -435,12 +435,17 @@ static int nfp_encode_basic_qdr(u64 addr, int dest_island, int cpp_tgt,/* Full Island ID and channel bits overlap? */ ret =nfp_decode_basic (addr, &v, cpp_tgt, mode, addr40, isld1, isld0); -if (ret) +if (ret) { +pr_warn ("%s: decode dest_island failed: %d\n" , __func__, ret);return ret; + }/* The current address won't go where expected? */ -if (dest_island !=-1 && dest_island != v) +if (dest_island !=-1 && dest_island != v) { +pr_warn ("%s: dest_island mismatch: current (%d) != decoded (%d)\n" , + __func__, dest_island, v);return -EINVAL ; + }/* If dest_island was -1, we don't care where it goes. */ return 0 ;
@@ -493,7 +498,7 @@ static int nfp_encode_basic(u64 *addr, int dest_island, int cpp_tgt,* the address but we can verify if the existing * contents will point to a valid island. */ -return nfp_encode_basic_qdr (*addr, cpp_tgt, dest_island, +return nfp_encode_basic_qdr (*addr, dest_island, cpp_tgt, mode, addr40, isld1, isld0); iid_lsb = addr40 ?34 :26 ;
@@ -504,7 +509,7 @@ static int nfp_encode_basic(u64 *addr, int dest_island, int cpp_tgt,return 0 ;case 1 :if (cpp_tgt ==NFP_CPP_TARGET_QDR && !addr40) -return nfp_encode_basic_qdr (*addr, cpp_tgt, dest_island, +return nfp_encode_basic_qdr (*addr, dest_island, cpp_tgt, mode, addr40, isld1, isld0); idx_lsb = addr40 ?39 :31 ;
@@ -530,7 +535,7 @@ static int nfp_encode_basic(u64 *addr, int dest_island, int cpp_tgt,* be set before hand and with them select an island. * So we need to confirm that it's at least plausible. */ -return nfp_encode_basic_qdr (*addr, cpp_tgt, dest_island, +return nfp_encode_basic_qdr (*addr, dest_island, cpp_tgt, mode, addr40, isld1, isld0);/* Make sure we compare against isldN values
@@ -551,7 +556,7 @@ static int nfp_encode_basic(u64 *addr, int dest_island, int cpp_tgt,* iid<1> = addr<30> = channel<0> * channel<1> = addr<31> = Index */ -return nfp_encode_basic_qdr (*addr, cpp_tgt, dest_island, +return nfp_encode_basic_qdr (*addr, dest_island, cpp_tgt, mode, addr40, isld1, isld0); isld[0 ] &= ~3 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 720/969 tipc: fix double-free in tipc_buf_append()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
[ Upstream commit d293ca716e7d5dffdaecaf6b9b2f857a33dc3d3a ]
tipc_msg_validate() can potentially reallocate the skb it is validating, freeing the old one. In tipc_buf_append(), it was being called with a pointer to a local variable which was a copy of the caller's skb pointer.
If the skb was reallocated and validation subsequently failed, the error handling path would free the original skb pointer, which had already been freed, leading to double-free.
Fix this by checking if head now points to a newly allocated reassembled skb. If it does, reassign *headbuf for later freeing operations.
--- net/tipc/msg.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
net/tipc/msg.c +13 -1
@@ -177,8 +177,20 @@ int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf)if (fragid ==LAST_FRAGMENT ) {TIPC_SKB_CB (head)->validated =0 ; -if (unlikely (!tipc_msg_validate (&head))) + +/* If the reassembled skb has been freed in +* tipc_msg_validate() because of an invalid truesize, +* then head will point to a newly allocated reassembled +* skb, while *headbuf points to freed reassembled skb. +* In such cases, correct *headbuf for freeing the newly +* allocated reassembled skb later. +*/ +if (unlikely (!tipc_msg_validate (&head))) { +if (head != *headbuf) + *headbuf = head; goto err; + } + *buf = head;TIPC_SKB_CB (head)->tail =NULL ; *headbuf =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 721/969 vhost_net: fix sleeping with preempt-disabled in vhost_net_busy_poll()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kohei Enju <[email protected]>
[ Upstream commit e08a9fac5cf8c3fecf4755e7e3ac059f78b8f83d ]
syzbot reported "sleeping function called from invalid context" in vhost_net_busy_poll().
Commit 030881372460 ("vhost_net: basic polling support") introduced a busy-poll loop and preempt_{disable,enable}() around it, where each iteration calls a sleepable function inside the loop.
The purpose of disabling preemption was to keep local_clock()-based timeout accounting on a single CPU, rather than as a requirement of busy-poll itself:
https://lore.kernel.org/[email protected]
Quoted 1 line
From this perspective,
migrate_disable()is sufficient here, so replace
preempt_disable() with migrate_disable(), avoiding sleepable accesses from a preempt-disabled context.
--- drivers/vhost/net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vhost/net.c +2 -2
@@ -546,7 +546,7 @@ static void vhost_net_busy_poll(struct vhost_net *net, busyloop_timeout = poll_rx ? rvq->busyloop_timeout: tvq->busyloop_timeout; -preempt_disable (); +migrate_disable (); endtime =busy_clock () + busyloop_timeout;while (vhost_can_busy_poll (endtime)) {
@@ -563,7 +563,7 @@ static void vhost_net_busy_poll(struct vhost_net *net,cpu_relax (); } -preempt_enable (); +migrate_enable ();if (poll_rx ||sock_has_rx_data (sock))vhost_net_busy_poll_try_queue (net, vq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 722/969 fs/adfs: validate nzones in adfs_validate_bblk()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bae Yeonju <[email protected]>
[ Upstream commit dd9d3e16c2d5fa166e13dce07413be51f42c8f5d ]
Reject ADFS disc records with a zero zone count during boot block validation, before the disc record is used.
When nzones is 0, adfs_read_map() passes it to kmalloc_array(0, ...) which returns ZERO_SIZE_PTR, and adfs_map_layout() then writes to dm[-1], causing an out-of-bounds write before the allocated buffer.
adfs_validate_dr0() already rejects nzones != 1 for old-format images. Add the equivalent check to adfs_validate_bblk() for new-format images so that a crafted image with nzones == 0 is rejected at probe time.
Found by syzkaller.
--- fs/adfs/super.c | 3 +++ 1 file changed, 3 insertions(+)
fs/adfs/super.c +3 -0
@@ -343,6 +343,9 @@ static int adfs_validate_bblk(struct super_block *sb, struct buffer_head *bh,if (adfs_checkdiscrecord (dr))return -EILSEQ ; +if ((dr->nzones | dr->nzones_high <<8 ) ==0 ) +return -EILSEQ ; + *drp = dr;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 723/969 rtc: abx80x: Disable alarm feature if no interrupt attached
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Pighin (Nokia) <[email protected]>
[ Upstream commit 0fedce7244e4b85c049ce579c87e298a1b0b811d ]
Commit 795cda8338ea ("rtc: interface: Fix long-standing race when setting alarm") exposed an issue where the rtc-abx80x driver does not clear the alarm feature bit, but instead relies on the set_alarm operation to return invalid.
For example, when a RTC_UIE_ON ioctl is handled, it should abort at the feature validation. Instead, it proceeds to the rtc_timer_enqueue(), which used to return an error from the set_alarm call. However, following the race condition handling, which likely should not be discarding predecing errors, a success condition is returned to the ioctl() caller. This results in (for example):
hwclock: select() to /dev/rtc0 to wait for clock tick timed out
Notwithstanding the validity of the race condition handling, if an interrupt wasn't specified, or could not be attached, the driver should clear the alarm feature bit.
--- drivers/rtc/rtc-abx80x.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/rtc/rtc-abx80x.c +2 -0
@@ -836,6 +836,8 @@ static int abx80x_probe(struct i2c_client *client, client->irq =0 ; } } +if (client->irq <=0 ) +clear_bit (RTC_FEATURE_ALARM , priv->rtc->features); err =rtc_add_group (priv->rtc, &rtc_calib_attr_group);if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 724/969 fbdev: offb: fix PCI device reference leak on probe failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 869b93ba04088713596e68453c1146f52f713290 ]
offb_init_nodriver() gets a referenced PCI device with pci_get_device(). If pci_enable_device() fails, the function returns without dropping that reference.
Release the PCI device reference before returning from the pci_enable_device() failure path.
--- drivers/video/fbdev/offb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/video/fbdev/offb.c +6 -1
@@ -646,8 +646,13 @@ static void offb_init_nodriver(struct platform_device *parent, struct device_nod vid =be32_to_cpup (vidp); did =be32_to_cpup (didp); pdev =pci_get_device (vid, did,NULL ); -if (!pdev ||pci_enable_device (pdev)) +if (!pdev)return ; + +if (pci_enable_device (pdev)) { +pci_dev_put (pdev); +return ; + } }#endif /* kludge for valkyrie */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 725/969 mailbox: mailbox-test: free channels on probe error
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wolfram Sang <[email protected]>
[ Upstream commit c02053a9055d5fdfd32432287cca8958db1d5bc5 ]
On probe error, free the previously obtained channels. This not only prevents a leak, but also UAF scenarios because the client structure will be removed nonetheless because it was allocated with devm.
--- drivers/mailbox/mailbox-test.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/mailbox/mailbox-test.c +12 -3
@@ -405,18 +405,27 @@ static int mbox_test_probe(struct platform_device *pdev)if (tdev->rx_channel) { tdev->rx_buffer =devm_kzalloc (&pdev->dev,MBOX_MAX_MSG_LEN ,GFP_KERNEL ); -if (!tdev->rx_buffer) -return -ENOMEM ; +if (!tdev->rx_buffer) { + ret = -ENOMEM ; + goto err_free_chans; + } } ret =mbox_test_add_debugfs (pdev, tdev);if (ret) -return ret; + goto err_free_chans;init_waitqueue_head (&tdev->waitq);dev_info (&pdev->dev,"Successfully registered\n" );return 0 ; + +err_free_chans: +if (tdev->tx_channel) +mbox_free_channel (tdev->tx_channel); +if (tdev->rx_channel) +mbox_free_channel (tdev->rx_channel); +return ret; }static int mbox_test_remove (struct platform_device *pdev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 726/969 cgroup/rdma: fix integer overflow in rdmacg_try_charge()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: cuitao <[email protected]>
[ Upstream commit c802f460dd485c1332b5a35e7adcfb2bc22536a2 ]
The expression rpool->resources[index].usage + 1 is computed in int arithmetic before being assigned to s64 variable new. When usage equals INT_MAX (the default "max" value), the addition overflows to INT_MIN. This negative value then passes the new > max check incorrectly, allowing a charge that should be rejected and corrupting usage to negative.
Fix by casting usage to s64 before the addition so the arithmetic is done in 64-bit.
--- kernel/cgroup/rdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cgroup/rdma.c +1 -1
@@ -281,7 +281,7 @@ int rdmacg_try_charge(struct rdma_cgroup **rdmacg, ret =PTR_ERR (rpool); goto err; }else { - new = rpool->resources[index].usage +1 ; + new = (s64 )rpool->resources[index].usage +1 ;if (new > rpool->resources[index].max) { ret = -EAGAIN ; goto err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 727/969 mailbox: add sanity check for channel array
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wolfram Sang <[email protected]>
[ Upstream commit c1aad75595fb67edc7fda8af249d3b886efa1be9 ]
Fail gracefully if there is no channel array attached to the mailbox controller. Otherwise the later dereference will cause an OOPS which might not be seen because mailbox controllers might instantiate very early. Remove the comment explaining the obvious while here.
--- drivers/mailbox/mailbox.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mailbox/mailbox.c +1 -2
@@ -524,8 +524,7 @@ int mbox_controller_register(struct mbox_controller *mbox) {int i, txdone; -/* Sanity check */ -if (!mbox || !mbox->dev || !mbox->ops || !mbox->num_chans) +if (!mbox || !mbox->dev || !mbox->ops || !mbox->chans || !mbox->num_chans)return -EINVAL ;if (mbox->txdone_irq)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 728/969 mailbox: mailbox-test: dont free the reused channel
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wolfram Sang <[email protected]>
[ Upstream commit 88ebadbf0deefdaccdab868b44ff70a0a257f473 ]
The RX channel can be aliased to the TX channel if it has a different MMIO. This special case needs to be handled when freeing the channels otherwise a double-free occurs.
--- drivers/mailbox/mailbox-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mailbox/mailbox-test.c +2 -2
@@ -423,7 +423,7 @@ static int mbox_test_probe(struct platform_device *pdev) err_free_chans:if (tdev->tx_channel)mbox_free_channel (tdev->tx_channel); -if (tdev->rx_channel) +if (tdev->rx_channel && tdev->rx_channel != tdev->tx_channel)mbox_free_channel (tdev->rx_channel);return ret; }
@@ -436,7 +436,7 @@ static int mbox_test_remove(struct platform_device *pdev)if (tdev->tx_channel)mbox_free_channel (tdev->tx_channel); -if (tdev->rx_channel) +if (tdev->rx_channel && tdev->rx_channel != tdev->tx_channel)mbox_free_channel (tdev->rx_channel);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 729/969 mailbox: mailbox-test: initialize struct earlier
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wolfram Sang <[email protected]>
[ Upstream commit bbcf9af68bfedb3d9cc3c7eae62f5c844d8b78b9 ]
The waitqueue must be initialized before the debugfs files are created because from that time, requests from userspace can already be made. Similarily, drvdata and spinlock needs to be initialized before we request the channel, otherwise dangling irqs might run into problems like a NULL pointer exception.
--- drivers/mailbox/mailbox-test.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/mailbox/mailbox-test.c +6 -7
@@ -365,6 +365,12 @@ static int mbox_test_probe(struct platform_device *pdev)if (!tdev)return -ENOMEM ; + tdev->dev = &pdev->dev; +spin_lock_init (&tdev->lock); +mutex_init (&tdev->mutex); +init_waitqueue_head (&tdev->waitq); +platform_set_drvdata (pdev, tdev); +/* It's okay for MMIO to be NULL */ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); tdev->tx_mmio =devm_ioremap_resource (&pdev->dev, res);
@@ -396,12 +402,6 @@ static int mbox_test_probe(struct platform_device *pdev)if (!tdev->rx_channel && (tdev->rx_mmio != tdev->tx_mmio)) tdev->rx_channel = tdev->tx_channel; - tdev->dev = &pdev->dev; -platform_set_drvdata (pdev, tdev); - -spin_lock_init (&tdev->lock); -mutex_init (&tdev->mutex); -if (tdev->rx_channel) { tdev->rx_buffer =devm_kzalloc (&pdev->dev,MBOX_MAX_MSG_LEN ,GFP_KERNEL );
@@ -415,7 +415,6 @@ static int mbox_test_probe(struct platform_device *pdev)if (ret) goto err_free_chans; -init_waitqueue_head (&tdev->waitq);dev_info (&pdev->dev,"Successfully registered\n" );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 730/969 mailbox: mailbox-test: make data_ready a per-instance variable
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wolfram Sang <[email protected]>
[ Upstream commit 6e937f4e769e60947909e3525965f0137b9039e8 ]
While not the default case, multiple tests can be run simultaneously. Then, data_ready being a global variable will be overwritten and the per-instance lock will not help. Turn the global variable into a per-instance one to avoid this problem.
--- drivers/mailbox/mailbox-test.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/mailbox/mailbox-test.c +4 -5
@@ -27,8 +27,6 @@#define MBOX_HEXDUMP_MAX_LEN (MBOX_HEXDUMP_LINE_LEN * \ (MBOX_MAX_MSG_LEN / MBOX_BYTES_PER_LINE)) -static bool mbox_data_ready; -struct mbox_test_device {struct device *dev;void __iomem *tx_mmio;
@@ -41,6 +39,7 @@ struct mbox_test_device {spinlock_t lock;struct mutex mutex;wait_queue_head_t waitq; +bool data_ready;struct fasync_struct *async_queue;struct dentry *root_debugfs_dir; };
@@ -161,7 +160,7 @@ static bool mbox_test_message_data_ready(struct mbox_test_device *tdev)unsigned long flags;spin_lock_irqsave (&tdev->lock, flags); - data_ready = mbox_data_ready; + data_ready = tdev->data_ready;spin_unlock_irqrestore (&tdev->lock, flags);return data_ready;
@@ -226,7 +225,7 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf, *(touser + l) ='\0' ;memset (tdev->rx_buffer,0 ,MBOX_MAX_MSG_LEN ); - mbox_data_ready = false; + tdev->data_ready = false;spin_unlock_irqrestore (&tdev->lock, flags);
@@ -296,7 +295,7 @@ static void mbox_test_receive_message(struct mbox_client *client, void *message) message, MBOX_MAX_MSG_LEN);memcpy (tdev->rx_buffer, message,MBOX_MAX_MSG_LEN ); } - mbox_data_ready = true; + tdev->data_ready = true;spin_unlock_irqrestore (&tdev->lock, flags);wake_up_interruptible (&tdev->waitq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 731/969 btrfs: fix double-decrement of bytes_may_use in submit_one_async_extent()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Harmstone <[email protected]>
[ Upstream commit 82323b1a7088b7a5c3e528a5d634bff447fa286f ]
submit_one_async_extent() calls btrfs_reserve_extent(), which decrements bytes_may_use. If the call btrfs_create_io_em() fails, we jump to out_free_reserve, which calls extent_clear_unlock_delalloc().
Because we're specifying EXTENT_DO_ACCOUNTING, i.e. EXTENT_CLEAR_META_RESV | EXTENT_CLEAR_DATA_RESV, this decreases bytes_may_use again. This can lead to problems later on, as an initial write can fail only for the writeback to silently ENOSPC.
Fix this by replacing EXTENT_DO_ACCOUNTING with EXTENT_CLEAR_META_RESV. This parallels a4fe134fc1d8eb ("btrfs: fix a double release on reserved extents in cow_one_range()"), which is the same fix in cow_one_range().
--- fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/inode.c +1 -1
@@ -1069,7 +1069,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode,extent_clear_unlock_delalloc (inode, start, end,NULL ,EXTENT_LOCKED |EXTENT_DELALLOC |EXTENT_DELALLOC_NEW | -EXTENT_DEFRAG |EXTENT_DO_ACCOUNTING , +EXTENT_DEFRAG |EXTENT_CLEAR_META_RESV ,PAGE_UNLOCK |PAGE_START_WRITEBACK |PAGE_END_WRITEBACK |PAGE_SET_ERROR );free_async_extent_pages (async_extent);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 732/969 tracing: branch: Fix inverted check on stat tracer registration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 3b75dd76e64a04771861bb5647951c264919e563 ]
init_annotated_branch_stats() and all_annotated_branch_stats() check the return value of register_stat_tracer() with "if (!ret)", but register_stat_tracer() returns 0 on success and a negative errno on failure. The inverted check causes the warning to be printed on every successful registration, e.g.:
Warning: could not register annotated branches stats
while leaving real failures silent. The initcall also returned a hard-coded 1 instead of the actual error.
Invert the check and propagate ret so that the warning fires on real errors and the initcall reports the correct status.
--- kernel/trace/trace_branch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/trace/trace_branch.c +4 -4
@@ -379,10 +379,10 @@ __init static int init_annotated_branch_stats(void)int ret; ret =register_stat_tracer (&annotated_branch_stats); -if (!ret) { +if (ret) {printk (KERN_WARNING "Warning: could not register " "annotated branches stats\n" ); -return 1 ; +return ret; }return 0 ; }
@@ -444,10 +444,10 @@ __init static int all_annotated_branch_stats(void)int ret; ret =register_stat_tracer (&all_branch_stats); -if (!ret) { +if (ret) {printk (KERN_WARNING "Warning: could not register " "all branches stats\n" ); -return 1 ; +return ret; }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 733/969 nvmet-tcp: propagate nvmet_tcp_build_pdu_iovec() errors to its callers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maurizio Lombardi <[email protected]>
[ Upstream commit ea8e356acb165cb1fd75537a52e1f66e5e76c538 ]
Currently, when nvmet_tcp_build_pdu_iovec() detects an out-of-bounds PDU length or offset, it triggers nvmet_tcp_fatal_error(cmd->queue) and returns early. However, because the function returns void, the callers are entirely unaware that a fatal error has occurred and that the cmd->recv_msg.msg_iter was left uninitialized.
Callers such as nvmet_tcp_handle_h2c_data_pdu() proceed to blindly overwrite the queue state with queue->rcv_state = NVMET_TCP_RECV_DATA Consequently, the socket receiving loop may attempt to read incoming network data into the uninitialized iterator.
Fix this by shifting the error handling responsibility to the callers.
--- drivers/nvme/target/tcp.c | 51 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 22 deletions(-)
drivers/nvme/target/tcp.c +29 -22
@@ -308,7 +308,7 @@ static void nvmet_tcp_free_cmd_buffers(struct nvmet_tcp_cmd *cmd)static void nvmet_tcp_fatal_error (struct nvmet_tcp_queue *queue); -static void nvmet_tcp_build_pdu_iovec (struct nvmet_tcp_cmd *cmd) +static int nvmet_tcp_build_pdu_iovec (struct nvmet_tcp_cmd *cmd) {struct bio_vec *iov = cmd->iov;struct scatterlist *sg;
@@ -321,22 +321,19 @@ static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd) offset = cmd->rbytes_done; cmd->sg_idx = offset /PAGE_SIZE ; sg_offset = offset %PAGE_SIZE ; -if (!cmd->req.sg_cnt || cmd->sg_idx >= cmd->req.sg_cnt) { -nvmet_tcp_fatal_error (cmd->queue); -return ; - } +if (!cmd->req.sg_cnt || cmd->sg_idx >= cmd->req.sg_cnt) +return -EPROTO ; + sg = &cmd->req.sg[cmd->sg_idx]; sg_remaining = cmd->req.sg_cnt - cmd->sg_idx;while (length) { -if (!sg_remaining) { -nvmet_tcp_fatal_error (cmd->queue); -return ; - } -if (!sg->length || sg->length <= sg_offset) { -nvmet_tcp_fatal_error (cmd->queue); -return ; - } +if (!sg_remaining) +return -EPROTO ; + +if (!sg->length || sg->length <= sg_offset) +return -EPROTO ; +u32 iov_len =min_t (u32, length, sg->length - sg_offset); bvec_set_page(iov, sg_page(sg), iov_len,
@@ -351,6 +348,7 @@ static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd)iov_iter_bvec (&cmd->recv_msg.msg_iter,ITER_DEST , cmd->iov, nr_pages, cmd->pdu_len); +return 0 ; }static void nvmet_tcp_fatal_error (struct nvmet_tcp_queue *queue)
@@ -906,7 +904,7 @@ static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue)return 0 ; } -static void nvmet_tcp_handle_req_failure (struct nvmet_tcp_queue *queue, +static int nvmet_tcp_handle_req_failure (struct nvmet_tcp_queue *queue,struct nvmet_tcp_cmd *cmd,struct nvmet_req *req) {size_t data_len =le32_to_cpu (req->cmd->common.dptr.sgl.length);
@@ -922,19 +920,23 @@ static void nvmet_tcp_handle_req_failure(struct nvmet_tcp_queue *queue,if (!nvme_is_write (cmd->req.cmd) || !data_len || data_len > cmd->req.port->inline_data_size) {nvmet_prepare_receive_pdu (queue); -return ; +return 0 ; } ret =nvmet_tcp_map_data (cmd);if (unlikely (ret)) {pr_err ("queue %d: failed to map data\n" , queue->idx);nvmet_tcp_fatal_error (queue); -return ; +return -EPROTO ; } queue->rcv_state =NVMET_TCP_RECV_DATA ; -nvmet_tcp_build_pdu_iovec (cmd); cmd->flags |=NVMET_TCP_F_INIT_FAILED ; + ret =nvmet_tcp_build_pdu_iovec (cmd); +if (unlikely (ret)) +pr_err ("queue %d: failed to build PDU iovec\n" , queue->idx); + +return ret; }static int nvmet_tcp_handle_h2c_data_pdu (struct nvmet_tcp_queue *queue)
@@ -986,7 +988,10 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) goto err_proto; } cmd->pdu_recv =0 ; -nvmet_tcp_build_pdu_iovec (cmd); +if (unlikely (nvmet_tcp_build_pdu_iovec (cmd))) { +pr_err ("queue %d: failed to build PDU iovec\n" , queue->idx); + goto err_proto; + } queue->cmd = cmd; queue->rcv_state =NVMET_TCP_RECV_DATA ;
@@ -1049,8 +1054,7 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue) req->cmd->common.opcode, le32_to_cpu(req->cmd->common.dptr.sgl.length)); -nvmet_tcp_handle_req_failure (queue, queue->cmd, req); -return 0 ; +return nvmet_tcp_handle_req_failure (queue, queue->cmd, req); } ret =nvmet_tcp_map_data (queue->cmd);
@@ -1067,8 +1071,11 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue)if (nvmet_tcp_need_data_in (queue->cmd)) {if (nvmet_tcp_has_inline_data (queue->cmd)) { queue->rcv_state =NVMET_TCP_RECV_DATA ; -nvmet_tcp_build_pdu_iovec (queue->cmd); -return 0 ; + ret =nvmet_tcp_build_pdu_iovec (queue->cmd); +if (unlikely (ret)) +pr_err ("queue %d: failed to build PDU iovec\n" , + queue->idx); +return ret; }/* send back R2T */ nvmet_tcp_queue_response (&queue->cmd->req);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 734/969 netfilter: arp_tables: fix IEEE1394 ARP payload parsing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 1e8e3f449b1e73b73a843257635b9c50f0cc0f0a ]
Weiming Shi says:
"arp_packet_match() unconditionally parses the ARP payload assuming two hardware addresses are present (source and target). However, IPv4-over-IEEE1394 ARP (RFC 2734) omits the target hardware address field, and arp_hdr_len() already accounts for this by returning a shorter length for ARPHRD_IEEE1394 devices.
As a result, on IEEE1394 interfaces arp_packet_match() advances past a nonexistent target hardware address and reads the wrong bytes for both the target device address comparison and the target IP address. This causes arptables rules to match against garbage data, leading to incorrect filtering decisions: packets that should be accepted may be dropped and vice versa.
The ARP stack in net/ipv4/arp.c (arp_create and arp_process) already handles this correctly by skipping the target hardware address for ARPHRD_IEEE1394. Apply the same pattern to arp_packet_match()."
Mangle the original patch to always return 0 (no match) in case user matches on the target hardware address which is never present in IEEE1394.
Note that this returns 0 (no match) for either normal and inverse match because matching in the target hardware address in ARPHRD_IEEE1394 has never been supported by arptables. This is intentional, matching on the target hardware address should never evaluate true for ARPHRD_IEEE1394.
Moreover, adjust arpt_mangle to drop the packet too as AI suggests:
In arpt_mangle, the logic assumes a standard ARP layout. Because IEEE1394 (FireWire) omits the target hardware address, the linear pointer arithmetic miscalculates the offset for the target IP address. This causes mangling operations to write to the wrong location, leading to packet corruption. To ensure safety, this patch drops packets (NF_DROP) when mangling is requested for these fields on IEEE1394 devices, as the current implementation cannot correctly map the FireWire ARP payload.
This omits both mangling target hardware and IP address. Even if IP address mangling should be possible in IEEE1394, this would require to adjust arpt_mangle offset calculation, which has never been supported.
Based on patch from Weiming Shi <[email protected]>.
--- net/ipv4/netfilter/arp_tables.c | 18 +++++++++++++++--- net/ipv4/netfilter/arpt_mangle.c | 8 ++++++++ 2 files changed, 23 insertions(+), 3 deletions(-)
net/ipv4/netfilter/arp_tables.c +15 -3
@@ -110,13 +110,25 @@ static inline int arp_packet_match(const struct arphdr *arphdr, arpptr += dev->addr_len;memcpy (&src_ipaddr, arpptr,sizeof (u32)); arpptr +=sizeof (u32); - tgt_devaddr = arpptr; - arpptr += dev->addr_len; + +if (IS_ENABLED (CONFIG_FIREWIRE_NET ) && dev->type ==ARPHRD_IEEE1394 ) { +if (unlikely (memchr_inv (arpinfo->tgt_devaddr.mask,0 , +sizeof (arpinfo->tgt_devaddr.mask)))) +return 0 ; + + tgt_devaddr =NULL ; + }else { + tgt_devaddr = arpptr; + arpptr += dev->addr_len; + }memcpy (&tgt_ipaddr, arpptr,sizeof (u32));if (NF_INVF (arpinfo,ARPT_INV_SRCDEVADDR ,arp_devaddr_compare (&arpinfo->src_devaddr, src_devaddr, - dev->addr_len)) || + dev->addr_len))) +return 0 ; + +if (tgt_devaddr &&NF_INVF (arpinfo,ARPT_INV_TGTDEVADDR ,arp_devaddr_compare (&arpinfo->tgt_devaddr, tgt_devaddr, dev->addr_len)))
net/ipv4/netfilter/arpt_mangle.c +8 -0
@@ -40,6 +40,10 @@ target(struct sk_buff *skb, const struct xt_action_param *par) } arpptr += pln;if (mangle->flags &ARPT_MANGLE_TDEV ) { +if (unlikely (IS_ENABLED (CONFIG_FIREWIRE_NET ) && + skb->dev->type ==ARPHRD_IEEE1394 )) +return NF_DROP ; +if (ARPT_DEV_ADDR_LEN_MAX < hln || (arpptr + hln >skb_tail_pointer (skb)))return NF_DROP ;
@@ -47,6 +51,10 @@ target(struct sk_buff *skb, const struct xt_action_param *par) } arpptr += hln;if (mangle->flags &ARPT_MANGLE_TIP ) { +if (unlikely (IS_ENABLED (CONFIG_FIREWIRE_NET ) && + skb->dev->type ==ARPHRD_IEEE1394 )) +return NF_DROP ; +if (ARPT_MANGLE_ADDR_LEN_MAX < pln || (arpptr + pln >skb_tail_pointer (skb)))return NF_DROP ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 735/969 nvme-pci: fix missed admin queue sq doorbell write
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Keith Busch <[email protected]>
[ Upstream commit 1cc4cdae2a3b7730d462d69e30f213fd2efe7807 ]
We can batch admin commands submitted through io_uring_cmd passthrough, which means bd->last may be false and skips the doorbell write to aggregate multiple commands per write. If a subsequent command can't be dispatched for whatever reason, we have to provide the blk-mq ops' commit_rqs callback in order to ensure we properly update the doorbell.
--- drivers/nvme/host/pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/pci.c +1 -0
@@ -1756,6 +1756,7 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid, bool polled)static const struct blk_mq_ops nvme_mq_admin_ops = { .queue_rq = nvme_queue_rq, .complete = nvme_pci_complete_rq, + .commit_rqs = nvme_commit_rqs, .init_hctx = nvme_admin_init_hctx, .init_request = nvme_pci_init_request, .timeout = nvme_timeout,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 736/969 drm/amdgpu: fix spelling typos
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandre Demers <[email protected]>
[ Upstream commit ce43abd7ec9464cf954f90e1c69e11768b02fa0a ]
Found some typos while exploring amdgpu code.
Stable-dep-of: 13e4cf116dbf ("drm/amdgpu/uvd3.1: Don't validate the firmware when already validated")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 +- drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c | 3 ++- drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
@@ -256,7 +256,7 @@ void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc* @adev: amdgpu device structure holding all necessary information * @mc: memory controller structure holding memory information * -* Function will place try to place GART before or after VRAM. +* Function will try to place GART before or after VRAM. * If GART size is bigger than space left then we ajust GART size. * Thus function will never fails. */
drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c +3 -3
@@ -98,7 +98,7 @@ static void uvd_v3_1_ring_emit_ib(struct amdgpu_ring *ring, }/** -* uvd_v3_1_ring_emit_fence - emit an fence & trap command +* uvd_v3_1_ring_emit_fence - emit a fence & trap command * * @ring: amdgpu_ring pointer * @addr: address
@@ -242,7 +242,7 @@ static void uvd_v3_1_mc_resume(struct amdgpu_device *adev)uint64_t addr;uint32_t size; -/* programm the VCPU memory controller bits 0-27 */ +/* program the VCPU memory controller bits 0-27 */ addr = (adev->uvd.inst->gpu_addr +AMDGPU_UVD_FIRMWARE_OFFSET ) >>3 ; size =AMDGPU_UVD_FIRMWARE_SIZE (adev) >>3 ;WREG32 (mmUVD_VCPU_CACHE_OFFSET0, addr);
@@ -416,7 +416,7 @@ static int uvd_v3_1_start(struct amdgpu_device *adev)/* Set the write pointer delay */ WREG32 (mmUVD_RBC_RB_WPTR_CNTL,0 ); -/* programm the 4GB memory segment for rptr and ring buffer */ +/* Program the 4GB memory segment for rptr and ring buffer */ WREG32 (mmUVD_LMI_EXT40_ADDR,upper_32_bits (ring->gpu_addr) | (0x7 <<16 ) | (0x1 <<31 ));
drivers/gpu/drm/amd/amdgpu/uvd_v4_2.c +2 -1
@@ -298,7 +298,7 @@ static int uvd_v4_2_start(struct amdgpu_device *adev)/* enable VCPU clock */ WREG32 (mmUVD_VCPU_CNTL,1 <<9 ); -/* disable interupt */ +/* disable interrupt */ WREG32_P (mmUVD_MASTINT_EN,0 , ~(1 <<1 ));#ifdef __BIG_ENDIAN
@@ -308,6 +308,7 @@ static int uvd_v4_2_start(struct amdgpu_device *adev)#endif WREG32 (mmUVD_LMI_SWAP_CNTL, lmi_swap_cntl);WREG32 (mmUVD_MP_SWAP_CNTL, mp_swap_cntl); +/* initialize UVD memory controller */ WREG32 (mmUVD_LMI_CTRL,0x203108 );
drivers/gpu/drm/amd/amdgpu/vce_v2_0.c +1 -1
@@ -278,7 +278,7 @@ static int vce_v2_0_stop(struct amdgpu_device *adev)int status;if (vce_v2_0_lmi_clean (adev)) { -DRM_INFO ("vce is not idle \n" ); +DRM_INFO ("VCE is not idle \n" );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 737/969 drm/amdgpu/uvd3.1: Dont validate the firmware when already validated
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit 13e4cf116dbf7a1fb8123a59bea2c098f30d3736 ]
UVD 3.1 firmware validation seems to always fail after attempting it when it had already been validated. (This works similarly with the VCE 1.0 as well.)
Don't attempt repeating the validation when it's already done.
This caused issues in situations when the system isn't able to suspend the GPU properly and so the GPU isn't actually powered down. Then amdgpu would fail when calling the IP block resume function.
--- drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c +10 -0
@@ -242,6 +242,10 @@ static void uvd_v3_1_mc_resume(struct amdgpu_device *adev)uint64_t addr;uint32_t size; +/* When the keyselect is already set, don't perturb it. */ +if (RREG32 (mmUVD_FW_START)) +return ; +/* program the VCPU memory controller bits 0-27 */ addr = (adev->uvd.inst->gpu_addr +AMDGPU_UVD_FIRMWARE_OFFSET ) >>3 ; size =AMDGPU_UVD_FIRMWARE_SIZE (adev) >>3 ;
@@ -284,6 +288,12 @@ static int uvd_v3_1_fw_validate(struct amdgpu_device *adev)int i;uint32_t keysel = adev->uvd.keyselect; +if (RREG32 (mmUVD_FW_START) &UVD_FW_STATUS__PASS_MASK ) { +dev_dbg (adev->dev,"UVD keyselect already set: 0x%x (on CPU: 0x%x)\n" , +RREG32 (mmUVD_FW_START), adev->uvd.keyselect); +return 0 ; + } +WREG32 (mmUVD_FW_START, keysel);for (i =0 ; i <10 ; ++i) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 738/969 drm/amdgpu/gfx6: Support harvested SI chips with disabled TCCs (v2)
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit fe2b84f9228e2a0903221a4d0d8c350b018e9c0c ]
This commit fixes amdgpu to work on the Radeon HD 7870 XT which has never worked with the Linux open source drivers before.
Some boards have "harvested" chips, meaning that some parts of the chip are disabled and fused, and it's sold for cheaper and under a different marketing name.
On a harvested chip, any of the following can be disabled:
- CUs (Compute Units)
- RBs (Render Backend, aka. ROP)
- Memory channels (ie. the chip has a lower bandwidth)
- TCCs (ie. less L2 cache)
Handle chips with harvested TCCs by patching the registers that configure how TCCs are mapped.
If some TCCs are disabled, we need to make sure that the disabled TCCs are not used, and the remaining TCCs are used optimally.
TCP_CHAN_STEER_LO/HI control which TCC is used by TCP channels. TCP_ADDR_CONFIG.NUM_TCC_BANKS controls how many channels are used.
Note that the TCC configuration is highly relevant to performance. Suboptimal configuration (eg. CHAN_STEER=0) can significantly reduce gaming performance.
For optimal performance:
- Rely on the CHAN_STEER from the golden registers table, only skip disabled TCCs but keep the mapping order.
- Limit NUM_TCC_BANKS to number of active TCCs to avoid thrashing, which performs better than using the same TCC twice.
v2:
- Also consider CGTS_USER_TCC_DISABLE for disabled TCCs.
--- drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +66 -0
@@ -1568,6 +1568,71 @@ static void gfx_v6_0_setup_spi(struct amdgpu_device *adev)mutex_unlock (&adev->grbm_idx_mutex); } +/** +* gfx_v6_0_setup_tcc() - setup which TCCs are used +* +* @adev: amdgpu_device pointer +* +* Verify whether the current GPU has any TCCs disabled, +* which can happen when the GPU is harvested and some +* memory channels are disabled, reducing the memory bus width. +* For example, on the Radeon HD 7870 XT (Tahiti LE). +* +* If some TCCs are disabled, we need to make sure that +* the disabled TCCs are not used, and the remaining TCCs +* are used optimally. +* +* TCP_CHAN_STEER_LO/HI control which TCC is used by TCP channels. +* TCP_ADDR_CONFIG.NUM_TCC_BANKS controls how many channels are used. +* +* For optimal performance: +* - Rely on the CHAN_STEER from the golden registers table, +* only skip disabled TCCs but keep the mapping order. +* - Limit NUM_TCC_BANKS to number of active TCCs to avoid thrashing, +* which performs better than using the same TCC twice. +*/ +static void gfx_v6_0_setup_tcc (struct amdgpu_device *adev) +{ +u32 i, tcc, tcp_addr_config, num_active_tcc =0 ; +u64 chan_steer, patched_chan_steer =0 ; +const u32 num_max_tcc = adev->gfx.config.max_texture_channel_caches; +const u32 dis_tcc_mask = +amdgpu_gfx_create_bitmask (num_max_tcc) & + (REG_GET_FIELD (RREG32 (mmCGTS_TCC_DISABLE), +CGTS_TCC_DISABLE ,TCC_DISABLE ) | +REG_GET_FIELD (RREG32 (mmCGTS_USER_TCC_DISABLE), +CGTS_USER_TCC_DISABLE ,TCC_DISABLE )); + +/* When no TCC is disabled, the golden registers table already has optimal TCC setup */ +if (!dis_tcc_mask) +return ; + +/* Each 4-bit nibble contains the index of a TCC used by all TCPs */ + chan_steer =RREG32 (mmTCP_CHAN_STEER_LO) | ((u64 )RREG32 (mmTCP_CHAN_STEER_HI) <<32ull ); + +/* Patch the TCP to TCC mapping to skip disabled TCCs */ +for (i =0 ; i < num_max_tcc; ++i) { + tcc = (chan_steer >> (u64)(4 * i)) &0xf ; + +if (!((1 << tcc) & dis_tcc_mask)) { +/* Copy enabled TCC indices to the patched register value. */ + patched_chan_steer |= (u64 )tcc << (u64)(4 * num_active_tcc); + ++num_active_tcc; + } + } + +WARN_ON (num_active_tcc != num_max_tcc -hweight32 (dis_tcc_mask)); + +/* Patch number of TCCs used by TCPs */ + tcp_addr_config =REG_SET_FIELD (RREG32 (mmTCP_ADDR_CONFIG), +TCP_ADDR_CONFIG ,NUM_TCC_BANKS , + num_active_tcc -1 ); + +WREG32 (mmTCP_ADDR_CONFIG, tcp_addr_config); +WREG32 (mmTCP_CHAN_STEER_HI,upper_32_bits (patched_chan_steer)); +WREG32 (mmTCP_CHAN_STEER_LO,lower_32_bits (patched_chan_steer)); +} +static void gfx_v6_0_config_init (struct amdgpu_device *adev) { adev->gfx.config.double_offchip_lds_buf =0 ;
@@ -1726,6 +1791,7 @@ static void gfx_v6_0_constants_init(struct amdgpu_device *adev)gfx_v6_0_tiling_mode_table_init (adev);gfx_v6_0_setup_rb (adev); +gfx_v6_0_setup_tcc (adev);gfx_v6_0_setup_spi (adev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 739/969 netfilter: xt_policy: fix strict mode inbound policy matching
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiexun Wang <[email protected]>
[ Upstream commit 4b2b4d7d4e203c92db8966b163edfacb1f0e1e29 ]
match_policy_in() walks sec_path entries from the last transform to the first one, but strict policy matching needs to consume info->pol[] in the same forward order as the rule layout.
Derive the strict-match policy position from the number of transforms already consumed so that multi-element inbound rules are matched consistently.
--- net/netfilter/xt_policy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_policy.c +1 -1
@@ -63,7 +63,7 @@ match_policy_in(const struct sk_buff *skb, const struct xt_policy_info *info,return 0 ;for (i = sp->len -1 ; i >=0 ; i--) { - pos = strict ? i - sp->len +1 :0 ; + pos = strict ? sp->len - i -1 :0 ;if (pos >= info->len)return 0 ; e = &info->pol[pos];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 740/969 netfilter: nf_conntrack_sip: dont use simple_strtoul
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 8cf6809cddcbe301aedfc6b51bcd4944d45795f6 ]
Replace unsafe port parsing in epaddr_len(), ct_sip_parse_header_uri(), and ct_sip_parse_request() with a new sip_parse_port() helper that validates each digit against the buffer limit, eliminating the use of simple_strtoul() which assumes NUL-terminated strings.
The previous code dereferenced pointers without bounds checks after sip_parse_addr() and relied on simple_strtoul() on non-NUL-terminated skb data. A port that reaches the buffer limit without a trailing character is also rejected as malformed.
Also get rid of all simple_strtoul() usage in conntrack, prefer a stricter version instead. There are intentional changes:
- Bail out if number is > UINT_MAX and indicate a failure, same for too long sequences.
While we do accept 05535 as port 5535, we will not accept e.g. 'sip:10.0.0.1:005060'. While its syntactically valid under RFC 3261, we should restrict this to not waste cycles when presented with malformed packets with 64k '0' characters.
- Force base 10 in ct_sip_parse_numerical_param(). This is used to fetch 'expire=' and 'rports='; both are expected to use base-10.
- In nf_nat_sip.c, only accept the parsed value if its within the 1k-64k range.
- epaddr_len now returns 0 if the port is invalid, as it already does for invalid ip addresses. This is intentional. nf_conntrack_sip performs lots of guesswork to find the right parts of the message to parse. Being stricter could break existing setups. Connection tracking helpers are designed to allow traffic to pass, not to block it.
Based on an earlier patch from Jenny Guanni Qu <[email protected]>.
--- net/netfilter/nf_conntrack_sip.c | 152 ++++++++++++++++++++++++------- net/netfilter/nf_nat_sip.c | 1 + 2 files changed, 119 insertions(+), 34 deletions(-)
net/netfilter/nf_conntrack_sip.c +118 -34
@@ -181,6 +181,57 @@ static int sip_parse_addr(const struct nf_conn *ct, const char *cp,return 1 ; } +/* Parse optional port number after IP address. +* Returns false on malformed input, true otherwise. +* If port is non-NULL, stores parsed port in network byte order. +* If no port is present, sets *port to default SIP port. +*/ +static bool sip_parse_port (const char *dptr,const char **endp, +const char *limit,__be16 *port) +{ +unsigned int p =0 ; +int len =0 ; + +if (dptr >= limit) +return false; + +if (*dptr !=':' ) { +if (port) + *port =htons (SIP_PORT ); +if (endp) + *endp = dptr; +return true; + } + + dptr++;/* skip ':' */ + +while (dptr < limit &&isdigit (*dptr)) { + p = p *10 + (*dptr -'0' ); + dptr++; + len++; +if (len >5 )/* max "65535" */ +return false; + } + +if (len ==0 ) +return false; + +/* reached limit while parsing port */ +if (dptr >= limit) +return false; + +if (p <1024 || p >65535 ) +return false; + +if (port) + *port =htons (p); + +if (endp) + *endp = dptr; + +return true; +} +/* skip ip address. returns its length. */ static int epaddr_len (const struct nf_conn *ct,const char *dptr,const char *limit,int *shift)
@@ -193,11 +244,8 @@ static int epaddr_len(const struct nf_conn *ct, const char *dptr,return 0 ; } -/* Port number */ -if (*dptr ==':' ) { - dptr++; - dptr +=digits_len (ct, dptr, limit, shift); - } +if (!sip_parse_port (dptr, &dptr, limit,NULL )) +return 0 ;return dptr - aux; }
@@ -228,6 +276,51 @@ static int skp_epaddr_len(const struct nf_conn *ct, const char *dptr,return epaddr_len (ct, dptr, limit, shift); } +/* simple_strtoul stops after first non-number character. +* But as we're not dealing with c-strings, we can't rely on +* hitting \r,\n,\0 etc. before moving past end of buffer. +* +* This is a variant of simple_strtoul, but doesn't require +* a c-string. +* +* If value exceeds UINT_MAX, 0 is returned. +*/ +static unsigned int sip_strtouint (const char *cp,unsigned int len,char **endp) +{ +const unsigned int max =sizeof ("4294967295" ); +unsigned int olen = len; +const char *s = cp; +u64 result =0 ; + +if (len > max) + len = max; + +while (olen >0 &&isdigit (*s)) { +unsigned int value; + +if (len ==0 ) + goto err; + + value = *s -'0' ; + result = result *10 + value; + +if (result >UINT_MAX ) + goto err; + s++; + len--; + olen--; + } + +if (endp) + *endp = (char *)s; + +return result; +err: +if (endp) + *endp = (char *)cp; +return 0 ; +} +/* Parse a SIP request line of the form: * * Request-Line = Method SP Request-URI SP SIP-Version CRLF
@@ -241,7 +334,6 @@ int ct_sip_parse_request(const struct nf_conn *ct, {const char *start = dptr, *limit = dptr + datalen, *end;unsigned int mlen; -unsigned int p;int shift =0 ;/* Skip method and following whitespace */
@@ -267,14 +359,8 @@ int ct_sip_parse_request(const struct nf_conn *ct,if (!sip_parse_addr (ct, dptr, &end, addr, limit, true))return -1 ; -if (end < limit && *end ==':' ) { - end++; - p =simple_strtoul (end, (char **)&end,10 ); -if (p <1024 || p >65535 ) -return -1 ; - *port =htons (p); - }else - *port =htons (SIP_PORT ); +if (!sip_parse_port (end, &end, limit, port)) +return -1 ;if (end == dptr)return 0 ;
@@ -509,7 +595,6 @@ int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, union nf_inet_addr *addr, __be16 *port) { const char *c, *limit = dptr + datalen; -unsigned int p;int ret; ret = ct_sip_walk_headers(ct, dptr, dataoff ? *dataoff : 0, datalen,
@@ -520,14 +605,8 @@ int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr,if (!sip_parse_addr (ct, dptr + *matchoff, &c, addr, limit, true))return -1 ; -if (*c ==':' ) { - c++; - p =simple_strtoul (c, (char **)&c,10 ); -if (p <1024 || p >65535 ) -return -1 ; - *port =htons (p); - }else - *port =htons (SIP_PORT ); +if (!sip_parse_port (c, &c, limit, port)) +return -1 ;if (dataoff) *dataoff = c - dptr;
@@ -609,7 +688,7 @@ int ct_sip_parse_numerical_param(const struct nf_conn *ct, const char *dptr,return 0 ; start +=strlen (name); - *val =simple_strtoul (start, &end,0 ); + *val =sip_strtouint (start, limit - start, (char **)&end);if (start == end)return -1 ;if (matchoff && matchlen) {
@@ -1065,6 +1144,8 @@ static int process_sdp(struct sk_buff *skb, unsigned int protoff, mediaoff = sdpoff;for (i =0 ; i <ARRAY_SIZE (sdp_media_types); ) { +char *end; +if (ct_sip_get_sdp_header (ct, *dptr, mediaoff, *datalen,SDP_HDR_MEDIA ,SDP_HDR_UNSPEC , &mediaoff, &medialen) <=0 )
@@ -1080,8 +1161,8 @@ static int process_sdp(struct sk_buff *skb, unsigned int protoff, mediaoff += t->len; medialen -= t->len; - port =simple_strtoul (*dptr + mediaoff,NULL ,10 ); -if (port ==0 ) + port =sip_strtouint (*dptr + mediaoff, *datalen - mediaoff, (char **)&end); +if (port ==0 || *dptr + mediaoff == end)continue ;if (port <1024 || port >65535 ) {nf_ct_helper_log (skb, ct,"wrong port %u" , port);
@@ -1255,7 +1336,7 @@ static int process_register_request(struct sk_buff *skb, unsigned int protoff,*/ if (ct_sip_get_header (ct, *dptr,0 , *datalen,SIP_HDR_EXPIRES , &matchoff, &matchlen) >0 ) - expires =simple_strtoul (*dptr + matchoff,NULL ,10 ); + expires =sip_strtouint (*dptr + matchoff, *datalen - matchoff,NULL ); ret = ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen, SIP_HDR_CONTACT, NULL,
@@ -1359,7 +1440,7 @@ static int process_register_response(struct sk_buff *skb, unsigned int protoff,if (ct_sip_get_header (ct, *dptr,0 , *datalen,SIP_HDR_EXPIRES , &matchoff, &matchlen) >0 ) - expires =simple_strtoul (*dptr + matchoff,NULL ,10 ); + expires =sip_strtouint (*dptr + matchoff, *datalen - matchoff,NULL );while (1 ) {unsigned int c_expires = expires;
@@ -1419,10 +1500,12 @@ static int process_sip_response(struct sk_buff *skb, unsigned int protoff,struct nf_conn *ct =nf_ct_get (skb, &ctinfo);unsigned int matchoff, matchlen, matchend;unsigned int code, cseq, i; +char *end;if (*datalen <strlen ("SIP/2.0 200" ))return NF_ACCEPT ; - code =simple_strtoul (*dptr +strlen ("SIP/2.0 " ),NULL ,10 ); + code =sip_strtouint (*dptr +strlen ("SIP/2.0 " ), + *datalen -strlen ("SIP/2.0 " ),NULL );if (!code) {nf_ct_helper_log (skb, ct,"cannot get code" );return NF_DROP ;
@@ -1433,8 +1516,8 @@ static int process_sip_response(struct sk_buff *skb, unsigned int protoff,nf_ct_helper_log (skb, ct,"cannot parse cseq" );return NF_DROP ; } - cseq =simple_strtoul (*dptr + matchoff,NULL ,10 ); -if (!cseq && *(*dptr + matchoff) !='0' ) { + cseq =sip_strtouint (*dptr + matchoff, *datalen - matchoff, (char **)&end); +if (*dptr + matchoff == end) {nf_ct_helper_log (skb, ct,"cannot get cseq" );return NF_DROP ; }
@@ -1483,6 +1566,7 @@ static int process_sip_request(struct sk_buff *skb, unsigned int protoff,for (i =0 ; i <ARRAY_SIZE (sip_handlers); i++) {const struct sip_handler *handler; +char *end; handler = &sip_handlers[i];if (handler->request ==NULL )
@@ -1499,8 +1583,8 @@ static int process_sip_request(struct sk_buff *skb, unsigned int protoff,nf_ct_helper_log (skb, ct,"cannot parse cseq" );return NF_DROP ; } - cseq =simple_strtoul (*dptr + matchoff,NULL ,10 ); -if (!cseq && *(*dptr + matchoff) !='0' ) { + cseq =sip_strtouint (*dptr + matchoff, *datalen - matchoff, (char **)&end); +if (*dptr + matchoff == end) {nf_ct_helper_log (skb, ct,"cannot get cseq" );return NF_DROP ; }
@@ -1576,7 +1660,7 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff, &matchoff, &matchlen) <= 0)break ; - clen =simple_strtoul (dptr + matchoff, (char **)&end,10 ); + clen =sip_strtouint (dptr + matchoff, datalen - matchoff, (char **)&end);if (dptr + matchoff == end)break ;
net/netfilter/nf_nat_sip.c +1 -0
@@ -246,6 +246,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff,if (ct_sip_parse_numerical_param (ct, *dptr, matchend, *datalen,"rport=" , &poff, &plen, &n) >0 && + n >=1024 && n <=65535 &&htons (n) == ct->tuplehash[dir].tuple.dst.u.udp.port &&htons (n) != ct->tuplehash[!dir].tuple.src.u.udp.port) {__be16 p = ct->tuplehash[!dir].tuple.src.u.udp.port;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 741/969 drivers/spi-rockchip.c : Remove redundant variable slave
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lizhe <[email protected]>
[ Upstream commit 8c220e6c6da9c2f70a78ba8b3121893b3634a54c ]
variable slave in spi_alloc_master() or spi_alloc_slave() has been assigned. it is not necessary to be assigned again
Stable-dep-of: b4683a239a40 ("spi: rockchip: Read ISR, not IMR, to detect cs-inactive IRQ")
--- drivers/spi/spi-rockchip.c | 1 - 1 file changed, 1 deletion(-)
drivers/spi/spi-rockchip.c +0 -1
@@ -772,7 +772,6 @@ static int rockchip_spi_probe(struct platform_device *pdev)platform_set_drvdata (pdev, ctlr); rs =spi_controller_get_devdata (ctlr); - ctlr->slave = slave_mode;/* Get basic io resource and map it */ mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 742/969 spi: rockchip: switch to use modern name
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Yingliang <[email protected]>
[ Upstream commit 1a3ccff3bc39acc04e69e3a65833d474471598ec ]
Change legacy name master/slave to modern name host/target or controller.
No functional changed.
Stable-dep-of: b4683a239a40 ("spi: rockchip: Read ISR, not IMR, to detect cs-inactive IRQ")
--- drivers/spi/spi-rockchip.c | 58 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/spi/spi-rockchip.c +29 -29
@@ -104,8 +104,8 @@#define CR0_XFM_RO 0x2#define CR0_OPM_OFFSET 20 -#define CR0_OPM_MASTER 0x0 -#define CR0_OPM_SLAVE 0x1 +#define CR0_OPM_HOST 0x0 +#define CR0_OPM_TARGET 0x1#define CR0_SOI_OFFSET 23
@@ -125,7 +125,7 @@#define SR_TF_EMPTY (1 << 2)#define SR_RF_EMPTY (1 << 3)#define SR_RF_FULL (1 << 4) -#define SR_SLAVE_TX_BUSY (1 << 5) +#define SR_TARGET_TX_BUSY (1 << 5)/* Bit fields in ISR, IMR, ISR, RISR, 5bit */ #define INT_MASK 0x1f
@@ -151,7 +151,7 @@#define RXDMA (1 << 0)#define TXDMA (1 << 1) -/* sclk_out: spi master internal logic in rk3x can support 50Mhz */ +/* sclk_out: spi host internal logic in rk3x can support 50Mhz */ #define MAX_SCLK_OUT 50000000U/*
@@ -194,8 +194,8 @@ struct rockchip_spi {bool cs_asserted[ROCKCHIP_SPI_MAX_CS_NUM ]; -bool slave_abort; -bool cs_inactive;/* spi slave tansmition stop when cs inactive */ +bool target_abort; +bool cs_inactive;/* spi target tansmition stop when cs inactive */ bool cs_high_supported;/* native CS supports active-high polarity */ struct spi_transfer *xfer;/* Store xfer temporarily */
@@ -206,13 +206,13 @@ static inline void spi_enable_chip(struct rockchip_spi *rs, bool enable)writel_relaxed ((enable ?1U :0U ), rs->regs +ROCKCHIP_SPI_SSIENR ); } -static inline void wait_for_tx_idle (struct rockchip_spi *rs,bool slave_mode) +static inline void wait_for_tx_idle (struct rockchip_spi *rs,bool target_mode) {unsigned long timeout = jiffies +msecs_to_jiffies (5 ); do { - if (slave_mode) { - if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_SLAVE_TX_BUSY) && + if (target_mode) { + if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_TARGET_TX_BUSY) && !((readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))) return; } else {
@@ -349,9 +349,9 @@ static irqreturn_t rockchip_spi_isr(int irq, void *dev_id)struct spi_controller *ctlr = dev_id;struct rockchip_spi *rs =spi_controller_get_devdata (ctlr); -/* When int_cs_inactive comes, spi slave abort */ +/* When int_cs_inactive comes, spi target abort */ if (rs->cs_inactive &&readl_relaxed (rs->regs +ROCKCHIP_SPI_IMR ) &INT_CS_INACTIVE ) { - ctlr->slave_abort (ctlr); + ctlr->target_abort (ctlr);writel_relaxed (0 , rs->regs +ROCKCHIP_SPI_IMR );writel_relaxed (0xffffffff , rs->regs +ROCKCHIP_SPI_ICR );
@@ -403,7 +403,7 @@ static void rockchip_spi_dma_rxcb(void *data)struct rockchip_spi *rs =spi_controller_get_devdata (ctlr);int state =atomic_fetch_andnot (RXDMA , &rs->state); -if (state &TXDMA && !rs->slave_abort) +if (state &TXDMA && !rs->target_abort)return ;if (rs->cs_inactive)
@@ -419,11 +419,11 @@ static void rockchip_spi_dma_txcb(void *data)struct rockchip_spi *rs =spi_controller_get_devdata (ctlr);int state =atomic_fetch_andnot (TXDMA , &rs->state); -if (state &RXDMA && !rs->slave_abort) +if (state &RXDMA && !rs->target_abort)return ;/* Wait until the FIFO data completely. */ -wait_for_tx_idle (rs, ctlr->slave); +wait_for_tx_idle (rs, ctlr->target);spi_enable_chip (rs, false);spi_finalize_current_transfer (ctlr);
@@ -523,7 +523,7 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs,static int rockchip_spi_config (struct rockchip_spi *rs,struct spi_device *spi,struct spi_transfer *xfer, -bool use_dma,bool slave_mode) +bool use_dma,bool target_mode) {u32 cr0 =CR0_FRF_SPI <<CR0_FRF_OFFSET |CR0_BHT_8BIT <<CR0_BHT_OFFSET
@@ -532,9 +532,9 @@ static int rockchip_spi_config(struct rockchip_spi *rs,u32 cr1;u32 dmacr =0 ; -if (slave_mode) - cr0 |=CR0_OPM_SLAVE <<CR0_OPM_OFFSET ; - rs->slave_abort = false; +if (target_mode) + cr0 |=CR0_OPM_TARGET <<CR0_OPM_OFFSET ; + rs->target_abort = false; cr0 |= rs->rsd <<CR0_RSD_OFFSET ; cr0 |= (spi->mode &0x3U ) <<CR0_SCPH_OFFSET ;
@@ -612,7 +612,7 @@ static size_t rockchip_spi_max_transfer_size(struct spi_device *spi)return ROCKCHIP_SPI_MAX_TRANLEN ; } -static int rockchip_spi_slave_abort (struct spi_controller *ctlr) +static int rockchip_spi_target_abort (struct spi_controller *ctlr) {struct rockchip_spi *rs =spi_controller_get_devdata (ctlr);u32 rx_fifo_left;
@@ -657,7 +657,7 @@ static int rockchip_spi_slave_abort(struct spi_controller *ctlr)dmaengine_terminate_sync (ctlr->dma_tx);atomic_set (&rs->state,0 );spi_enable_chip (rs, false); - rs->slave_abort = true; + rs->target_abort = true;spi_finalize_current_transfer (ctlr);return 0 ;
@@ -695,7 +695,7 @@ static int rockchip_spi_transfer_one( rs->xfer = xfer; use_dma = ctlr->can_dma ? ctlr->can_dma (ctlr, spi, xfer) : false; - ret =rockchip_spi_config (rs, spi, xfer, use_dma, ctlr->slave); + ret =rockchip_spi_config (rs, spi, xfer, use_dma, ctlr->target);if (ret)return ret;
@@ -755,15 +755,15 @@ static int rockchip_spi_probe(struct platform_device *pdev)struct resource *mem;struct device_node *np = pdev->dev.of_node;u32 rsd_nsecs, num_cs; -bool slave_mode; +bool target_mode; - slave_mode =of_property_read_bool (np,"spi-slave" ); + target_mode =of_property_read_bool (np,"spi-slave" ); -if (slave_mode) - ctlr =spi_alloc_slave (&pdev->dev, +if (target_mode) + ctlr =spi_alloc_target (&pdev->dev,sizeof (struct rockchip_spi ));else - ctlr =spi_alloc_master (&pdev->dev, + ctlr =spi_alloc_host (&pdev->dev,sizeof (struct rockchip_spi ));if (!ctlr)
@@ -853,9 +853,9 @@ static int rockchip_spi_probe(struct platform_device *pdev) ctlr->auto_runtime_pm = true; ctlr->bus_num = pdev->id; ctlr->mode_bits =SPI_CPOL |SPI_CPHA |SPI_LOOP |SPI_LSB_FIRST ; -if (slave_mode) { +if (target_mode) { ctlr->mode_bits |=SPI_NO_CS ; - ctlr->slave_abort = rockchip_spi_slave_abort; + ctlr->target_abort = rockchip_spi_target_abort; }else { ctlr->flags =SPI_MASTER_GPIO_SS ; ctlr->max_native_cs =ROCKCHIP_SPI_MAX_CS_NUM ;
@@ -910,7 +910,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)case ROCKCHIP_SPI_VER2_TYPE2 : rs->cs_high_supported = true; ctlr->mode_bits |=SPI_CS_HIGH ; -if (ctlr->can_dma && slave_mode) +if (ctlr->can_dma && target_mode) rs->cs_inactive = true;else rs->cs_inactive = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 743/969 spi: rockchip: Read ISR, not IMR, to detect cs-inactive IRQ
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Madieu <[email protected]>
[ Upstream commit b4683a239a409d65f88052f5630c748a8ba070cd ]
rockchip_spi_isr() decides whether the current interrupt was the cs-inactive event by reading IMR:
if (rs->cs_inactive && readl_relaxed(rs->regs + ROCKCHIP_SPI_IMR) & INT_CS_INACTIVE) ctlr->target_abort(ctlr);
IMR is the interrupt mask register: it tells which sources are enabled, not which one fired. In the PIO path, rockchip_spi_prepare_irq() enables both INT_RF_FULL and INT_CS_INACTIVE in IMR when rs->cs_inactive is true:
if (rs->cs_inactive) writel_relaxed(INT_RF_FULL | INT_CS_INACTIVE, rs->regs + ROCKCHIP_SPI_IMR);
so the IMR check is always true once cs_inactive is enabled, and every PIO interrupt - including normal RF_FULL completions - is dispatched to ctlr->target_abort(), aborting the transfer. The bug is reachable on ROCKCHIP_SPI_VER2_TYPE2 in target mode with a DMA-capable controller when the transfer is short enough to fall back to PIO (rockchip_spi_can_dma() returns false below fifo_len).
Read ISR (which is RISR masked by IMR) so the check actually reflects which interrupt fired, and parenthesise the expression for clarity while at it.
--- drivers/spi/spi-rockchip.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-rockchip.c +2 -1
@@ -350,7 +350,8 @@ static irqreturn_t rockchip_spi_isr(int irq, void *dev_id)struct rockchip_spi *rs =spi_controller_get_devdata (ctlr);/* When int_cs_inactive comes, spi target abort */ -if (rs->cs_inactive &&readl_relaxed (rs->regs +ROCKCHIP_SPI_IMR ) &INT_CS_INACTIVE ) { +if (rs->cs_inactive && + (readl_relaxed (rs->regs +ROCKCHIP_SPI_ISR ) &INT_CS_INACTIVE )) { ctlr->target_abort (ctlr);writel_relaxed (0 , rs->regs +ROCKCHIP_SPI_IMR );writel_relaxed (0xffffffff , rs->regs +ROCKCHIP_SPI_ICR );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 744/969 cdrom, scsi: sr: propagate read-only status to block layer via set_disk_ro()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daan De Meyer <[email protected]>
[ Upstream commit 0898a817621a2f0cddca8122d9b974003fe5036d ]
The cdrom core never calls set_disk_ro() for a registered device, so BLKROGET on a CD-ROM device always returns 0 (writable), even when the drive has no write capabilities and writes will inevitably fail. This causes problems for userspace that relies on BLKROGET to determine whether a block device is read-only. For example, systemd's loop device setup uses BLKROGET to decide whether to create a loop device with LO_FLAGS_READ_ONLY. Without the read-only flag, writes pass through the loop device to the CD-ROM and fail with I/O errors. systemd-fsck similarly checks BLKROGET to decide whether to run fsck in no-repair mode (-n).
The write-capability bits in cdi->mask come from two different sources:CDC_DVD_RAM and CDC_CD_RW are populated by the driver from the MODE SENSE capabilities page (page 0x2A) before register_cdrom() is called, while CDC_MRW_W and CDC_RAM require the MMC GET CONFIGURATION command and were only probed by cdrom_open_write() at device open time. This meant that any attempt to compute the writable state from the full mask at probe time was incorrect, because the GET CONFIGURATION bits were still unset (and cdi->mask is initialized such that capabilities are assumed present).
Fix this by factoring the GET CONFIGURATION probing out of cdrom_open_write() into a new exported helper, cdrom_probe_write_features(), and having sr call it from sr_probe() right after get_capabilities() has populated the MODE SENSE bits. register_cdrom() then calls set_disk_ro() based on the full write-capability mask (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW) so the block layer reflects the drive's actual write support. The feature queries used (CDF_MRW and CDF_RWRT via GET CONFIGURATION with RT=00) report drive-level capabilities that are persistent across media, so a single probe before register_cdrom() is sufficient and the redundant probe at open time is dropped.
With set_disk_ro() now accurate, the long-vestigial cd->writeable flag in sr can go: get_capabilities() used to set cd->writeable based on the same four mask bits, but because CDC_MRW_W and CDC_RAM default to "capability present" in cdi->mask and aren't touched by MODE SENSE, the condition that gated cd->writeable was always true, making it unconditionally 1. Replace the corresponding gate in sr_init_command() with get_disk_ro(cd->disk), which turns a previously no-op check into a real one and also catches kernel-internal bio writers that bypass blkdev_write_iter()'s bdev_read_only() check.
The sd driver (SCSI disks) does not have this problem because it checks the MODE SENSE Write Protect bit and calls set_disk_ro() accordingly. The sr driver cannot use the same approach because the MMC specification does not define the WP bit in the MODE SENSE device-specific parameter byte for CD-ROM devices.
--- drivers/cdrom/cdrom.c | 73 ++++++++++++++++++++++++++++--------------- drivers/scsi/sr.c | 11 ++----- drivers/scsi/sr.h | 1 - include/linux/cdrom.h | 1 + 4 files changed, 51 insertions(+), 35 deletions(-)
drivers/cdrom/cdrom.c +48 -25
@@ -633,6 +633,16 @@ int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi)WARN_ON (!cdo->generic_packet); +/* +* Propagate the drive's write support to the block layer so BLKROGET +* reflects actual write capability. Drivers that use GET CONFIGURATION +* features (CDC_MRW_W, CDC_RAM) must have called +* cdrom_probe_write_features() before register_cdrom() so the mask is +* complete here. +*/ +set_disk_ro (disk, !CDROM_CAN (CDC_DVD_RAM |CDC_MRW_W |CDC_RAM | +CDC_CD_RW )); +cd_dbg (CD_REG_UNREG ,"drive \"/dev/%s\" registered\n" , cdi->name);mutex_lock (&cdrom_mutex);list_add (&cdi->list, &cdrom_list);
@@ -747,6 +757,44 @@ static int cdrom_is_random_writable(struct cdrom_device_info *cdi, int *write)return 0 ; } +/* +* Probe write-related MMC features via GET CONFIGURATION and update +* cdi->mask accordingly. Drivers that populate cdi->mask from the MODE SENSE +* capabilities page (e.g. sr) should call this after those MODE SENSE bits +* have been set but before register_cdrom(), so that the full set of +* write-capability bits is known by the time register_cdrom() decides on the +* initial read-only state of the disk. +*/ +void cdrom_probe_write_features (struct cdrom_device_info *cdi) +{ +int mrw, mrw_write, ram_write; + + mrw =0 ; +if (!cdrom_is_mrw (cdi, &mrw_write)) + mrw =1 ; + +if (CDROM_CAN (CDC_MO_DRIVE )) + ram_write =1 ; +else + (void )cdrom_is_random_writable (cdi, &ram_write); + +if (mrw) + cdi->mask &= ~CDC_MRW ; +else + cdi->mask |=CDC_MRW ; + +if (mrw_write) + cdi->mask &= ~CDC_MRW_W ; +else + cdi->mask |=CDC_MRW_W ; + +if (ram_write) + cdi->mask &= ~CDC_RAM ; +else + cdi->mask |=CDC_RAM ; +} +EXPORT_SYMBOL (cdrom_probe_write_features); +static int cdrom_media_erasable (struct cdrom_device_info *cdi) {disc_information di;
@@ -899,33 +947,8 @@ static int cdrom_is_dvd_rw(struct cdrom_device_info *cdi)*/ static int cdrom_open_write (struct cdrom_device_info *cdi) { -int mrw, mrw_write, ram_write;int ret =1 ; - mrw =0 ; -if (!cdrom_is_mrw (cdi, &mrw_write)) - mrw =1 ; - -if (CDROM_CAN (CDC_MO_DRIVE )) - ram_write =1 ; -else - (void )cdrom_is_random_writable (cdi, &ram_write); - -if (mrw) - cdi->mask &= ~CDC_MRW ; -else - cdi->mask |=CDC_MRW ; - -if (mrw_write) - cdi->mask &= ~CDC_MRW_W ; -else - cdi->mask |=CDC_MRW_W ; - -if (ram_write) - cdi->mask &= ~CDC_RAM ; -else - cdi->mask |=CDC_RAM ; -if (CDROM_CAN (CDC_MRW_W )) ret =cdrom_mrw_open_write (cdi);else if (CDROM_CAN (CDC_DVD_RAM ))
drivers/scsi/sr.c +2 -9
@@ -392,7 +392,7 @@ static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt)switch (req_op (rq)) {case REQ_OP_WRITE : -if (!cd->writeable) +if (get_disk_ro (cd->disk)) goto out; SCpnt->cmnd[0 ] =WRITE_10 ; cd->cdi.media_written =1 ;
@@ -672,6 +672,7 @@ static int sr_probe(struct device *dev) error = -ENOMEM ;if (get_capabilities (cd)) goto fail_minor; +cdrom_probe_write_features (&cd->cdi);sr_vendor_init (cd);set_capacity (disk, cd->capacity);
@@ -890,14 +891,6 @@ static int get_capabilities(struct scsi_cd *cd)/*else I don't think it can close its tray cd->cdi.mask |= CDC_CLOSE_TRAY; */ -/* -* if DVD-RAM, MRW-W or CD-RW, we are randomly writable -*/ -if ((cd->cdi.mask & (CDC_DVD_RAM |CDC_MRW_W |CDC_RAM |CDC_CD_RW )) != - (CDC_DVD_RAM |CDC_MRW_W |CDC_RAM |CDC_CD_RW )) { - cd->writeable =1 ; - } -kfree (buffer);return 0 ; }
drivers/scsi/sr.h +0 -1
@@ -35,7 +35,6 @@ typedef struct scsi_cd {struct scsi_device *device;unsigned int vendor;/* vendor code, see sr_vendor.c */ unsigned long ms_offset;/* for reading multisession-CD's */ - unsigned writeable : 1; unsigned use:1; /* is this device still supportable */ unsigned xa_flag:1; /* CD has XA sectors ? */ unsigned readcd_known:1; /* drive supports READ_CD (0xbe) */
include/linux/cdrom.h +1 -0
@@ -109,6 +109,7 @@ extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,extern unsigned int cdrom_check_events (struct cdrom_device_info *cdi,unsigned int clearing); +extern void cdrom_probe_write_features (struct cdrom_device_info *cdi);extern int register_cdrom (struct gendisk *disk,struct cdrom_device_info *cdi);extern void unregister_cdrom (struct cdrom_device_info *cdi);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 745/969 netdevsim: zero initialize struct iphdr in dummy sk_buff
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikola Z. Ivanov <[email protected]>
[ Upstream commit 35eaa6d8d6c2ee65e96f507add856e0eacf24591 ]
Syzbot reports a KMSAN uninit-value originating from nsim_dev_trap_skb_build, with the allocation also being performed in the same function.
Fix this by calling skb_put_zero instead of skb_put to guarantee zero initialization of the whole IP header.
--- drivers/net/netdevsim/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/netdevsim/dev.c +1 -1
@@ -758,7 +758,7 @@ static struct sk_buff *nsim_dev_trap_skb_build(void) skb->protocol =htons (ETH_P_IP );skb_set_network_header (skb, skb->len); - iph =skb_put (skb,sizeof (struct iphdr )); + iph =skb_put_zero (skb,sizeof (struct iphdr )); iph->protocol =IPPROTO_UDP ; iph->saddr =in_aton ("192.0.2.1" ); iph->daddr =in_aton ("198.51.100.1" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 746/969 net/sched: netem: fix probability gaps in 4-state loss model
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephen Hemminger <[email protected]>
[ Upstream commit 732b463449fd0ef90acd13cda68eab1c91adb00c ]
The 4-state Markov chain in loss_4state() has gaps at the boundaries between transition probability ranges. The comparisons use:
if (rnd < a4) else if (a4 < rnd && rnd < a1 + a4)
When rnd equals a boundary value exactly, neither branch matches and no state transition occurs. The redundant lower-bound check (a4 < rnd) is already implied by being in the else branch.
Remove the unnecessary lower-bound comparisons so the ranges are contiguous and every random value produces a transition, matching the GI (General and Intuitive) loss model specification.
This bug goes back to original implementation of this model.
--- net/sched/sch_netem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/sched/sch_netem.c +4 -4
@@ -219,10 +219,10 @@ static bool loss_4state(struct netem_sched_data *q)if (rnd < clg->a4) { clg->state =LOST_IN_GAP_PERIOD ;return true; - }else if (clg->a4 < rnd && rnd < clg->a1 + clg->a4) { + }else if (rnd < clg->a1 + clg->a4) { clg->state =LOST_IN_BURST_PERIOD ;return true; - }else if (clg->a1 + clg->a4 < rnd) { + }else { clg->state =TX_IN_GAP_PERIOD ; }
@@ -239,9 +239,9 @@ static bool loss_4state(struct netem_sched_data *q)case LOST_IN_BURST_PERIOD :if (rnd < clg->a3) clg->state =TX_IN_BURST_PERIOD ; -else if (clg->a3 < rnd && rnd < clg->a2 + clg->a3) { +else if (rnd < clg->a2 + clg->a3) { clg->state =TX_IN_GAP_PERIOD ; - }else if (clg->a2 + clg->a3 < rnd) { + }else { clg->state =LOST_IN_BURST_PERIOD ;return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 747/969 net/sched: netem: fix queue limit check to include reordered packets
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephen Hemminger <[email protected]>
[ Upstream commit 4185701fcce6b426b6c3630b25330dddd9c47b0d ]
The queue limit check in netem_enqueue() uses q->t_len which only counts packets in the internal tfifo. Packets placed in sch->q by the reorder path (__qdisc_enqueue_head) are not counted, allowing the total queue occupancy to exceed sch->limit under reordering.
Include sch->q.qlen in the limit check.
--- net/sched/sch_netem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_netem.c +1 -1
@@ -512,7 +512,7 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,1 <<prandom_u32_max (8 ); } -if (unlikely (q->t_len >= sch->limit)) { +if (unlikely (sch->q.qlen >= sch->limit)) {/* re-link segs, so that qdisc_drop_all() frees them all */ skb->next = segs;qdisc_drop_all (skb, sch, to_free);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 748/969 net/sched: netem: validate slot configuration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephen Hemminger <[email protected]>
[ Upstream commit 01801c359a74737b9b1aa28568b60374d857241a ]
Reject slot configurations that have no defensible meaning:
- negative min_delay or max_delay
- min_delay greater than max_delay
- negative dist_delay or dist_jitter
- negative max_packets or max_bytes
Negative or out-of-order delays underflow in get_slot_next(), producing garbage intervals. Negative limits trip the per-slot accounting (packets_left/bytes_left <= 0) on the first packet of every slot, defeating the rate-limiting half of the slot feature.
Note that dist_jitter has been silently coerced to its absolute value by get_slot() since the feature was introduced; rejecting negatives here converts that silent coercion into -EINVAL. The abs() can be removed in a follow-up.
--- net/sched/sch_netem.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
net/sched/sch_netem.c +29 -0
@@ -815,6 +815,29 @@ static int get_dist_table(struct disttable **tbl, const struct nlattr *attr)return 0 ; } +static int validate_slot (const struct nlattr *attr,struct netlink_ext_ack *extack) +{ +const struct tc_netem_slot *c =nla_data (attr); + +if (c->min_delay <0 || c->max_delay <0 ) { +NL_SET_ERR_MSG_ATTR (extack, attr,"negative slot delay" ); +return -EINVAL ; + } +if (c->min_delay > c->max_delay) { +NL_SET_ERR_MSG_ATTR (extack, attr,"slot min delay greater than max delay" ); +return -EINVAL ; + } +if (c->dist_delay <0 || c->dist_jitter <0 ) { +NL_SET_ERR_MSG_ATTR (extack, attr,"negative dist delay" ); +return -EINVAL ; + } +if (c->max_packets <0 || c->max_bytes <0 ) { +NL_SET_ERR_MSG_ATTR (extack, attr,"negative slot limit" ); +return -EINVAL ; + } +return 0 ; +} +static void get_slot (struct netem_sched_data *q,const struct nlattr *attr) {const struct tc_netem_slot *c =nla_data (attr);
@@ -1027,6 +1050,12 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt, goto table_free; } +if (tb[TCA_NETEM_SLOT ]) { + ret =validate_slot (tb[TCA_NETEM_SLOT ], extack); +if (ret) + goto table_free; + } +sch_tree_lock (sch);/* backup q->clg and q->loss_model */ old_clg = q->clg;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 749/969 net/sched: netem: fix slot delay calculation overflow
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephen Hemminger <[email protected]>
[ Upstream commit 51e94e1e2fef351c74d69eb53666df808d26af95 ]
get_slot_next() computes a random delay between min_delay and max_delay using:
get_random_u32() * (max_delay - min_delay) >> 32
This overflows signed 64-bit arithmetic when the delay range exceeds approximately 2.1 seconds (2^31 nanoseconds), producing a negative result that effectively disables slot-based pacing. This is a realistic configuration for WAN emulation (e.g., slot 1s 5s).
Use mul_u64_u32_shr() which handles the widening multiply without overflow.
--- net/sched/sch_netem.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/sched/sch_netem.c +2 -3
@@ -647,9 +647,8 @@ static void get_slot_next(struct netem_sched_data *q, u64 now)if (!q->slot_dist) next_delay = q->slot_config.min_delay + - (get_random_u32 () * - (q->slot_config.max_delay - - q->slot_config.min_delay) >>32 ); +mul_u64_u32_shr (q->slot_config.max_delay - q->slot_config.min_delay, +get_random_u32 (),32 );else next_delay = tabledist(q->slot_config.dist_delay, (s32)(q->slot_config.dist_jitter),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 750/969 net/sched: sch_choke: annotate data-races in choke_dump_stats()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit d3aeb889dcbd78e95f500d383799a23d949796e0 ]
choke_dump_stats() only runs with RTNL held. It reads fields that can be changed in qdisc fast path. Add READ_ONCE()/WRITE_ONCE() annotations.
--- net/sched/sch_choke.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
net/sched/sch_choke.c +16 -10
@@ -229,7 +229,7 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch,/* Draw a packet at random from queue and compare flow */ if (choke_match_random (q, skb, &idx)) { - q->stats.matched++; +WRITE_ONCE (q->stats.matched, q->stats.matched +1 );choke_drop_by_idx (sch, idx, to_free); goto congestion_drop; }
@@ -241,11 +241,13 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch,qdisc_qstats_overlimit (sch);if (use_harddrop (q) || !use_ecn (q) || !INET_ECN_set_ce (skb)) { - q->stats.forced_drop++; +WRITE_ONCE (q->stats.forced_drop, + q->stats.forced_drop +1 ); goto congestion_drop; } - q->stats.forced_mark++; +WRITE_ONCE (q->stats.forced_mark, + q->stats.forced_mark +1 ); }else if (++q->vars.qcount) {if (red_mark_probability (p, &q->vars, q->vars.qavg)) { q->vars.qcount =0 ;
@@ -253,11 +255,13 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch,qdisc_qstats_overlimit (sch);if (!use_ecn (q) || !INET_ECN_set_ce (skb)) { - q->stats.prob_drop++; +WRITE_ONCE (q->stats.prob_drop, + q->stats.prob_drop +1 ); goto congestion_drop; } - q->stats.prob_mark++; +WRITE_ONCE (q->stats.prob_mark, + q->stats.prob_mark +1 ); } }else q->vars.qR =red_random (p);
@@ -272,7 +276,7 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch,return NET_XMIT_SUCCESS ; } - q->stats.pdrop++; +WRITE_ONCE (q->stats.pdrop, q->stats.pdrop +1 );return qdisc_drop (skb, sch, to_free); congestion_drop:
@@ -460,10 +464,12 @@ static int choke_dump_stats(struct Qdisc *sch, struct gnet_dump *d) {struct choke_sched_data *q =qdisc_priv (sch);struct tc_choke_xstats st = { - .early = q->stats.prob_drop + q->stats.forced_drop, - .marked = q->stats.prob_mark + q->stats.forced_mark, - .pdrop = q->stats.pdrop, - .matched = q->stats.matched, + .early =READ_ONCE (q->stats.prob_drop) + +READ_ONCE (q->stats.forced_drop), + .marked =READ_ONCE (q->stats.prob_mark) + +READ_ONCE (q->stats.forced_mark), + .pdrop =READ_ONCE (q->stats.pdrop), + .matched =READ_ONCE (q->stats.matched), };return gnet_stats_copy_app (d, &st,sizeof (st));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 751/969 net/sched: sch_fq_pie: annotate data-races in fq_pie_dump_stats()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 59b145771c7982cfe9020d4e9e22da92d6b5ae31 ]
fq_codel_dump_stats() acquires the qdisc spinlock a bit too late.
Move this acquisition before we fill tc_fq_pie_xstats with live data.
Alternative would be to add READ_ONCE() and WRITE_ONCE() annotations, but the spinlock is needed anyway to scan q->new_flows and q->old_flows.
--- net/sched/sch_fq_pie.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
net/sched/sch_fq_pie.c +10 -9
@@ -498,18 +498,19 @@ static int fq_pie_dump(struct Qdisc *sch, struct sk_buff *skb)static int fq_pie_dump_stats (struct Qdisc *sch,struct gnet_dump *d) {struct fq_pie_sched_data *q =qdisc_priv (sch); -struct tc_fq_pie_xstats st = { - .packets_in = q->stats.packets_in, - .overlimit = q->stats.overlimit, - .overmemory = q->overmemory, - .dropped = q->stats.dropped, - .ecn_mark = q->stats.ecn_mark, - .new_flow_count = q->new_flow_count, - .memory_usage = q->memory_usage, - }; +struct tc_fq_pie_xstats st = {0 };struct list_head *pos;sch_tree_lock (sch); + + st.packets_in = q->stats.packets_in; + st.overlimit = q->stats.overlimit; + st.overmemory = q->overmemory; + st.dropped = q->stats.dropped; + st.ecn_mark = q->stats.ecn_mark; + st.new_flow_count = q->new_flow_count; + st.memory_usage = q->memory_usage; +list_for_each (pos, &q->new_flows) st.new_flows_len++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 752/969 vrf: Fix a potential NPD when removing a port from a VRF
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit 2674d603a9e6970463b2b9ebcf8e31e90beae169 ]
RCU readers that identified a net device as a VRF port using netif_is_l3_slave() assume that a subsequent call to netdev_master_upper_dev_get_rcu() will return a VRF device. They then continue to dereference its l3mdev operations.
This assumption is not always correct and can result in a NPD [1]. There is no RCU synchronization when removing a port from a VRF, so it is possible for an RCU reader to see a new master device (e.g., a bridge) that does not have l3mdev operations.
Fix by adding RCU synchronization after clearing the IFF_L3MDEV_SLAVE flag. Skip this synchronization when a net device is removed from a VRF as part of its deletion and when the VRF device itself is deleted. In the latter case an RCU grace period will pass by the time RTNL is released.
[1]
BUG: kernel NULL pointer dereference, address: 0000000000000000 [...] RIP: 0010:l3mdev_fib_table_rcu (net/l3mdev/l3mdev.c:181) [...] Call Trace: <TASK> l3mdev_fib_table_by_index (net/l3mdev/l3mdev.c:201 net/l3mdev/l3mdev.c:189) __inet_bind (net/ipv4/af_inet.c:499 (discriminator 3)) inet_bind_sk (net/ipv4/af_inet.c:469) __sys_bind (./include/linux/file.h:62 (discriminator 1) ./include/linux/file.h:83 (discriminator 1) net/socket.c:1951 (discriminator 1)) __x64_sys_bind (net/socket.c:1969 (discriminator 1) net/socket.c:1967 (discriminator 1) net/socket.c:1967 (discriminator 1)) do_syscall_64 (arch/x86/entry/syscall_64.c:63 (discriminator 1) arch/x86/entry/syscall_64.c:94 (discriminator 1))
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
--- drivers/net/vrf.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/vrf.c +11 -4
@@ -1126,6 +1126,7 @@ static int do_vrf_add_slave(struct net_device *dev, struct net_device *port_dev, err: port_dev->priv_flags &= ~IFF_L3MDEV_SLAVE ; +synchronize_net ();return ret; }
@@ -1145,10 +1146,16 @@ static int vrf_add_slave(struct net_device *dev, struct net_device *port_dev, }/* inverse of do_vrf_add_slave */ -static int do_vrf_del_slave (struct net_device *dev,struct net_device *port_dev) +static int do_vrf_del_slave (struct net_device *dev,struct net_device *port_dev, +bool needs_sync) {netdev_upper_dev_unlink (port_dev, dev); port_dev->priv_flags &= ~IFF_L3MDEV_SLAVE ; +/* Make sure that concurrent RCU readers that identified the device +* as a VRF port see a VRF master or no master at all. +*/ +if (needs_sync) +synchronize_net ();cycle_netdev (port_dev,NULL );
@@ -1157,7 +1164,7 @@ static int do_vrf_del_slave(struct net_device *dev, struct net_device *port_dev)static int vrf_del_slave (struct net_device *dev,struct net_device *port_dev) { -return do_vrf_del_slave (dev, port_dev); +return do_vrf_del_slave (dev, port_dev, true); }static void vrf_dev_uninit (struct net_device *dev)
@@ -1722,7 +1729,7 @@ static void vrf_dellink(struct net_device *dev, struct list_head *head)struct list_head *iter;netdev_for_each_lower_dev (dev, port_dev, iter) -vrf_del_slave (dev, port_dev); +do_vrf_del_slave (dev, port_dev, false);vrf_map_unregister_dev (dev);
@@ -1853,7 +1860,7 @@ static int vrf_device_event(struct notifier_block *unused, goto out; vrf_dev =netdev_master_upper_dev_get (dev); -vrf_del_slave (vrf_dev, dev); +do_vrf_del_slave (vrf_dev, dev, false); } out:return NOTIFY_DONE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 753/969 net: usb: rtl8150: fix use-after-free in rtl8150_start_xmit()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Jun <[email protected]>
[ Upstream commit 23f0e34c64acba15cad4d23e50f41f533da195fa ]
syzbot reported a KASAN slab-use-after-free read in rtl8150_start_xmit() when accessing skb->len for tx statistics after usb_submit_urb() has been called:
BUG: KASAN: slab-use-after-free in rtl8150_start_xmit+0x71f/0x760
drivers/net/usb/rtl8150.c:712
Read of size 4 at addr ffff88810eb7a930 by task kworker/0:4/5226The URB completion handler write_bulk_callback() frees the skb via dev_kfree_skb_irq(dev->tx_skb). The URB may complete on another CPU in softirq context before usb_submit_urb() returns in the submitter, so by the time the submitter reads skb->len the skb has already been queued to the per-CPU completion_queue and freed by net_tx_action():
CPU A (xmit) CPU B (USB completion softirq)
------------ ------------------------------
dev->tx_skb = skb;
usb_submit_urb() --+
|-------> write_bulk_callback()
| dev_kfree_skb_irq(dev->tx_skb)
| net_tx_action()
| napi_skb_cache_put() <-- free
netdev->stats.tx_bytes |
+= skb->len; <-- UAF readFix it by caching skb->len before submitting the URB and using the cached value when updating the tx_bytes counter.
The pre-existing tx_bytes semantics are preserved: the counter tracks the original frame length (skb->len), not the ETH_ZLEN/USB-alignment padded "count" value that is handed to the device. Changing that would be a user-visible accounting change and is out of scope for this UAF fix.
--- drivers/net/usb/rtl8150.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/usb/rtl8150.c +4 -1
@@ -685,6 +685,7 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev) {rtl8150_t *dev =netdev_priv (netdev); +unsigned int skb_len;int count, res;/* pad the frame and ensure terminating USB packet, datasheet 9.2.3 */
@@ -696,6 +697,8 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,return NETDEV_TX_OK ; } + skb_len = skb->len; +netif_stop_queue (netdev); dev->tx_skb = skb; usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
@@ -711,7 +714,7 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb, } }else { netdev->stats.tx_packets++; - netdev->stats.tx_bytes += skb->len; + netdev->stats.tx_bytes += skb_len;netif_trans_update (netdev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 754/969 net: usb: rtl8150: free skb on usb_submit_urb() failure in xmit
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Morduan Zang <[email protected]>
[ Upstream commit adbe2cdf75461891e50dbe11896ac78e9af1f874 ]
When rtl8150_start_xmit() fails to submit the tx URB, the URB is never handed to the USB core and write_bulk_callback() will not run. The driver returns NETDEV_TX_OK, which tells the networking stack that the skb has been consumed, but nothing actually frees the skb on this error path:
dev->tx_skb = skb;
...
if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
...
/* no kfree_skb here */
}
return NETDEV_TX_OK;This leaks the skb on every submit failure and also leaves dev->tx_skb pointing at memory that the driver itself may later free, which is fragile.
Free the skb with dev_kfree_skb_any() in the error path and clear dev->tx_skb so no stale pointer is left behind.
--- drivers/net/usb/rtl8150.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/usb/rtl8150.c +7 -0
@@ -712,6 +712,13 @@ static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb, netdev->stats.tx_errors++;netif_start_queue (netdev); } +/* +* The URB was not submitted, so write_bulk_callback() will +* never run to free dev->tx_skb. Drop the skb here and +* clear tx_skb to avoid leaving a stale pointer. +*/ + dev->tx_skb =NULL ; +dev_kfree_skb_any (skb); }else { netdev->stats.tx_packets++; netdev->stats.tx_bytes += skb_len;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 755/969 NFC: trf7970a: Ignore antenna noise when checking for RF field
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Geurts <[email protected]>
[ Upstream commit a9bc28aa4e64320668131349436a650bf42591a5 ]
The main channel Received Signal Strength Indicator (RSSI) measurement is used to determine whether an RF field is present or not. RSSI != 0 is interpreted as an RF Field is present. This does not take RF noise and measurement inaccuracy into account, and results in false positives in the field.
Define a noise level and make sure the RF field is only interpreted as present when the RSSI is above the noise level.
--- drivers/nfc/trf7970a.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nfc/trf7970a.c +2 -1
@@ -311,6 +311,7 @@#define TRF7970A_RSSI_OSC_STATUS_RSSI_MASK (BIT(2) | BIT(1) | BIT(0))#define TRF7970A_RSSI_OSC_STATUS_RSSI_X_MASK (BIT(5) | BIT(4) | BIT(3))#define TRF7970A_RSSI_OSC_STATUS_RSSI_OSC_OK BIT(6) +#define TRF7970A_RSSI_OSC_STATUS_RSSI_NOISE_LEVEL 1#define TRF7970A_SPECIAL_FCN_REG1_COL_7_6 BIT(0)#define TRF7970A_SPECIAL_FCN_REG1_14_ANTICOLL BIT(1)
@@ -1253,7 +1254,7 @@ static int trf7970a_is_rf_field(struct trf7970a *trf, bool *is_rf_field)if (ret)return ret; -if (rssi &TRF7970A_RSSI_OSC_STATUS_RSSI_MASK ) +if ((rssi &TRF7970A_RSSI_OSC_STATUS_RSSI_MASK ) >TRF7970A_RSSI_OSC_STATUS_RSSI_NOISE_LEVEL ) *is_rf_field = true;else *is_rf_field = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 756/969 neighbour: add RCU protection to neigh_tables[]
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit f8f2eb9de69a1119117d198547c13d7a1123a5a9 ]
In order to remove RTNL protection from neightbl_dump_info() and neigh_dump_info() later, we need to add
RCU protection to neigh_tables[].
Stable-dep-of: 4438113be604 ("neigh: let neigh_xmit take skb ownership")
--- net/core/neighbour.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
net/core/neighbour.c +19 -11
@@ -1764,7 +1764,7 @@ static void neigh_parms_destroy(struct neigh_parms *parms)static struct lock_class_key neigh_table_proxy_queue_class; -static struct neigh_table *neigh_tables[NEIGH_NR_TABLES ]__read_mostly ; +static struct neigh_table __rcu *neigh_tables[NEIGH_NR_TABLES ]__read_mostly ;void neigh_table_init (int index,struct neigh_table *tbl) {
@@ -1821,13 +1821,19 @@ void neigh_table_init(int index, struct neigh_table *tbl) tbl->last_flush = now; tbl->last_rand = now + tbl->parms.reachable_time *20 ; - neigh_tables[index] = tbl; +rcu_assign_pointer (neigh_tables[index], tbl); }EXPORT_SYMBOL (neigh_table_init); +/* +* Only called from ndisc_cleanup(), which means this is dead code +* because we no longer can unload IPv6 module. +*/ int neigh_table_clear (int index,struct neigh_table *tbl) { - neigh_tables[index] =NULL ; +RCU_INIT_POINTER (neigh_tables[index],NULL ); +synchronize_rcu (); +/* It is not clean... Fix it to unload IPv6 module safely */ cancel_delayed_work_sync (&tbl->managed_work);cancel_delayed_work_sync (&tbl->gc_work);
@@ -1859,10 +1865,10 @@ static struct neigh_table *neigh_find_table(int family)switch (family) {case AF_INET : - tbl = neigh_tables[NEIGH_ARP_TABLE ]; + tbl =rcu_dereference_rtnl (neigh_tables[NEIGH_ARP_TABLE ]);break ;case AF_INET6 : - tbl = neigh_tables[NEIGH_ND_TABLE ]; + tbl =rcu_dereference_rtnl (neigh_tables[NEIGH_ND_TABLE ]);break ; }
@@ -2328,7 +2334,7 @@ static int neightbl_set(struct sk_buff *skb, struct nlmsghdr *nlh, ndtmsg =nlmsg_data (nlh);for (tidx =0 ; tidx <NEIGH_NR_TABLES ; tidx++) { - tbl = neigh_tables[tidx]; + tbl =rcu_dereference_rtnl (neigh_tables[tidx]);if (!tbl)continue ;if (ndtmsg->ndtm_family && tbl->family != ndtmsg->ndtm_family)
@@ -2516,7 +2522,7 @@ static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb)for (tidx =0 ; tidx <NEIGH_NR_TABLES ; tidx++) {struct neigh_parms *p; - tbl = neigh_tables[tidx]; + tbl =rcu_dereference_rtnl (neigh_tables[tidx]);if (!tbl)continue ;
@@ -2877,7 +2883,7 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb) s_t = cb->args[0 ];for (t =0 ; t <NEIGH_NR_TABLES ; t++) { - tbl = neigh_tables[t]; + tbl =rcu_dereference_rtnl (neigh_tables[t]);if (!tbl)continue ;
@@ -3141,14 +3147,15 @@ int neigh_xmit(int index, struct net_device *dev, const void *addr, struct sk_buff *skb) { int err = -EAFNOSUPPORT; +if (likely (index <NEIGH_NR_TABLES )) {struct neigh_table *tbl;struct neighbour *neigh; - tbl = neigh_tables[index]; -if (!tbl) - goto out;rcu_read_lock (); + tbl =rcu_dereference (neigh_tables[index]); +if (!tbl) + goto out_unlock;if (index ==NEIGH_ARP_TABLE ) {u32 key = *((u32 *)addr);
@@ -3164,6 +3171,7 @@ int neigh_xmit(int index, struct net_device *dev, goto out_kfree_skb; } err =READ_ONCE (neigh->output)(neigh, skb); +out_unlock:rcu_read_unlock (); }else if (index ==NEIGH_LINK_TABLE ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 757/969 neigh: let neigh_xmit take skb ownership
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 4438113be604ee67a7bf4f81da6e1cca41332ce4 ]
neigh_xmit always releases the skb, except when no neighbour table is found. But even the first added user of neigh_xmit (mpls) relied on neigh_xmit to release the skb (or queue it for tx).
sashiko reported:
If neigh_xmit() is called with an uninitialized neighbor table (for example, NEIGH_ND_TABLE when IPv6 is disabled), it returns -EAFNOSUPPORT and bypasses its internal out_kfree_skb error path. Because the return value of neigh_xmit() is ignored here, does this leak the SKB?
Assume full ownership and remove the last code path that doesn't xmit or free skb.
--- net/core/neighbour.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/core/neighbour.c +5 -5
@@ -3154,8 +3154,10 @@ int neigh_xmit(int index, struct net_device *dev,rcu_read_lock (); tbl =rcu_dereference (neigh_tables[index]); -if (!tbl) - goto out_unlock; +if (!tbl) { +rcu_read_unlock (); + goto out_kfree_skb; + }if (index ==NEIGH_ARP_TABLE ) {u32 key = *((u32 *)addr);
@@ -3171,7 +3173,6 @@ int neigh_xmit(int index, struct net_device *dev, goto out_kfree_skb; } err =READ_ONCE (neigh->output)(neigh, skb); -out_unlock:rcu_read_unlock (); }else if (index ==NEIGH_LINK_TABLE ) {
@@ -3181,11 +3182,10 @@ int neigh_xmit(int index, struct net_device *dev, goto out_kfree_skb; err =dev_queue_xmit (skb); } -out:return err; out_kfree_skb:kfree_skb (skb); - goto out; +return err; }EXPORT_SYMBOL (neigh_xmit);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 758/969 ALSA: usb-audio: Fix potential leak of pd at parsing UAC3 streams
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit c39f0bc03f84ba64c9144c95714df1dc36150f6d ]
At parsing UAC3 streams, we allocate a PD object at each time, and either assign or free it. But there is a case where the PD object may be leaked; namely, in __snd_usb_parse_audio_interface() loop, when an audioformat shares the same endpoint with others, it's put to a link and returns from snd_usb_add_audio_stream(), but the PD is forgotten afterwards. Overall, the treatment of PD object in the parser code is a bit flaky, and we should be more careful about the object ownership.
This patch tries to fix the above case and improve the code a bit. The pd object is now managed with the auto-cleanup in the loop, and the ownership is updated when the pd object gets assigned to the stream, which guarantees the release of the leftover object.
--- sound/usb/quirks.c | 2 +- sound/usb/stream.c | 58 ++++++++++++++++++---------------------------- sound/usb/stream.h | 3 ++- 3 files changed, 25 insertions(+), 38 deletions(-)
sound/usb/quirks.c +1 -1
@@ -121,7 +121,7 @@ static int add_audio_stream_from_fixed_fmt(struct snd_usb_audio *chip,snd_usb_audioformat_set_sync_ep (chip, fp); - err =snd_usb_add_audio_stream (chip, stream, fp); + err =snd_usb_add_audio_stream (chip, stream, fp,NULL );if (err <0 )return err;
sound/usb/stream.c +22 -36
129 lines not on this page · raw message
sound/usb/stream.h +2 -1
@@ -7,7 +7,8 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip,int snd_usb_add_audio_stream (struct snd_usb_audio *chip,int stream, -struct audioformat *fp); +struct audioformat *fp, +struct snd_usb_power_domain **pdptr);#endif /* __USBAUDIO_STREAM_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 759/969 net: mctp i2c: check length before marking flow active
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: William A. Kennington III <[email protected]>
[ Upstream commit 4ca07b9239bd0478ae586632a2ed72be37ed8407 ]
Currently, mctp_i2c_get_tx_flow_state() is called before the packet length sanity check. This function marks a new flow as active in the MCTP core.
If the sanity check fails, mctp_i2c_xmit() returns early without calling mctp_i2c_lock_nest(). This results in a mismatched locking state: the flow is active, but the I2C bus lock was never acquired for it.
When the flow is later released, mctp_i2c_release_flow() will see the active state and queue an unlock marker. The TX thread will then decrement midev->i2c_lock_count from 0, causing it to underflow to -1.
This underflow permanently breaks the driver's locking logic, allowing future transmissions to occur without holding the I2C bus lock, leading to bus collisions and potential hardware hangs.
Move the mctp_i2c_get_tx_flow_state() call to after the length sanity check to ensure we only transition the flow state if we are actually going to proceed with the transmission and locking.
--- drivers/net/mctp/mctp-i2c.c | 4 ++-- net/sched/cls_flower.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/mctp/mctp-i2c.c +2 -2
@@ -461,8 +461,6 @@ static void mctp_i2c_xmit(struct mctp_i2c_dev *midev, struct sk_buff *skb)u8 *pecp;int rc; - fs =mctp_i2c_get_tx_flow_state (midev, skb); - hdr = (void *)skb_mac_header (skb);/* Sanity check that packet contents matches skb length, * and can't exceed MCTP_I2C_BUFSZ
@@ -474,6 +472,8 @@ static void mctp_i2c_xmit(struct mctp_i2c_dev *midev, struct sk_buff *skb)return ; } + fs =mctp_i2c_get_tx_flow_state (midev, skb); +if (skb_tailroom (skb) >=1 ) {/* Linear case with space, we can just append the PEC */ skb_put (skb,1 );
net/sched/cls_flower.c +3 -1
@@ -537,6 +537,7 @@ static int __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f, struct netlink_ext_ack *extack) {struct cls_fl_head *head =fl_head_dereference (tp); +struct fl_flow_mask *mask; *last = false;
@@ -553,11 +554,12 @@ static int __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f,list_del_rcu (&f->list);spin_unlock (&tp->lock); - *last =fl_mask_put (head, f->mask); + mask = f->mask;if (!tc_skip_hw (f->flags))fl_hw_destroy_filter (tp, f, rtnl_held, extack);tcf_unbind_filter (tp, &f->res);__fl_put (f); + *last =fl_mask_put (head, mask);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 760/969 net: phy: dp83869: fix setting CLK_O_SEL field.
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Heiko Schocher <[email protected]>
[ Upstream commit 46f74a3f7d57d9cc0110b09cbc8163fa0a01afa2 ]
Table 7-121 in datasheet says we have to set register 0xc6 to value 0x10 before CLK_O_SEL can be modified. No more infos about this field found in datasheet. With this fix, setting of CLK_O_SEL field in IO_MUX_CFG register worked through dts property "ti,clk-output-sel" on a DP83869HMRGZR.
--- drivers/net/phy/dp83869.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/phy/dp83869.c +12 -1
@@ -31,6 +31,7 @@#define DP83869_RGMIICTL 0x0032#define DP83869_STRAP_STS1 0x006e#define DP83869_RGMIIDCTL 0x0086 +#define DP83869_ANA_PLL_PROG_PI 0x00c6#define DP83869_RXFCFG 0x0134#define DP83869_RXFPMD1 0x0136#define DP83869_RXFPMD2 0x0137
@@ -802,12 +803,22 @@ static int dp83869_config_init(struct phy_device *phydev)dp83869_config_port_mirroring (phydev);/* Clock output selection if muxing property is set */ -if (dp83869->clk_output_sel !=DP83869_CLK_O_SEL_REF_CLK ) +if (dp83869->clk_output_sel !=DP83869_CLK_O_SEL_REF_CLK ) { +/* +* Table 7-121 in datasheet says we have to set register 0xc6 +* to value 0x10 before CLK_O_SEL can be modified. +*/ + ret =phy_write_mmd (phydev,DP83869_DEVADDR , +DP83869_ANA_PLL_PROG_PI ,0x10 ); +if (ret) +return ret; + ret =phy_modify_mmd (phydev,DP83869_DEVADDR ,DP83869_IO_MUX_CFG ,DP83869_IO_MUX_CFG_CLK_O_SEL_MASK , dp83869->clk_output_sel <<DP83869_IO_MUX_CFG_CLK_O_SEL_SHIFT ); + }if (phy_interface_is_rgmii (phydev)) { ret = phy_write_mmd(phydev, DP83869_DEVADDR, DP83869_RGMIIDCTL,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 761/969 ASoC: codecs: ab8500: Fix casting of private data
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian A. Ehrhardt <[email protected]>
[ Upstream commit a201aef1a88b675e9eb8487e27d14e2eef3cef80 ]
ab8500_filter_controls[i].private_value is initialized using
.private_value = (unsigned long)&(struct filter_control)
{.count = xcount, .min = xmin, .max = xmax}thus it's a pointer to a struct filter_control casted to unsigned long.
So to get back that pointer .private_data must be cast back, not its address.
--- sound/soc/codecs/ab8500-codec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/codecs/ab8500-codec.c +3 -3
@@ -2496,13 +2496,13 @@ static int ab8500_codec_probe(struct snd_soc_component *component)return status; } fc = (struct filter_control *) - &ab8500_filter_controls[AB8500_FILTER_ANC_FIR ].private_value; + ab8500_filter_controls[AB8500_FILTER_ANC_FIR ].private_value; drvdata->anc_fir_values = (long *)fc->value; fc = (struct filter_control *) - &ab8500_filter_controls[AB8500_FILTER_ANC_IIR ].private_value; + ab8500_filter_controls[AB8500_FILTER_ANC_IIR ].private_value; drvdata->anc_iir_values = (long *)fc->value; fc = (struct filter_control *) - &ab8500_filter_controls[AB8500_FILTER_SID_FIR ].private_value; + ab8500_filter_controls[AB8500_FILTER_SID_FIR ].private_value; drvdata->sid_fir_values = (long *)fc->value;snd_soc_dapm_disable_pin (dapm,"ANC Configure Input" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 762/969 netfilter: skip recording stale or retransmitted INIT
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
[ Upstream commit 576a5d2bad4814c881a829576b1261b9b8159d2b ]
An INIT whose init_tag matches the peer's vtag does not provide new state information. It indicates either:
- a stale INIT (after INIT-ACK has already been seen on the same side), or
- a retransmitted INIT (after INIT has already been recorded on the same side).
In both cases, the INIT must not update ct->proto.sctp.init[] state, since it does not advance the handshake tracking and may otherwise corrupt INIT/INIT-ACK validation logic.
Allow INIT processing only when the conntrack entry is newly created (SCTP_CONNTRACK_NONE), or when the init_tag differs from the stored peer vtag.
Note it skips the check for the ct with old_state SCTP_CONNTRACK_NONE in nf_conntrack_sctp_packet(), as it is just created in sctp_new() where it set ct->proto.sctp.vtag[IP_CT_DIR_REPLY] = ih->init_tag.
--- net/netfilter/nf_conntrack_proto_sctp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/netfilter/nf_conntrack_proto_sctp.c +7 -3
@@ -484,9 +484,13 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,if (!ih) goto out_unlock; -if (ct->proto.sctp.init[dir] && ct->proto.sctp.init[!dir]) - ct->proto.sctp.init[!dir] =0 ; - ct->proto.sctp.init[dir] =1 ; +/* Do not record INIT matching peer vtag (stale or retransmitted INIT). */ +if (old_state ==SCTP_CONNTRACK_NONE || + ct->proto.sctp.vtag[!dir] != ih->init_tag) { +if (ct->proto.sctp.init[dir] && ct->proto.sctp.init[!dir]) + ct->proto.sctp.init[!dir] =0 ; + ct->proto.sctp.init[dir] =1 ; + }pr_debug ("Setting vtag %x for dir %d\n" , ih->init_tag, !dir); ct->proto.sctp.vtag[!dir] = ih->init_tag;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 763/969 sctp: discard stale INIT after handshake completion
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
[ Upstream commit 8a92cb475ca90d84db769e4d4383e631ace0d6e5 ]
After an association reaches ESTABLISHED, the peer’s init_tag is already known from the handshake. Any subsequent INIT with the same init_tag is not a valid restart, but a delayed or duplicate INIT.
Drop such INIT chunks in sctp_sf_do_unexpected_init() instead of processing them as new association attempts.
--- net/sctp/sm_statefuns.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/sctp/sm_statefuns.c +6 -0
@@ -1556,6 +1556,12 @@ static enum sctp_disposition sctp_sf_do_unexpected_init(/* Tag the variable length parameters. */ chunk->param_hdr.v =skb_pull (chunk->skb,sizeof (struct sctp_inithdr )); +if (asoc->state >=SCTP_STATE_ESTABLISHED ) { +/* Discard INIT matching peer vtag after handshake completion (stale INIT). */ +if (ntohl (chunk->subh.init_hdr->init_tag) == asoc->peer.i.init_tag) +return sctp_sf_pdiscard (net, ep, asoc, type, arg, commands); + } +/* Verify the INIT chunk before processing it. */ err_chunk =NULL ; if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 764/969 ipv4: rename and move ip_route_output_tunnel()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Beniamino Galvani <[email protected]>
[ Upstream commit bf3fcbf7e7a08015d3b169bad6281b29d45c272d ]
At the moment ip_route_output_tunnel() is used only by bareudp. Ideally, other UDP tunnel implementations should use it, but to do so the function needs to accept new parameters that are specific for UDP tunnels, such as the ports.
Prepare for these changes by renaming the function to udp_tunnel_dst_lookup() and move it to file net/ipv4/udp_tunnel_core.c.
Stable-dep-of: aa6c6d9ee064 ("bareudp: fix NULL pointer dereference in bareudp_fill_metadata_dst()")
--- drivers/net/bareudp.c | 8 +++---- include/net/route.h | 6 ----- include/net/udp_tunnel.h | 6 +++++ net/ipv4/route.c | 48 -------------------------------------- net/ipv4/udp_tunnel_core.c | 48 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 58 deletions(-)
drivers/net/bareudp.c +4 -4
@@ -325,8 +325,8 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,if (!sock)return -ESHUTDOWN ; - rt =ip_route_output_tunnel (skb, dev, bareudp->net, &saddr, info, -IPPROTO_UDP , use_cache); + rt =udp_tunnel_dst_lookup (skb, dev, bareudp->net, &saddr, info, +IPPROTO_UDP , use_cache);if (IS_ERR (rt))return PTR_ERR (rt);
@@ -505,8 +505,8 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,struct rtable *rt;__be32 saddr; - rt =ip_route_output_tunnel (skb, dev, bareudp->net, &saddr, - info,IPPROTO_UDP , use_cache); + rt =udp_tunnel_dst_lookup (skb, dev, bareudp->net, &saddr, + info,IPPROTO_UDP , use_cache);if (IS_ERR (rt))return PTR_ERR (rt);
include/net/route.h +0 -6
@@ -139,12 +139,6 @@ static inline struct rtable *__ip_route_output_key(struct net *net,struct rtable *ip_route_output_flow (struct net *,struct flowi4 *flp,const struct sock *sk); -struct rtable *ip_route_output_tunnel (struct sk_buff *skb, -struct net_device *dev, -struct net *net,__be32 *saddr, -const struct ip_tunnel_info *info, -u8 protocol,bool use_cache); -struct dst_entry *ipv4_blackhole_route (struct net *net,struct dst_entry *dst_orig);
include/net/udp_tunnel.h +6 -0
@@ -161,6 +161,12 @@ int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,void udp_tunnel_sock_release (struct socket *sock); +struct rtable *udp_tunnel_dst_lookup (struct sk_buff *skb, +struct net_device *dev, +struct net *net,__be32 *saddr, +const struct ip_tunnel_info *info, +u8 protocol,bool use_cache); +struct metadata_dst *udp_tun_rx_dst (struct sk_buff *skb,unsigned short family,__be16 flags,__be64 tunnel_id,int md_size);
net/ipv4/route.c +0 -48
54 lines not on this page · raw message
net/ipv4/udp_tunnel_core.c +48 -0
52 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 765/969 ipv4: remove "proto" argument from udp_tunnel_dst_lookup()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Beniamino Galvani <[email protected]>
[ Upstream commit 78f3655adcb52412275f282267ee771421731632 ]
The function is now UDP-specific, the protocol is always IPPROTO_UDP.
Stable-dep-of: aa6c6d9ee064 ("bareudp: fix NULL pointer dereference in bareudp_fill_metadata_dst()")
--- drivers/net/bareudp.c | 4 ++-- include/net/udp_tunnel.h | 2 +- net/ipv4/udp_tunnel_core.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/bareudp.c +2 -2
@@ -326,7 +326,7 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,return -ESHUTDOWN ; rt =udp_tunnel_dst_lookup (skb, dev, bareudp->net, &saddr, info, -IPPROTO_UDP , use_cache); + use_cache);if (IS_ERR (rt))return PTR_ERR (rt);
@@ -506,7 +506,7 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,__be32 saddr; rt =udp_tunnel_dst_lookup (skb, dev, bareudp->net, &saddr, - info,IPPROTO_UDP , use_cache); + info, use_cache);if (IS_ERR (rt))return PTR_ERR (rt);
include/net/udp_tunnel.h +1 -1
@@ -165,7 +165,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,struct net_device *dev, struct net *net, __be32 *saddr, const struct ip_tunnel_info *info, - u8 protocol, bool use_cache); + bool use_cache); struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, __be16 flags, __be64 tunnel_id,
net/ipv4/udp_tunnel_core.c +2 -2
@@ -208,7 +208,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,struct net_device *dev, struct net *net, __be32 *saddr, const struct ip_tunnel_info *info, - u8 protocol, bool use_cache) + bool use_cache) { #ifdef CONFIG_DST_CACHE struct dst_cache *dst_cache;
@@ -227,7 +227,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,#endif memset (&fl4,0 ,sizeof (fl4)); fl4.flowi4_mark = skb->mark; - fl4.flowi4_proto = protocol; + fl4.flowi4_proto =IPPROTO_UDP ; fl4.daddr = info->key.u.ipv4.dst; fl4.saddr = info->key.u.ipv4.src; tos = info->key.tos;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 766/969 ipv4: add new arguments to udp_tunnel_dst_lookup()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Beniamino Galvani <[email protected]>
[ Upstream commit 72fc68c6356b663a8763f02d9b0ec773d59a4949 ]
We want to make the function more generic so that it can be used by other UDP tunnel implementations such as geneve and vxlan. To do that, add the following arguments:
- source and destination UDP port;
- ifindex of the output interface, needed by vxlan;
- the tos, because in some cases it is not taken from struct ip_tunnel_info (for example, when it's inherited from the inner packet);
- the dst cache, because not all tunnel types (e.g. vxlan) want to use the one from struct ip_tunnel_info.
With these parameters, the function no longer needs the full struct ip_tunnel_info as argument and we can pass only the relevant part of it (struct ip_tunnel_key).
Stable-dep-of: aa6c6d9ee064 ("bareudp: fix NULL pointer dereference in bareudp_fill_metadata_dst()")
--- drivers/net/bareudp.c | 11 +++++++---- include/net/udp_tunnel.h | 8 +++++--- net/ipv4/udp_tunnel_core.c | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 20 deletions(-)
drivers/net/bareudp.c +7 -4
@@ -325,8 +325,10 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,if (!sock)return -ESHUTDOWN ; - rt =udp_tunnel_dst_lookup (skb, dev, bareudp->net, &saddr, info, - use_cache); + rt =udp_tunnel_dst_lookup (skb, dev, bareudp->net,0 , &saddr, &info->key, +0 ,0 , key->tos, + use_cache ? + (struct dst_cache *)&info->dst_cache :NULL );if (IS_ERR (rt))return PTR_ERR (rt);
@@ -505,8 +507,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,struct rtable *rt;__be32 saddr; - rt =udp_tunnel_dst_lookup (skb, dev, bareudp->net, &saddr, - info, use_cache); + rt =udp_tunnel_dst_lookup (skb, dev, bareudp->net,0 , &saddr, + &info->key,0 ,0 , info->key.tos, + use_cache ? &info->dst_cache :NULL );if (IS_ERR (rt))return PTR_ERR (rt);
include/net/udp_tunnel.h +5 -3
@@ -163,9 +163,11 @@ void udp_tunnel_sock_release(struct socket *sock);struct rtable *udp_tunnel_dst_lookup (struct sk_buff *skb,struct net_device *dev, -struct net *net,__be32 *saddr, -const struct ip_tunnel_info *info, -bool use_cache); +struct net *net,int oif, +__be32 *saddr, +const struct ip_tunnel_key *key, +__be16 sport,__be16 dport,u8 tos, +struct dst_cache *dst_cache); struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, __be16 flags, __be64 tunnel_id,
net/ipv4/udp_tunnel_core.c +13 -13
@@ -206,31 +206,31 @@ EXPORT_SYMBOL_GPL(udp_tun_rx_dst);struct rtable *udp_tunnel_dst_lookup (struct sk_buff *skb,struct net_device *dev, -struct net *net,__be32 *saddr, -const struct ip_tunnel_info *info, -bool use_cache) +struct net *net,int oif, +__be32 *saddr, +const struct ip_tunnel_key *key, +__be16 sport,__be16 dport,u8 tos, +struct dst_cache *dst_cache) { -#ifdef CONFIG_DST_CACHE -struct dst_cache *dst_cache; -#endif struct rtable *rt =NULL ;struct flowi4 fl4; -__u8 tos;#ifdef CONFIG_DST_CACHE - dst_cache = (struct dst_cache *)&info->dst_cache; -if (use_cache) { +if (dst_cache) { rt =dst_cache_get_ip4 (dst_cache, saddr);if (rt)return rt; }#endif +memset (&fl4,0 ,sizeof (fl4)); fl4.flowi4_mark = skb->mark; fl4.flowi4_proto =IPPROTO_UDP ; - fl4.daddr = info->key.u.ipv4.dst; - fl4.saddr = info->key.u.ipv4.src; - tos = info->key.tos; + fl4.flowi4_oif = oif; + fl4.daddr = key->u.ipv4.dst; + fl4.saddr = key->u.ipv4.src; + fl4.fl4_dport = dport; + fl4.fl4_sport = sport; fl4.flowi4_tos =RT_TOS (tos); rt =ip_route_output_key (net, &fl4);
@@ -244,7 +244,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,return ERR_PTR (-ELOOP ); }#ifdef CONFIG_DST_CACHE -if (use_cache) +if (dst_cache)dst_cache_set_ip4 (dst_cache, &rt->dst, fl4.saddr);#endif *saddr = fl4.saddr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 767/969 ipv6: rename and move ip6_dst_lookup_tunnel()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Beniamino Galvani <[email protected]>
[ Upstream commit fc47e86dbfb75a864c0c9dd8e78affb6506296bb ]
At the moment ip6_dst_lookup_tunnel() is used only by bareudp. Ideally, other UDP tunnel implementations should use it, but to do so the function needs to accept new parameters that are specific for UDP tunnels, such as the ports.
Prepare for these changes by renaming the function to udp_tunnel6_dst_lookup() and move it to file net/ipv6/ip6_udp_tunnel.c.
This is similar to what already done for IPv4 in commit bf3fcbf7e7a0 ("ipv4: rename and move ip_route_output_tunnel()").
Stable-dep-of: aa6c6d9ee064 ("bareudp: fix NULL pointer dereference in bareudp_fill_metadata_dst()")
--- drivers/net/bareudp.c | 10 +++--- include/net/ipv6.h | 6 ---- include/net/udp_tunnel.h | 7 ++++ net/ipv6/ip6_output.c | 68 -------------------------------------- net/ipv6/ip6_udp_tunnel.c | 69 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 79 deletions(-)
drivers/net/bareudp.c +5 -5
@@ -393,8 +393,8 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,if (!sock)return -ESHUTDOWN ; - dst =ip6_dst_lookup_tunnel (skb, dev, bareudp->net, sock, &saddr, info, -IPPROTO_UDP , use_cache); + dst =udp_tunnel6_dst_lookup (skb, dev, bareudp->net, sock, &saddr, info, +IPPROTO_UDP , use_cache);if (IS_ERR (dst))return PTR_ERR (dst);
@@ -520,9 +520,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,struct in6_addr saddr;struct socket *sock =rcu_dereference (bareudp->sock); - dst =ip6_dst_lookup_tunnel (skb, dev, bareudp->net, sock, - &saddr, info,IPPROTO_UDP , - use_cache); + dst =udp_tunnel6_dst_lookup (skb, dev, bareudp->net, sock, + &saddr, info,IPPROTO_UDP , + use_cache);if (IS_ERR (dst))return PTR_ERR (dst);
include/net/ipv6.h +0 -6
@@ -1098,12 +1098,6 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, ststruct dst_entry *ip6_sk_dst_lookup_flow (struct sock *sk,struct flowi6 *fl6,const struct in6_addr *final_dst,bool connected); -struct dst_entry *ip6_dst_lookup_tunnel (struct sk_buff *skb, -struct net_device *dev, -struct net *net,struct socket *sock, -struct in6_addr *saddr, -const struct ip_tunnel_info *info, -u8 protocol,bool use_cache);struct dst_entry *ip6_blackhole_route (struct net *net,struct dst_entry *orig_dst);
include/net/udp_tunnel.h +7 -0
@@ -168,6 +168,13 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,const struct ip_tunnel_key *key, __be16 sport, __be16 dport, u8 tos, struct dst_cache *dst_cache); +struct dst_entry *udp_tunnel6_dst_lookup (struct sk_buff *skb, +struct net_device *dev, +struct net *net, +struct socket *sock, +struct in6_addr *saddr, +const struct ip_tunnel_info *info, +u8 protocol,bool use_cache); struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, __be16 flags, __be64 tunnel_id,
net/ipv6/ip6_output.c +0 -68
74 lines not on this page · raw message
net/ipv6/ip6_udp_tunnel.c +69 -0
76 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 768/969 bareudp: fix NULL pointer dereference in bareudp_fill_metadata_dst()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit aa6c6d9ee064aabfede4402fd1283424e649ca19 ]
bareudp_fill_metadata_dst() passes bareudp->sock to udp_tunnel6_dst_lookup() in the IPv6 path without a NULL check. The socket is only created in bareudp_open() and NULLed in bareudp_stop(), so calling this function while the device is down triggers a NULL dereference via sock->sk.
BUG: kernel NULL pointer dereference, address: 0000000000000018 RIP: 0010:udp_tunnel6_dst_lookup (net/ipv6/ip6_udp_tunnel.c:160) Call Trace: <TASK> bareudp_fill_metadata_dst (drivers/net/bareudp.c:532) do_execute_actions (net/openvswitch/actions.c:901) ovs_execute_actions (net/openvswitch/actions.c:1589) ovs_packet_cmd_execute (net/openvswitch/datapath.c:700) genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114) genl_rcv_msg (net/netlink/genetlink.c:1209) netlink_rcv_skb (net/netlink/af_netlink.c:2550) </TASK>
Add a NULL check returning -ESHUTDOWN, consistent with the xmit paths in the same driver.
--- drivers/net/bareudp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/bareudp.c +3 -0
@@ -520,6 +520,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,struct in6_addr saddr;struct socket *sock =rcu_dereference (bareudp->sock); +if (!sock) +return -ESHUTDOWN ; + dst =udp_tunnel6_dst_lookup (skb, dev, bareudp->net, sock, &saddr, info,IPPROTO_UDP , use_cache);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 769/969 net/sched: sch_cake: annotate data-races in cake_dump_stats() (V)
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit a6c95b833dc17e84d16a8ac0f40fd0931616a52d ]
cake_dump_stats() runs without qdisc spinlock being held.
In this final patch, I add READ_ONCE()/WRITE_ONCE() annotations for cparams.target and cparams.interval.
--- net/sched/sch_cake.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
net/sched/sch_cake.c +7 -6
@@ -2313,10 +2313,11 @@ static void cake_set_rate(struct cake_tin_data *b, u64 rate, u32 mtu, byte_target_ns = (byte_target * rate_ns) >> rate_shft; - b->cparams.target =max ((byte_target_ns *3 ) /2 , target_ns); - b->cparams.interval =max (rtt_est_ns + - b->cparams.target - target_ns, - b->cparams.target *2 ); +WRITE_ONCE (b->cparams.target, +max ((byte_target_ns *3 ) /2 , target_ns)); +WRITE_ONCE (b->cparams.interval, +max (rtt_est_ns + b->cparams.target - target_ns, + b->cparams.target *2 )); b->cparams.mtu_time = byte_target_ns; b->cparams.p_inc =1 <<24 ;/* 1/256 */ b->cparams.p_dec =1 <<20 ;/* 1/4096 */
@@ -2930,9 +2931,9 @@ static int cake_dump_stats(struct Qdisc *sch, struct gnet_dump *d)PUT_TSTAT_U32 (BACKLOG_BYTES , b->tin_backlog);PUT_TSTAT_U32 (TARGET_US , -ktime_to_us (ns_to_ktime (b->cparams.target))); +ktime_to_us (ns_to_ktime (READ_ONCE (b->cparams.target))));PUT_TSTAT_U32 (INTERVAL_US , -ktime_to_us (ns_to_ktime (b->cparams.interval))); +ktime_to_us (ns_to_ktime (READ_ONCE (b->cparams.interval))));PUT_TSTAT_U32 (SENT_PACKETS , b->packets);PUT_TSTAT_U32 (DROPPED_PACKETS , b->tin_dropped);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 770/969 net: netconsole: move newline trimming to function
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Wood <[email protected]>
[ Upstream commit ae001dc67907618423fd15bbab2014308c00ad0b ]
Move newline trimming logic from dev_name_store() to a new function (trim_newline()) for shared use in netconsole.c
Stable-dep-of: 92ceb7bff62c ("netconsole: propagate device name truncation in dev_name_store()")
--- drivers/net/netconsole.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/net/netconsole.c +11 -6
@@ -240,6 +240,16 @@ static struct netconsole_target *to_target(struct config_item *item)NULL ; } +/* Get rid of possible trailing newline, returning the new length */ +static void trim_newline (char *s,size_t maxlen) +{ +size_t len; + + len =strnlen (s, maxlen); +if (s[len -1 ] =='\n' ) + s[len -1 ] ='\0' ; +} +/* * Attribute operations for netconsole_target. */
@@ -404,7 +414,6 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf, size_t count) {struct netconsole_target *nt =to_target (item); -size_t len;mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {
@@ -415,11 +424,7 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf, }strscpy (nt->np.dev_name, buf,IFNAMSIZ ); - -/* Get rid of possible trailing newline from echo(1) */ - len =strnlen (nt->np.dev_name,IFNAMSIZ ); -if (nt->np.dev_name[len -1 ] =='\n' ) - nt->np.dev_name[len -1 ] ='\0' ; +trim_newline (nt->np.dev_name,IFNAMSIZ );mutex_unlock (&dynamic_netconsole_mutex);return strnlen (buf, count);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 771/969 netconsole: propagate device name truncation in dev_name_store()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 92ceb7bff62c2606f664c204750eca0b85d44112 ]
dev_name_store() calls strscpy(nt->np.dev_name, buf, IFNAMSIZ) without checking the return value. If userspace writes an interface name longer than IFNAMSIZ - 1, strscpy() silently truncates and returns -E2BIG, but the function ignores it and reports a fully successful write back to userspace.
If a real interface happens to match the truncated name, netconsole will bind to the wrong device on the next enable, sending kernel logs and panic output to an unintended network segment with no indication to userspace that anything was rewritten.
Reject writes whose length cannot fit in nt->np.dev_name up front:
if (count >= IFNAMSIZ) return -ENAMETOOLONG;
This is not a big deal of a problem, but, it is still the correct approach.
--- drivers/net/netconsole.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/netconsole.c +7 -0
@@ -414,6 +414,13 @@ static ssize_t dev_name_store(struct config_item *item, const char *buf, size_t count) {struct netconsole_target *nt =to_target (item); +size_t len = count; + +/* Account for a trailing newline appended by tools like echo */ +if (len && buf[len -1 ] =='\n' ) + len--; +if (len >=IFNAMSIZ ) +return -ENAMETOOLONG ;mutex_lock (&dynamic_netconsole_mutex);if (nt->enabled) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 772/969 ALSA: hda/conexant: fix some typos
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oldherl Oh <[email protected]>
[ Upstream commit 73253f2fd1d0a44708735c842e37163712e3f03b ]
Fix some typos in patch_conexant.c
Stable-dep-of: b0e2333a2311 ("ALSA: hda/conexant: Fix missing error check for jack detection")
--- sound/pci/hda/patch_conexant.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/pci/hda/patch_conexant.c +8 -8
@@ -166,18 +166,18 @@ static void cxt_init_gpio_led(struct hda_codec *codec)static void cx_fixup_headset_recog (struct hda_codec *codec) { -unsigned int mic_persent; +unsigned int mic_present;/* fix some headset type recognize fail issue, such as EDIFIER headset */ -/* set micbiasd output current comparator threshold from 66% to 55%. */ +/* set micbias output current comparator threshold from 66% to 55%. */ snd_hda_codec_write (codec,0x1c ,0 ,0x320 ,0x010 ); -/* set OFF voltage for DFET from -1.2V to -0.8V, set headset micbias registor +/* set OFF voltage for DFET from -1.2V to -0.8V, set headset micbias register * value adjustment trim from 2.2K ohms to 2.0K ohms. */ snd_hda_codec_write (codec,0x1c ,0 ,0x3b0 ,0xe10 );/* fix reboot headset type recognize fail issue */ - mic_persent =snd_hda_codec_read (codec,0x19 ,0 ,AC_VERB_GET_PIN_SENSE ,0x0 ); -if (mic_persent &AC_PINSENSE_PRESENCE ) + mic_present =snd_hda_codec_read (codec,0x19 ,0 ,AC_VERB_GET_PIN_SENSE ,0x0 ); +if (mic_present &AC_PINSENSE_PRESENCE )/* enable headset mic VREF */ snd_hda_codec_write (codec,0x19 ,0 ,AC_VERB_SET_PIN_WIDGET_CONTROL ,0x24 );else
@@ -247,9 +247,9 @@ static void cx_update_headset_mic_vref(struct hda_codec *codec, struct hda_jack_ {unsigned int mic_present; -/* In cx8070 and sn6140, the node 16 can only be config to headphone or disabled, -* the node 19 can only be config to microphone or disabled. -* Check hp&mic tag to process headset pulgin&plugout. +/* In cx8070 and sn6140, the node 16 can only be configured to headphone or disabled, +* the node 19 can only be configured to microphone or disabled. +* Check hp&mic tag to process headset plugin & plugout. */ mic_present =snd_hda_codec_read (codec,0x19 ,0 ,AC_VERB_GET_PIN_SENSE ,0x0 );if (!(mic_present &AC_PINSENSE_PRESENCE ))/* mic plugout */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 773/969 ALSA: hda/conexant: Renaming the codec with device ID 0x1f86 and 0x1f87
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: wangdicheng <[email protected]>
[ Upstream commit 7f4c540e0859e2025675d2c5c5c6ab88eaf817e2 ]
Due to changes in the manufacturer's plan, all 0x14f11f86 will be named CX11880, and 0x14f11f87 will be named SN6140
Stable-dep-of: b0e2333a2311 ("ALSA: hda/conexant: Fix missing error check for jack detection")
--- sound/pci/hda/patch_conexant.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
sound/pci/hda/patch_conexant.c +6 -6
@@ -42,7 +42,7 @@ struct conexant_spec {unsigned int gpio_led;unsigned int gpio_mute_led_mask;unsigned int gpio_mic_led_mask; -bool is_cx8070_sn6140; +bool is_cx11880_sn6140; };
@@ -195,7 +195,7 @@ static int cx_auto_init(struct hda_codec *codec)cxt_init_gpio_led (codec);snd_hda_apply_fixup (codec,HDA_FIXUP_ACT_INIT ); -if (spec->is_cx8070_sn6140) +if (spec->is_cx11880_sn6140)cx_fixup_headset_recog (codec);return 0 ;
@@ -247,7 +247,7 @@ static void cx_update_headset_mic_vref(struct hda_codec *codec, struct hda_jack_ {unsigned int mic_present; -/* In cx8070 and sn6140, the node 16 can only be configured to headphone or disabled, +/* In cx11880 and sn6140, the node 16 can only be configured to headphone or disabled, * the node 19 can only be configured to microphone or disabled. * Check hp&mic tag to process headset plugin & plugout. */
@@ -1210,11 +1210,11 @@ static int patch_conexant_auto(struct hda_codec *codec) codec->spec = spec; codec->patch_ops = cx_auto_patch_ops; -/* init cx8070/sn6140 flag and reset headset_present_flag */ +/* init cx11880/sn6140 flag and reset headset_present_flag */ switch (codec->core.vendor_id) {case 0x14f11f86 :case 0x14f11f87 : - spec->is_cx8070_sn6140 = true; + spec->is_cx11880_sn6140 = true;snd_hda_jack_detect_enable_callback (codec,0x19 , cx_update_headset_mic_vref);break ; }
@@ -1302,7 +1302,7 @@ static int patch_conexant_auto(struct hda_codec *codec)*/ static const struct hda_device_id snd_hda_id_conexant[] = { -HDA_CODEC_ENTRY (0x14f11f86 ,"CX8070" , patch_conexant_auto), +HDA_CODEC_ENTRY (0x14f11f86 ,"CX11880" , patch_conexant_auto),HDA_CODEC_ENTRY (0x14f11f87 ,"SN6140" , patch_conexant_auto),HDA_CODEC_ENTRY (0x14f12008 ,"CX8200" , patch_conexant_auto),HDA_CODEC_ENTRY (0x14f120d0 ,"CX11970" , patch_conexant_auto),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 774/969 ALSA: hda/conexant: Fix missing error check for jack detection
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: wangdicheng <[email protected]>
[ Upstream commit b0e2333a231107adedd38c6fcfe1adc6162716fc ]
In cx_probe(), the return value of snd_hda_jack_detect_enable_callback() is ignored. This function returns a pointer, and if it fails (e.g., due to memory allocation failure), it returns an error pointer which must be checked using IS_ERR().
If the registration fails, the driver continues to probe, but the jack detection callback will not be registered. This can lead to a kernel crash later when the driver attempts to handle jack events or accesses the uninitialized structure.
Check the return value using IS_ERR() and propagate the error via PTR_ERR() to the probe caller.
--- sound/pci/hda/patch_conexant.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
sound/pci/hda/patch_conexant.c +7 -1
@@ -1199,6 +1199,7 @@ static void add_cx5051_fake_mutes(struct hda_codec *codec)static int patch_conexant_auto (struct hda_codec *codec) {struct conexant_spec *spec; +struct hda_jack_callback *callback;int err;codec_info (codec,"%s: BIOS auto-probing.\n" , codec->core.chip_name);
@@ -1215,7 +1216,12 @@ static int patch_conexant_auto(struct hda_codec *codec)case 0x14f11f86 :case 0x14f11f87 : spec->is_cx11880_sn6140 = true; -snd_hda_jack_detect_enable_callback (codec,0x19 , cx_update_headset_mic_vref); + callback =snd_hda_jack_detect_enable_callback (codec,0x19 , + cx_update_headset_mic_vref); +if (IS_ERR (callback)) { + err =PTR_ERR (callback); + goto error; + }break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 775/969 futex: Prevent lockup in requeue-PI during signal/ timeout wakeup
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit bc7304f3ae20972d11db6e0b1b541c63feda5f05 ]
During wait-requeue-pi (task A) and requeue-PI (task B) the following race can happen:
Task A Task B
futex_wait_requeue_pi()
futex_setup_timer()
futex_do_wait()
futex_requeue()
CLASS(hb, hb1)(&key1);
CLASS(hb, hb2)(&key2);
*timeout*
futex_requeue_pi_wakeup_sync()
requeue_state = Q_REQUEUE_PI_IGNORE
*blocks on hb->lock*
futex_proxy_trylock_atomic()
futex_requeue_pi_prepare()
Q_REQUEUE_PI_IGNORE => -EAGAIN
double_unlock_hb(hb1, hb2)
*retry*Task B acquires both hb locks and attempts to acquire the PI-lock of the top most waiter (task B). Task A is leaving early due to a signal/ timeout and started removing itself from the queue. It updates its requeue_state but can not remove it from the list because this requires the hb lock which is owned by task B.
Usually task A is able to swoop the lock after task B unlocked it. However if task B is of higher priority then task A may not be able to wake up in time and acquire the lock before task B gets it again. Especially on a UP system where A is never scheduled.
As a result task A blocks on the lock and task B busy loops, trying to make progress but live locks the system instead. Tragic.
This can be fixed by removing the top most waiter from the list in this case. This allows task B to grab the next top waiter (if any) in the next iteration and make progress.
Remove the top most waiter if futex_requeue_pi_prepare() fails. Let the waiter conditionally remove itself from the list in handle_early_requeue_pi_wakeup().
--- kernel/futex/requeue.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
kernel/futex/requeue.c +9 -4
@@ -307,8 +307,11 @@ futex_proxy_trylock_atomic(u32 __user *pifutex, struct futex_hash_bucket *hb1,return -EINVAL ;/* Ensure that this does not race against an early wakeup */ -if (!futex_requeue_pi_prepare (top_waiter,NULL )) +if (!futex_requeue_pi_prepare (top_waiter,NULL )) { +plist_del (&top_waiter->list, &hb1->chain); +futex_hb_waiters_dec (hb1);return -EAGAIN ; + }/* * Try to take the lock for top_waiter and set the FUTEX_WAITERS bit
@@ -707,10 +710,12 @@ int handle_early_requeue_pi_wakeup(struct futex_hash_bucket *hb,/* * We were woken prior to requeue by a timeout or a signal. -* Unqueue the futex_q and determine which it was. +* Conditionally unqueue the futex_q and determine which it was. */ -plist_del (&q->list, &hb->chain); -futex_hb_waiters_dec (hb); +if (!plist_node_empty (&q->list)) { +plist_del (&q->list, &hb->chain); +futex_hb_waiters_dec (hb); + }/* Handle spurious wakeups gracefully */ ret = -EWOULDBLOCK ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 776/969 drm/amd/display: Allow DCE link encoder without AUX registers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit ac27e3f99035f132f23bc0409d0e57f11f054c70 ]
Allow constructing the DCE link encoder without DDC, which means the AUX registers array will be NULL.
This is necessary to support embedded connectors without DDC.
--- drivers/gpu/drm/amd/display/dc/dce/dce_link_encoder.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dce/dce_link_encoder.c +3 -1
@@ -992,7 +992,9 @@ void dce110_link_encoder_hw_init(ASSERT (result ==BP_RESULT_OK ); } -aux_initialize (enc110); + +if (enc110->aux_regs) +aux_initialize (enc110);/* reinitialize HPD. * hpd_initialize() will pass DIG_FE id to HW context.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 777/969 drm/amd/display: Read EDID from VBIOS embedded panel info
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
[ Upstream commit 9ea16f64189bf7b6ba50fc7f0325b3c1f836d105 ]
Some board manufacturers hardcode the EDID for the embedded panel in the VBIOS. This EDID should be used when the panel doesn't have a DDC.
For reference, see the legacy non-DC display code:amdgpu_atombios_encoder_get_lcd_info()
This is necessary to support embedded connectors without DDC.
--- .../gpu/drm/amd/display/dc/bios/bios_parser.c | 62 +++++++++++++++++++ .../display/include/grph_object_ctrl_defs.h | 4 ++ 2 files changed, 66 insertions(+)
drivers/gpu/drm/amd/display/dc/bios/bios_parser.c +62 -0
@@ -1215,6 +1215,60 @@ static enum bp_result bios_parser_get_embedded_panel_info(return BP_RESULT_FAILURE ; } +static enum bp_result get_embedded_panel_extra_info ( +struct bios_parser *bp, +struct embedded_panel_info *info, +const uint32_t table_offset) +{ +uint8_t *record =bios_get_image (&bp->base, table_offset,1 ); +ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record; +ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record; + +while (*record !=ATOM_RECORD_END_TYPE ) { +switch (*record) { +case LCD_MODE_PATCH_RECORD_MODE_TYPE : + record +=sizeof (ATOM_PATCH_RECORD_MODE ); +break ; +case LCD_RTS_RECORD_TYPE : + record +=sizeof (ATOM_LCD_RTS_RECORD ); +break ; +case LCD_CAP_RECORD_TYPE : + record +=sizeof (ATOM_LCD_MODE_CONTROL_CAP ); +break ; +case LCD_FAKE_EDID_PATCH_RECORD_TYPE : + fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record; +if (fake_edid_record->ucFakeEDIDLength) { +if (fake_edid_record->ucFakeEDIDLength ==128 ) + info->fake_edid_size = + fake_edid_record->ucFakeEDIDLength; +else + info->fake_edid_size = + fake_edid_record->ucFakeEDIDLength *128 ; + + info->fake_edid = fake_edid_record->ucFakeEDIDString; + + record +=struct_size (fake_edid_record, + ucFakeEDIDString, + info->fake_edid_size); + }else { +/* empty fake edid record must be 3 bytes long */ + record +=sizeof (ATOM_FAKE_EDID_PATCH_RECORD ) +1 ; + } +break ; +case LCD_PANEL_RESOLUTION_RECORD_TYPE : + panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record; + info->panel_width_mm = panel_res_record->usHSize; + info->panel_height_mm = panel_res_record->usVSize; + record +=sizeof (ATOM_PANEL_RESOLUTION_PATCH_RECORD ); +break ; +default : +return BP_RESULT_BADBIOSTABLE ; + } + } + +return BP_RESULT_OK ; +} +static enum bp_result get_embedded_panel_info_v1_2 (struct bios_parser *bp,struct embedded_panel_info *info)
@@ -1331,6 +1385,10 @@ static enum bp_result get_embedded_panel_info_v1_2(if (ATOM_PANEL_MISC_API_ENABLED & lvds->ucLVDS_Misc) info->lcd_timing.misc_info.API_ENABLED = true; +if (lvds->usExtInfoTableOffset) +return get_embedded_panel_extra_info (bp, info, +le16_to_cpu (lvds->usExtInfoTableOffset) +DATA_TABLES (LCD_Info)); +return BP_RESULT_OK ; }
@@ -1456,6 +1514,10 @@ static enum bp_result get_embedded_panel_info_v1_3( (uint32_t ) (ATOM_PANEL_MISC_V13_GREY_LEVEL & lvds->ucLCD_Misc) >>ATOM_PANEL_MISC_V13_GREY_LEVEL_SHIFT ; +if (lvds->usExtInfoTableOffset) +return get_embedded_panel_extra_info (bp, info, +le16_to_cpu (lvds->usExtInfoTableOffset) +DATA_TABLES (LCD_Info)); +return BP_RESULT_OK ; }
drivers/gpu/drm/amd/display/include/grph_object_ctrl_defs.h +4 -0
@@ -153,6 +153,10 @@ struct embedded_panel_info {uint32_t drr_enabled;uint32_t min_drr_refresh_rate;bool realtek_eDPToLVDS; +uint16_t panel_width_mm; +uint16_t panel_height_mm; +uint16_t fake_edid_size; +const uint8_t *fake_edid; };struct dc_firmware_info {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 778/969 bonding: 802.3ad replace MAC_ADDRESS_EQUAL with __agg_has_partner
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jones Syue 薛懷宗 <[email protected]>
[ Upstream commit 4440873f3655325f849366d75382aa05d09b5575 ]
Replace macro MAC_ADDRESS_EQUAL() for null_mac_addr checking with inline function__agg_has_partner(). When MAC_ADDRESS_EQUAL() is verifiying aggregator's partner mac addr with null_mac_addr, means that seeing if aggregator has a valid partner or not. Using __agg_has_partner() makes it more clear to understand.
In ad_port_selection_logic(), since aggregator->partner_system and port->partner_oper.system has been compared first as a prerequisite, it is safe to replace the upcoming MAC_ADDRESS_EQUAL() for null_mac_addr checking with __agg_has_partner().
Delete null_mac_addr, which is not required anymore in bond_3ad.c, since all references to it are gone.
Stable-dep-of: c4f050ce06c5 ("bonding: 3ad: implement proper RCU rules for port->aggregator")
--- drivers/net/bonding/bond_3ad.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/net/bonding/bond_3ad.c +3 -11
@@ -81,10 +81,6 @@ enum ad_link_speed_type {#define MAC_ADDRESS_EQUAL (A ,B ) \ ether_addr_equal_64bits((const u8 *)A, (const u8 *)B) -static const u8 null_mac_addr[ETH_ALEN + 2] __long_aligned = { -0 ,0 ,0 ,0 ,0 ,0 -}; -static const u16 ad_ticks_per_sec =1000 /AD_TIMER_INTERVAL ;static const int ad_delta_in_ticks = (AD_TIMER_INTERVAL *HZ ) /1000 ;
@@ -1583,7 +1579,7 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr) (aggregator->partner_system_priority == port->partner_oper.system_priority) && (aggregator->partner_oper_aggregator_key == port->partner_oper.key) ) && - ((!MAC_ADDRESS_EQUAL (&(port->partner_oper.system), &(null_mac_addr)) &&/* partner answers */ + ((__agg_has_partner (aggregator) &&/* partner answers */ !aggregator->is_individual)/* but is not individual OR */ ) ) {
@@ -2033,9 +2029,7 @@ static void ad_enable_collecting(struct port *port)*/ static void ad_disable_distributing (struct port *port,bool *update_slave_arr) { -if (port->aggregator && - !MAC_ADDRESS_EQUAL (&port->aggregator->partner_system, - &(null_mac_addr))) { +if (port->aggregator &&__agg_has_partner (port->aggregator)) { slave_dbg(port->slave->bond->dev, port->slave->dev, "Disabling distributing on port %d (LAG %d)\n", port->actor_port_number,
@@ -2075,9 +2069,7 @@ static void ad_enable_collecting_distributing(struct port *port,static void ad_disable_collecting_distributing (struct port *port,bool *update_slave_arr) { -if (port->aggregator && - !MAC_ADDRESS_EQUAL (&(port->aggregator->partner_system), - &(null_mac_addr))) { +if (port->aggregator &&__agg_has_partner (port->aggregator)) { slave_dbg(port->slave->bond->dev, port->slave->dev, "Disabling port %d (LAG %d)\n", port->actor_port_number,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 779/969 net: bonding: add broadcast_neighbor option for 802.3ad
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tonghao Zhang <[email protected]>
[ Upstream commit ce7a381697cb3958ffe0b45e5028ac69444e9288 ]
Stacking technology is a type of technology used to expand ports on Ethernet switches. It is widely used as a common access method in large-scale Internet data center architectures. Years of practice have proved that stacking technology has advantages and disadvantages in high-reliability network architecture scenarios. For instance, in stacking networking arch, conventional switch system upgrades require multiple stacked devices to restart at the same time. Therefore, it is inevitable that the business will be interrupted for a while. It is for this reason that "no-stacking" in data centers has become a trend. Additionally, when the stacking link connecting the switches fails or is abnormal, the stack will split. Although it is not common, it still happens in actual operation. The problem is that after the split, it is equivalent to two switches with the same configuration appearing in the network, causing network configuration conflicts and ultimately interrupting the services carried by the stacking system.
To improve network stability, "non-stacking" solutions have been increasingly adopted, particularly by public cloud providers and tech companies like Alibaba, Tencent, and Didi. "non-stacking" is a method of mimicing switch stacking that convinces a LACP peer, bonding in this case, connected to a set of "non-stacked" switches that all of its ports are connected to a single switch (i.e., LACP aggregator), as if those switches were stacked. This enables the LACP peer's ports to aggregate together, and requires
(a) special switch configuration, described in the linked article, and (b) modifications to the bonding 802.3ad (LACP) mode to send all ARP/ND packets across all ports of the active aggregator.
Note that, with multiple aggregators, the current broadcast mode logic will send only packets to the selected aggregator(s).
+-----------+ +-----------+
| switch1 | | switch2 |
+-----------+ +-----------+
^ ^
| |
+-----------------+
| bond4 lacp |
+-----------------+
| |
| NIC1 | NIC2
+-----------------+
| server |
+-----------------+- https://www.ruijie.com/fr-fr/support/tech-gallery/de-stack-data-center-network-architecture/
Stable-dep-of: c4f050ce06c5 ("bonding: 3ad: implement proper RCU rules for port->aggregator")
--- Documentation/networking/bonding.rst | 6 +++ drivers/net/bonding/bond_main.c | 66 +++++++++++++++++++++++++--- drivers/net/bonding/bond_options.c | 42 ++++++++++++++++++ include/net/bond_options.h | 1 + include/net/bonding.h | 3 ++ 5 files changed, 112 insertions(+), 6 deletions(-)
Documentation/networking/bonding.rst +6 -0
@@ -562,6 +562,12 @@ lacp_rate The default is slow. +broadcast_neighbor + + Option specifying whether to broadcast ARP/ND packets to all + active slaves. This option has no effect in modes other than + 802.3ad mode. The default is off (0). + max_bonds Specifies the number of bonding devices to create for this
drivers/net/bonding/bond_main.c +60 -6
117 lines not on this page · raw message
drivers/net/bonding/bond_options.c +42 -0
69 lines not on this page · raw message
include/net/bond_options.h +1 -0
@@ -77,6 +77,7 @@ enum {BOND_OPT_NS_TARGETS ,BOND_OPT_PRIO ,BOND_OPT_COUPLED_CONTROL , +BOND_OPT_BROADCAST_NEIGH , BOND_OPT_LAST };
include/net/bonding.h +3 -0
@@ -119,6 +119,8 @@ static inline int is_netpoll_tx_blocked(struct net_device *dev)#define is_netpoll_tx_blocked (dev) (0)#endif +DECLARE_STATIC_KEY_FALSE (bond_bcast_neigh_enabled); +struct bond_params {int mode;int xmit_policy;
@@ -153,6 +155,7 @@ struct bond_params {struct in6_addr ns_targets[BOND_MAX_NS_TARGETS ];#endif int coupled_control; +int broadcast_neighbor;/* 2 bytes of padding : see ether_addr_equal_64bits() */ u8 ad_actor_system[ETH_ALEN +2 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 780/969 bonding: add support for per-port LACP actor priority
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hangbin Liu <[email protected]>
[ Upstream commit 6b6dc81ee7e8ca87c71a533e1d69cf96a4f1e986 ]
Introduce a new netlink attribute 'actor_port_prio' to allow setting the LACP actor port priority on a per-slave basis. This extends the existing bonding infrastructure to support more granular control over LACP negotiations.
The priority value is embedded in LACPDU packets and will be used by subsequent patches to influence aggregator selection policies.
Stable-dep-of: c4f050ce06c5 ("bonding: 3ad: implement proper RCU rules for port->aggregator")
--- Documentation/networking/bonding.rst | 9 +++++++ drivers/net/bonding/bond_3ad.c | 4 ++++ drivers/net/bonding/bond_netlink.c | 16 +++++++++++++ drivers/net/bonding/bond_options.c | 36 ++++++++++++++++++++++++++++ include/net/bond_3ad.h | 1 + include/net/bond_options.h | 1 + include/uapi/linux/if_link.h | 1 + 7 files changed, 68 insertions(+)
Documentation/networking/bonding.rst +9 -0
@@ -193,6 +193,15 @@ ad_actor_sys_prio This parameter has effect only in 802.3ad mode and is available through SysFs interface. +actor_port_prio + + In an AD system, this specifies the port priority. The allowed range + is 1 - 65535. If the value is not specified, it takes 255 as the + default value. + + This parameter has effect only in 802.3ad mode and is available through + netlink interface. + ad_actor_system In an AD system, this specifies the mac-address for the actor in
drivers/net/bonding/bond_3ad.c +4 -0
@@ -430,6 +430,7 @@ static void __ad_actor_update_port(struct port *port) port->actor_system =BOND_AD_INFO (bond).system.sys_mac_addr; port->actor_system_priority =BOND_AD_INFO (bond).system.sys_priority; + port->actor_port_priority =SLAVE_AD_INFO (port->slave)->port_priority; }/* Conversions */
@@ -2186,6 +2187,9 @@ void bond_3ad_bind_slave(struct slave *slave)ad_initialize_port (port, &bond->params); +/* Port priority is initialized. Update it to slave's ad info */ +SLAVE_AD_INFO (slave)->port_priority = port->actor_port_priority; + port->slave = slave; port->actor_port_number =SLAVE_AD_INFO (slave)->id;/* key is determined according to the link speed, duplex and
drivers/net/bonding/bond_netlink.c +16 -0
@@ -28,6 +28,7 @@ static size_t bond_get_slave_size(const struct net_device *bond_dev,nla_total_size (sizeof (u8)) +/* IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE */ nla_total_size (sizeof (u16)) +/* IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE */ nla_total_size (sizeof (s32)) +/* IFLA_BOND_SLAVE_PRIO */ +nla_total_size (sizeof (u16)) +/* IFLA_BOND_SLAVE_ACTOR_PORT_PRIO */ 0 ; }
@@ -76,6 +77,10 @@ static int bond_fill_slave_info(struct sk_buff *skb, ad_port->partner_oper.port_state)) goto nla_put_failure; } + +if (nla_put_u16 (skb,IFLA_BOND_SLAVE_ACTOR_PORT_PRIO , +SLAVE_AD_INFO (slave)->port_priority)) + goto nla_put_failure; }return 0 ;
@@ -128,6 +133,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {static const struct nla_policy bond_slave_policy[IFLA_BOND_SLAVE_MAX +1 ] = { [IFLA_BOND_SLAVE_QUEUE_ID ] = { .type =NLA_U16 }, [IFLA_BOND_SLAVE_PRIO ] = { .type =NLA_S32 }, + [IFLA_BOND_SLAVE_ACTOR_PORT_PRIO ] = { .type =NLA_U16 }, }; static int bond_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -178,6 +184,16 @@ static int bond_slave_changelink(struct net_device *bond_dev,return err; } +if (data[IFLA_BOND_SLAVE_ACTOR_PORT_PRIO ]) { +u16 ad_prio =nla_get_u16 (data[IFLA_BOND_SLAVE_ACTOR_PORT_PRIO ]); + +bond_opt_slave_initval (&newval, &slave_dev, ad_prio); + err =__bond_opt_set (bond,BOND_OPT_ACTOR_PORT_PRIO , &newval, + data[IFLA_BOND_SLAVE_ACTOR_PORT_PRIO ], extack); +if (err) +return err; + } +return 0 ; }
drivers/net/bonding/bond_options.c +36 -0
@@ -79,6 +79,8 @@ static int bond_option_tlb_dynamic_lb_set(struct bonding *bond, const struct bond_opt_value *newval);static int bond_option_ad_actor_sys_prio_set (struct bonding *bond,const struct bond_opt_value *newval); +static int bond_option_actor_port_prio_set (struct bonding *bond, +const struct bond_opt_value *newval);static int bond_option_ad_actor_system_set (struct bonding *bond,const struct bond_opt_value *newval); static int bond_option_ad_user_port_key_set(struct bonding *bond,
@@ -223,6 +225,13 @@ static const struct bond_opt_value bond_ad_actor_sys_prio_tbl[] = { { NULL, -1, 0}, }; +static const struct bond_opt_value bond_actor_port_prio_tbl[] = { + {"minval" ,0 ,BOND_VALFLAG_MIN }, + {"maxval" ,65535 ,BOND_VALFLAG_MAX }, + {"default" ,255 ,BOND_VALFLAG_DEFAULT }, + {NULL ,-1 ,0 }, +}; +static const struct bond_opt_value bond_ad_user_port_key_tbl[] = { {"minval" ,0 ,BOND_VALFLAG_MIN |BOND_VALFLAG_DEFAULT }, { "maxval", 1023, BOND_VALFLAG_MAX},
@@ -484,6 +493,13 @@ static const struct bond_option bond_opts[BOND_OPT_LAST] = { .values = bond_ad_actor_sys_prio_tbl, .set = bond_option_ad_actor_sys_prio_set, }, + [BOND_OPT_ACTOR_PORT_PRIO] = { + .id = BOND_OPT_ACTOR_PORT_PRIO, + .name = "actor_port_prio", + .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), + .values = bond_actor_port_prio_tbl, + .set = bond_option_actor_port_prio_set, + }, [BOND_OPT_AD_ACTOR_SYSTEM] = { .id = BOND_OPT_AD_ACTOR_SYSTEM, .name = "ad_actor_system",
@@ -1833,6 +1849,26 @@ static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,return 0 ; } +static int bond_option_actor_port_prio_set (struct bonding *bond, +const struct bond_opt_value *newval) +{ +struct slave *slave; + + slave =bond_slave_get_rtnl (newval->slave_dev); +if (!slave) { +netdev_dbg (bond->dev,"%s called on NULL slave\n" , __func__); +return -ENODEV ; + } + +netdev_dbg (newval->slave_dev,"Setting actor_port_prio to %llu\n" , + newval->value); + +SLAVE_AD_INFO (slave)->port_priority = newval->value; +bond_3ad_update_ad_actor_settings (bond); + +return 0 ; +} +static int bond_option_ad_actor_system_set (struct bonding *bond,const struct bond_opt_value *newval) {
include/net/bond_3ad.h +1 -0
@@ -271,6 +271,7 @@ struct ad_slave_info {struct port port;/* 802.3ad port structure */ struct bond_3ad_stats stats;u16 id; +u16 port_priority; };static inline const char *bond_3ad_churn_desc (churn_state_t state)
include/net/bond_options.h +1 -0
@@ -78,6 +78,7 @@ enum {BOND_OPT_PRIO ,BOND_OPT_COUPLED_CONTROL ,BOND_OPT_BROADCAST_NEIGH , +BOND_OPT_ACTOR_PORT_PRIO , BOND_OPT_LAST };
include/uapi/linux/if_link.h +1 -0
@@ -967,6 +967,7 @@ enum {IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE ,IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE ,IFLA_BOND_SLAVE_PRIO , +IFLA_BOND_SLAVE_ACTOR_PORT_PRIO , __IFLA_BOND_SLAVE_MAX, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 781/969 bonding: print churn state via netlink
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hangbin Liu <[email protected]>
[ Upstream commit 4916f2e2f3fc9aef289fcd07949301e5c29094c2 ]
Currently, the churn state is printed only in sysfs. Add netlink support so users could get the state via netlink.
Stable-dep-of: c4f050ce06c5 ("bonding: 3ad: implement proper RCU rules for port->aggregator")
--- drivers/net/bonding/bond_netlink.c | 9 +++++++++ include/uapi/linux/if_link.h | 2 ++ 2 files changed, 11 insertions(+)
drivers/net/bonding/bond_netlink.c +9 -0
@@ -29,6 +29,8 @@ static size_t bond_get_slave_size(const struct net_device *bond_dev,nla_total_size (sizeof (u16)) +/* IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE */ nla_total_size (sizeof (s32)) +/* IFLA_BOND_SLAVE_PRIO */ nla_total_size (sizeof (u16)) +/* IFLA_BOND_SLAVE_ACTOR_PORT_PRIO */ +nla_total_size (sizeof (u8)) +/* IFLA_BOND_SLAVE_AD_CHURN_ACTOR_STATE */ +nla_total_size (sizeof (u8)) +/* IFLA_BOND_SLAVE_AD_CHURN_PARTNER_STATE */ 0 ; }
@@ -76,6 +78,13 @@ static int bond_fill_slave_info(struct sk_buff *skb, IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE, ad_port->partner_oper.port_state)) goto nla_put_failure; + +if (nla_put_u8 (skb,IFLA_BOND_SLAVE_AD_CHURN_ACTOR_STATE , + ad_port->sm_churn_actor_state)) + goto nla_put_failure; +if (nla_put_u8 (skb,IFLA_BOND_SLAVE_AD_CHURN_PARTNER_STATE , + ad_port->sm_churn_partner_state)) + goto nla_put_failure; } if (nla_put_u16(skb, IFLA_BOND_SLAVE_ACTOR_PORT_PRIO,
include/uapi/linux/if_link.h +2 -0
@@ -968,6 +968,8 @@ enum {IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE ,IFLA_BOND_SLAVE_PRIO ,IFLA_BOND_SLAVE_ACTOR_PORT_PRIO , +IFLA_BOND_SLAVE_AD_CHURN_ACTOR_STATE , +IFLA_BOND_SLAVE_AD_CHURN_PARTNER_STATE , __IFLA_BOND_SLAVE_MAX, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 782/969 bonding: 3ad: implement proper RCU rules for port->aggregator
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit c4f050ce06c56cfb5993268af4a5cb66ed1cd04e ]
syzbot found a data-race in bond_3ad_get_active_agg_info / bond_3ad_state_machine_handler [1] which hints at lack of proper RCU implementation.
Add __rcu qualifier to port->aggregator, and add proper RCU API.
[1]
BUG: KCSAN: data-race in bond_3ad_get_active_agg_info / bond_3ad_state_machine_handler
write to 0xffff88813cf5c4b0 of 8 bytes by task 36 on cpu 0:
ad_port_selection_logic drivers/net/bonding/bond_3ad.c:1659 [inline] bond_3ad_state_machine_handler+0x9d5/0x2d60 drivers/net/bonding/bond_3ad.c:2569 process_one_work kernel/workqueue.c:3302 [inline] process_scheduled_works+0x4f0/0x9c0 kernel/workqueue.c:3385 worker_thread+0x58a/0x780 kernel/workqueue.c:3466 kthread+0x22a/0x280 kernel/kthread.c:436 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
read to 0xffff88813cf5c4b0 of 8 bytes by task 22063 on cpu 1:
__bond_3ad_get_active_agg_info drivers/net/bonding/bond_3ad.c:2858 [inline] bond_3ad_get_active_agg_info+0x8c/0x230 drivers/net/bonding/bond_3ad.c:2881 bond_fill_info+0xe0f/0x10f0 drivers/net/bonding/bond_netlink.c:853 rtnl_link_info_fill net/core/rtnetlink.c:906 [inline] rtnl_link_fill+0x1d7/0x4e0 net/core/rtnetlink.c:927 rtnl_fill_ifinfo+0xf8e/0x1380 net/core/rtnetlink.c:2168 rtmsg_ifinfo_build_skb+0x11c/0x1b0 net/core/rtnetlink.c:4453 rtmsg_ifinfo_event net/core/rtnetlink.c:4486 [inline] rtmsg_ifinfo+0x6d/0x110 net/core/rtnetlink.c:4495 __dev_notify_flags+0x76/0x390 net/core/dev.c:9790 netif_change_flags+0xac/0xd0 net/core/dev.c:9823 do_setlink+0x905/0x2950 net/core/rtnetlink.c:3180 rtnl_group_changelink net/core/rtnetlink.c:3813 [inline] __rtnl_newlink net/core/rtnetlink.c:3981 [inline] rtnl_newlink+0xf55/0x1400 net/core/rtnetlink.c:4109 rtnetlink_rcv_msg+0x64b/0x720 net/core/rtnetlink.c:6995 netlink_rcv_skb+0x123/0x220 net/netlink/af_netlink.c:2550 rtnetlink_rcv+0x1c/0x30 net/core/rtnetlink.c:7022 netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline] netlink_unicast+0x5a8/0x680 net/netlink/af_netlink.c:1344 netlink_sendmsg+0x5c8/0x6f0 net/netlink/af_netlink.c:1894 sock_sendmsg_nosec net/socket.c:787 [inline] __sock_sendmsg net/socket.c:802 [inline] ____sys_sendmsg+0x563/0x5b0 net/socket.c:2698 ___sys_sendmsg+0x195/0x1e0 net/socket.c:2752 __sys_sendmsg net/socket.c:2784 [inline] __do_sys_sendmsg net/socket.c:2789 [inline] __se_sys_sendmsg net/socket.c:2787 [inline] __x64_sys_sendmsg+0xd4/0x160 net/socket.c:2787 x64_sys_call+0x194c/0x3020 arch/x86/include/generated/asm/syscalls_64.h:47 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x12c/0x3b0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f
value changed: 0x0000000000000000 -> 0xffff88813cf5c400
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 22063 Comm: syz.0.31122 Tainted: G W syzkaller #0 PREEMPT(full) Tainted: [W]=WARN Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/18/2026
--- drivers/net/bonding/bond_3ad.c | 109 ++++++++++++++----------- drivers/net/bonding/bond_main.c | 8 +- drivers/net/bonding/bond_netlink.c | 16 ++-- drivers/net/bonding/bond_procfs.c | 3 +- drivers/net/bonding/bond_sysfs_slave.c | 17 ++-- include/net/bond_3ad.h | 2 +- 6 files changed, 89 insertions(+), 66 deletions(-)
drivers/net/bonding/bond_3ad.c +60 -49
@@ -982,6 +982,7 @@ static int ad_marker_send(struct port *port, struct bond_marker *marker)static void ad_mux_machine (struct port *port,bool *update_slave_arr) {struct bonding *bond =__get_bond_by_port (port); +struct aggregator *aggregator;mux_states_t last_state;/* keep current State Machine state to compare later if it was
@@ -989,6 +990,7 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr)*/ last_state = port->sm_mux_state; + aggregator =rcu_dereference (port->aggregator);if (port->sm_vars &AD_PORT_BEGIN ) { port->sm_mux_state =AD_MUX_DETACHED ; }else {
@@ -1008,7 +1010,7 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr)* cycle to update ready variable, we check * READY_N and update READY here */ -__set_agg_ports_ready (port->aggregator,__agg_ports_are_ready (port->aggregator)); +__set_agg_ports_ready (aggregator,__agg_ports_are_ready (aggregator)); port->sm_mux_state =AD_MUX_DETACHED ;break ; }
@@ -1023,7 +1025,7 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr)* update ready variable, we check READY_N and update * READY here */ -__set_agg_ports_ready (port->aggregator,__agg_ports_are_ready (port->aggregator)); +__set_agg_ports_ready (aggregator,__agg_ports_are_ready (aggregator));/* if the wait_while_timer expired, and the port is * in READY state, move to ATTACHED state
@@ -1039,7 +1041,7 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr)if ((port->sm_vars &AD_PORT_SELECTED ) && (port->partner_oper.port_state &LACP_STATE_SYNCHRONIZATION ) && !__check_agg_selection_timer (port)) { -if (port->aggregator->is_active) { +if (aggregator->is_active) {int state =AD_MUX_COLLECTING_DISTRIBUTING ;if (!bond->params.coupled_control)
@@ -1055,9 +1057,9 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr)* cycle to update ready variable, we check * READY_N and update READY here */ -__set_agg_ports_ready (port->aggregator,__agg_ports_are_ready (port->aggregator)); +__set_agg_ports_ready (aggregator,__agg_ports_are_ready (aggregator)); port->sm_mux_state =AD_MUX_DETACHED ; - }else if (port->aggregator->is_active) { + }else if (aggregator->is_active) { port->actor_oper_port_state |=LACP_STATE_SYNCHRONIZATION ; }
@@ -1068,7 +1070,7 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr)* sure that a collecting distributing * port in an active aggregator is enabled */ -if (port->aggregator->is_active && +if (aggregator->is_active && !__port_is_collecting_distributing (port)) {__enable_port (port); *update_slave_arr = true;
@@ -1087,7 +1089,7 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr)*/ struct slave *slave = port->slave; -if (port->aggregator->is_active && +if (aggregator->is_active &&bond_is_slave_rx_disabled (slave)) {ad_enable_collecting (port); *update_slave_arr = true;
@@ -1107,8 +1109,8 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr)* sure that a collecting distributing * port in an active aggregator is enabled */ -if (port->aggregator && - port->aggregator->is_active && +if (aggregator && + aggregator->is_active && !__port_is_collecting_distributing (port)) {__enable_port (port); *update_slave_arr = true;
@@ -1140,7 +1142,7 @@ static void ad_mux_machine(struct port *port, bool *update_slave_arr) port->sm_mux_timer_counter =__ad_timer_to_ticks (AD_WAIT_WHILE_TIMER ,0 );break ;case AD_MUX_ATTACHED : -if (port->aggregator->is_active) +if (aggregator->is_active) port->actor_oper_port_state |=LACP_STATE_SYNCHRONIZATION ;else
@@ -1513,9 +1515,9 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr) bond =__get_bond_by_port (port);/* if the port is connected to other aggregator, detach it */ -if (port->aggregator) { + temp_aggregator =rcu_dereference (port->aggregator); +if (temp_aggregator) {/* detach the port from its former aggregator */ - temp_aggregator = port->aggregator;for (curr_port = temp_aggregator->lag_ports; curr_port; last_port = curr_port, curr_port = curr_port->next_port_in_aggregator) {
@@ -1538,7 +1540,7 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr)/* clear the port's relations to this * aggregator */ - port->aggregator =NULL ; +RCU_INIT_POINTER (port->aggregator,NULL ); port->next_port_in_aggregator =NULL ; port->actor_port_aggregator_identifier =0 ;
@@ -1561,7 +1563,7 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr) port->slave->bond->dev->name, port->slave->dev->name, port->actor_port_number, - port->aggregator->aggregator_identifier); + temp_aggregator->aggregator_identifier); } }/* search on all aggregators for a suitable aggregator for this port */
@@ -1585,15 +1587,15 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr) ) ) {/* attach to the founded aggregator */ - port->aggregator = aggregator; +rcu_assign_pointer (port->aggregator, aggregator); port->actor_port_aggregator_identifier = - port->aggregator->aggregator_identifier; + aggregator->aggregator_identifier; port->next_port_in_aggregator = aggregator->lag_ports; - port->aggregator->num_of_ports++; + aggregator->num_of_ports++; aggregator->lag_ports = port;slave_dbg (bond->dev, slave->dev,"Port %d joined LAG %d (existing LAG)\n" , port->actor_port_number, - port->aggregator->aggregator_identifier); + aggregator->aggregator_identifier);/* mark this port as selected */ port->sm_vars |=AD_PORT_SELECTED ;
@@ -1608,39 +1610,40 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr)if (!found) {if (free_aggregator) {/* assign port a new aggregator */ - port->aggregator = free_aggregator; port->actor_port_aggregator_identifier = - port->aggregator->aggregator_identifier; + free_aggregator->aggregator_identifier;/* update the new aggregator's parameters * if port was responsed from the end-user */ if (port->actor_oper_port_key &AD_DUPLEX_KEY_MASKS )/* if port is full duplex */ - port->aggregator->is_individual = false; + free_aggregator->is_individual = false;else - port->aggregator->is_individual = true; + free_aggregator->is_individual = true; - port->aggregator->actor_admin_aggregator_key = + free_aggregator->actor_admin_aggregator_key = port->actor_admin_port_key; - port->aggregator->actor_oper_aggregator_key = + free_aggregator->actor_oper_aggregator_key = port->actor_oper_port_key; - port->aggregator->partner_system = + free_aggregator->partner_system = port->partner_oper.system; - port->aggregator->partner_system_priority = + free_aggregator->partner_system_priority = port->partner_oper.system_priority; - port->aggregator->partner_oper_aggregator_key = port->partner_oper.key; - port->aggregator->receive_state =1 ; - port->aggregator->transmit_state =1 ; - port->aggregator->lag_ports = port; - port->aggregator->num_of_ports++; + free_aggregator->partner_oper_aggregator_key = port->partner_oper.key; + free_aggregator->receive_state =1 ; + free_aggregator->transmit_state =1 ; + free_aggregator->lag_ports = port; + free_aggregator->num_of_ports++; + +rcu_assign_pointer (port->aggregator, free_aggregator);/* mark this port as selected */ port->sm_vars |=AD_PORT_SELECTED ;slave_dbg (bond->dev, port->slave->dev,"Port %d joined LAG %d (new LAG)\n" , port->actor_port_number, - port->aggregator->aggregator_identifier); + free_aggregator->aggregator_identifier); }else { slave_err(bond->dev, port->slave->dev, "Port %d did not find a suitable aggregator\n",
@@ -1652,13 +1655,12 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr)* in all aggregator's ports, else set ready=FALSE in all * aggregator's ports */ -__set_agg_ports_ready (port->aggregator, -__agg_ports_are_ready (port->aggregator)); + aggregator =rcu_dereference (port->aggregator); +__set_agg_ports_ready (aggregator,__agg_ports_are_ready (aggregator)); - aggregator =__get_first_agg (port); -ad_agg_selection_logic (aggregator, update_slave_arr); +ad_agg_selection_logic (__get_first_agg (port), update_slave_arr); -if (!port->aggregator->is_active) +if (!aggregator->is_active) port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION ; }
@@ -2012,13 +2014,15 @@ static void ad_initialize_port(struct port *port, const struct bond_params *bond*/ static void ad_enable_collecting (struct port *port) { -if (port->aggregator->is_active) { +struct aggregator *aggregator =rcu_dereference (port->aggregator); + +if (aggregator->is_active) {struct slave *slave = port->slave;slave_dbg (slave->bond->dev, slave->dev,"Enabling collecting on port %d (LAG %d)\n" , port->actor_port_number, - port->aggregator->aggregator_identifier); + aggregator->aggregator_identifier);__enable_collecting_port (port); } }
@@ -2030,11 +2034,13 @@ static void ad_enable_collecting(struct port *port)*/ static void ad_disable_distributing (struct port *port,bool *update_slave_arr) { -if (port->aggregator &&__agg_has_partner (port->aggregator)) { +struct aggregator *aggregator =rcu_dereference (port->aggregator); + +if (aggregator &&__agg_has_partner (aggregator)) {slave_dbg (port->slave->bond->dev, port->slave->dev,"Disabling distributing on port %d (LAG %d)\n" , port->actor_port_number, - port->aggregator->aggregator_identifier); + aggregator->aggregator_identifier);__disable_distributing_port (port);/* Slave array needs an update */ *update_slave_arr = true;
@@ -2051,11 +2057,13 @@ static void ad_disable_distributing(struct port *port, bool *update_slave_arr)static void ad_enable_collecting_distributing (struct port *port,bool *update_slave_arr) { -if (port->aggregator->is_active) { +struct aggregator *aggregator =rcu_dereference (port->aggregator); + +if (aggregator->is_active) {slave_dbg (port->slave->bond->dev, port->slave->dev,"Enabling port %d (LAG %d)\n" , port->actor_port_number, - port->aggregator->aggregator_identifier); + aggregator->aggregator_identifier);__enable_port (port);/* Slave array needs update */ *update_slave_arr = true;
@@ -2070,11 +2078,13 @@ static void ad_enable_collecting_distributing(struct port *port,static void ad_disable_collecting_distributing (struct port *port,bool *update_slave_arr) { -if (port->aggregator &&__agg_has_partner (port->aggregator)) { +struct aggregator *aggregator =rcu_dereference (port->aggregator); + +if (aggregator &&__agg_has_partner (aggregator)) {slave_dbg (port->slave->bond->dev, port->slave->dev,"Disabling port %d (LAG %d)\n" , port->actor_port_number, - port->aggregator->aggregator_identifier); + aggregator->aggregator_identifier);__disable_port (port);/* Slave array needs an update */ *update_slave_arr = true;
@@ -2314,7 +2324,7 @@ void bond_3ad_unbind_slave(struct slave *slave)*/ for (temp_port = aggregator->lag_ports; temp_port; temp_port = temp_port->next_port_in_aggregator) { - temp_port->aggregator = new_aggregator; +rcu_assign_pointer (temp_port->aggregator, new_aggregator); temp_port->actor_port_aggregator_identifier = new_aggregator->aggregator_identifier; }
@@ -2783,15 +2793,16 @@ int bond_3ad_set_carrier(struct bonding *bond)int __bond_3ad_get_active_agg_info (struct bonding *bond,struct ad_info *ad_info) { -struct aggregator *aggregator =NULL ; +struct aggregator *aggregator =NULL , *tmp;struct list_head *iter;struct slave *slave;struct port *port;bond_for_each_slave_rcu (bond, slave, iter) { port = &(SLAVE_AD_INFO (slave)->port); -if (port->aggregator && port->aggregator->is_active) { - aggregator = port->aggregator; + tmp =rcu_dereference (port->aggregator); +if (tmp && tmp->is_active) { + aggregator = tmp;break ; } }
drivers/net/bonding/bond_main.c +5 -3
@@ -1374,7 +1374,7 @@ static void bond_poll_controller(struct net_device *bond_dev)if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {struct aggregator *agg = -SLAVE_AD_INFO (slave)->port.aggregator; +rcu_dereference (SLAVE_AD_INFO (slave)->port.aggregator);if (agg && agg->aggregator_identifier != ad_info.aggregator_id)
@@ -5183,15 +5183,16 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)spin_unlock_bh (&bond->mode_lock); agg_id = ad_info.aggregator_id; } +rcu_read_lock ();bond_for_each_slave (bond, slave, iter) {if (skipslave == slave)continue ; all_slaves->arr[all_slaves->count++] = slave;if (BOND_MODE (bond) ==BOND_MODE_8023AD ) { -struct aggregator *agg; +const struct aggregator *agg; - agg =SLAVE_AD_INFO (slave)->port.aggregator; + agg =rcu_dereference (SLAVE_AD_INFO (slave)->port.aggregator);if (!agg || agg->aggregator_identifier != agg_id)continue ; }
@@ -5203,6 +5204,7 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave) usable_slaves->arr[usable_slaves->count++] = slave; } +rcu_read_unlock ();bond_set_slave_arr (bond, usable_slaves, all_slaves);return ret;
drivers/net/bonding/bond_netlink.c +10 -6
@@ -65,27 +65,29 @@ static int bond_fill_slave_info(struct sk_buff *skb,const struct port *ad_port; ad_port = &SLAVE_AD_INFO (slave)->port; - agg =SLAVE_AD_INFO (slave)->port.aggregator; +rcu_read_lock (); + agg =rcu_dereference (SLAVE_AD_INFO (slave)->port.aggregator);if (agg) {if (nla_put_u16 (skb,IFLA_BOND_SLAVE_AD_AGGREGATOR_ID , agg->aggregator_identifier)) - goto nla_put_failure; + goto nla_put_failure_rcu;if (nla_put_u8 (skb,IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE , ad_port->actor_oper_port_state)) - goto nla_put_failure; + goto nla_put_failure_rcu;if (nla_put_u16 (skb,IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE , ad_port->partner_oper.port_state)) - goto nla_put_failure; + goto nla_put_failure_rcu;if (nla_put_u8 (skb,IFLA_BOND_SLAVE_AD_CHURN_ACTOR_STATE , ad_port->sm_churn_actor_state)) - goto nla_put_failure; + goto nla_put_failure_rcu;if (nla_put_u8 (skb,IFLA_BOND_SLAVE_AD_CHURN_PARTNER_STATE , ad_port->sm_churn_partner_state)) - goto nla_put_failure; + goto nla_put_failure_rcu; } +rcu_read_unlock ();if (nla_put_u16 (skb,IFLA_BOND_SLAVE_ACTOR_PORT_PRIO ,SLAVE_AD_INFO (slave)->port_priority))
@@ -94,6 +96,8 @@ static int bond_fill_slave_info(struct sk_buff *skb,return 0 ; +nla_put_failure_rcu: +rcu_read_unlock (); nla_put_failure:return -EMSGSIZE ; }
drivers/net/bonding/bond_procfs.c +2 -1
@@ -187,6 +187,7 @@ static void bond_info_show_master(struct seq_file *seq) } } +/* Note: runs under rcu_read_lock() */ static void bond_info_show_slave (struct seq_file *seq,const struct slave *slave) {
@@ -213,7 +214,7 @@ static void bond_info_show_slave(struct seq_file *seq,if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {const struct port *port = &SLAVE_AD_INFO (slave)->port; -const struct aggregator *agg = port->aggregator; +const struct aggregator *agg =rcu_dereference (port->aggregator);if (agg) { seq_printf(seq, "Aggregator ID: %d\n",
drivers/net/bonding/bond_sysfs_slave.c +11 -6
@@ -62,10 +62,15 @@ static ssize_t ad_aggregator_id_show(struct slave *slave, char *buf)const struct aggregator *agg;if (BOND_MODE (slave->bond) ==BOND_MODE_8023AD ) { - agg =SLAVE_AD_INFO (slave)->port.aggregator; -if (agg) -return sysfs_emit (buf,"%d\n" , - agg->aggregator_identifier); +rcu_read_lock (); + agg =rcu_dereference (SLAVE_AD_INFO (slave)->port.aggregator); +if (agg) { +ssize_t res =sysfs_emit (buf,"%d\n" , + agg->aggregator_identifier); +rcu_read_unlock (); +return res; + } +rcu_read_unlock (); }return sysfs_emit (buf,"N/A\n" );
@@ -78,7 +83,7 @@ static ssize_t ad_actor_oper_port_state_show(struct slave *slave, char *buf)if (BOND_MODE (slave->bond) ==BOND_MODE_8023AD ) { ad_port = &SLAVE_AD_INFO (slave)->port; -if (ad_port->aggregator) +if (rcu_access_pointer (ad_port->aggregator))return sysfs_emit (buf,"%u\n" , ad_port->actor_oper_port_state); }
@@ -93,7 +98,7 @@ static ssize_t ad_partner_oper_port_state_show(struct slave *slave, char *buf)if (BOND_MODE (slave->bond) ==BOND_MODE_8023AD ) { ad_port = &SLAVE_AD_INFO (slave)->port; -if (ad_port->aggregator) +if (rcu_access_pointer (ad_port->aggregator))return sysfs_emit (buf,"%u\n" , ad_port->partner_oper.port_state); }
include/net/bond_3ad.h +1 -1
@@ -239,7 +239,7 @@ typedef struct port {churn_state_t sm_churn_actor_state;churn_state_t sm_churn_partner_state;struct slave *slave;/* pointer to the bond slave that this port belongs to */ -struct aggregator *aggregator;/* pointer to an aggregator that this port related to */ +struct aggregator __rcu *aggregator;/* pointer to an aggregator that this port related to */ struct port *next_port_in_aggregator;/* Next port on the linked list of the parent aggregator */ u32 transaction_id;/* continuous number for identification of Marker PDU's; */ struct lacpdu lacpdu;/* the lacpdu that will be sent for this port */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 783/969 iavf: rename IAVF_VLAN_IS_NEW to IAVF_VLAN_ADDING
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Oros <[email protected]>
[ Upstream commit 70d62b669f1f9080a25278fc90b64309f4ae8959 ]
Rename the IAVF_VLAN_IS_NEW state to IAVF_VLAN_ADDING to better describe what the state represents: an ADD request has been sent to the PF and is waiting for a response.
This is a pure rename with no behavioral change, preparing for a cleanup of the VLAN filter state machine.
Stable-dep-of: f2ce65b9b917 ("iavf: stop removing VLAN filters from PF on interface down")
--- drivers/net/ethernet/intel/iavf/iavf.h | 2 +- drivers/net/ethernet/intel/iavf/iavf_virtchnl.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +1 -1
@@ -158,7 +158,7 @@ struct iavf_vlan {enum iavf_vlan_state_t {IAVF_VLAN_INVALID ,IAVF_VLAN_ADD ,/* filter needs to be added */ -IAVF_VLAN_IS_NEW ,/* filter is new, wait for PF answer */ +IAVF_VLAN_ADDING ,/* ADD sent to PF, waiting for response */ IAVF_VLAN_ACTIVE ,/* filter is accepted by PF */ IAVF_VLAN_DISABLE ,/* filter needs to be deleted by PF, then marked INACTIVE */ IAVF_VLAN_INACTIVE ,/* filter is inactive, we are in IFF_DOWN */
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +4 -4
@@ -642,7 +642,7 @@ static void iavf_vlan_add_reject(struct iavf_adapter *adapter)spin_lock_bh (&adapter->mac_vlan_list_lock);list_for_each_entry_safe (f, ftmp, &adapter->vlan_filter_list, list) { -if (f->state ==IAVF_VLAN_IS_NEW ) { +if (f->state ==IAVF_VLAN_ADDING ) {list_del (&f->list);kfree (f); adapter->num_vlan_filters--;
@@ -707,7 +707,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter)if (f->state ==IAVF_VLAN_ADD ) { vvfl->vlan_id[i] = f->vlan.vid; i++; - f->state =IAVF_VLAN_IS_NEW ; + f->state =IAVF_VLAN_ADDING ;if (i == count)break ; }
@@ -771,7 +771,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter) vlan->tpid = f->vlan.tpid; i++; - f->state =IAVF_VLAN_IS_NEW ; + f->state =IAVF_VLAN_ADDING ; } }
@@ -2535,7 +2535,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,spin_lock_bh (&adapter->mac_vlan_list_lock);list_for_each_entry (f, &adapter->vlan_filter_list, list) { -if (f->state ==IAVF_VLAN_IS_NEW ) +if (f->state ==IAVF_VLAN_ADDING ) f->state =IAVF_VLAN_ACTIVE ; }spin_unlock_bh (&adapter->mac_vlan_list_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 784/969 iavf: stop removing VLAN filters from PF on interface down
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Oros <[email protected]>
[ Upstream commit f2ce65b9b917474a1a6ce68d357e15fac2aca0f2 ]
When a VF goes down, the driver currently sends DEL_VLAN to the PF for every VLAN filter (ACTIVE -> DISABLE -> send DEL -> INACTIVE), then re-adds them all on UP (INACTIVE -> ADD -> send ADD -> ADDING -> ACTIVE). This round-trip is unnecessary because:
1. The PF disables the VF's queues via VIRTCHNL_OP_DISABLE_QUEUES, which already prevents all RX/TX traffic regardless of VLAN filter state.
2. The VLAN filters remaining in PF HW while the VF is down is harmless - packets matching those filters have nowhere to go with queues disabled.
3. The DEL+ADD cycle during down/up creates race windows where the VLAN filter list is incomplete. With spoofcheck enabled, the PF enables TX VLAN filtering on the first non-zero VLAN add, blocking traffic for any VLANs not yet re-added.
Remove the entire DISABLE/INACTIVE state machinery:
- Remove IAVF_VLAN_DISABLE and IAVF_VLAN_INACTIVE enum values
- Remove iavf_restore_filters() and its call from iavf_open()
- Remove VLAN filter handling from iavf_clear_mac_vlan_filters(), rename it to iavf_clear_mac_filters()
- Remove DEL_VLAN_FILTER scheduling from iavf_down()
- Remove all DISABLE/INACTIVE handling from iavf_del_vlans()
VLAN filters now stay ACTIVE across down/up cycles. Only explicit user removal (ndo_vlan_rx_kill_vid) or PF/VF reset triggers VLAN filter deletion/re-addition.
--- drivers/net/ethernet/intel/iavf/iavf.h | 6 +-- drivers/net/ethernet/intel/iavf/iavf_main.c | 39 ++----------------- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 33 +++------------- 3 files changed, 12 insertions(+), 66 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +2 -4
@@ -159,10 +159,8 @@ enum iavf_vlan_state_t {IAVF_VLAN_INVALID ,IAVF_VLAN_ADD ,/* filter needs to be added */ IAVF_VLAN_ADDING ,/* ADD sent to PF, waiting for response */ -IAVF_VLAN_ACTIVE ,/* filter is accepted by PF */ -IAVF_VLAN_DISABLE ,/* filter needs to be deleted by PF, then marked INACTIVE */ -IAVF_VLAN_INACTIVE ,/* filter is inactive, we are in IFF_DOWN */ - IAVF_VLAN_REMOVE, /* filter needs to be removed from list */ +IAVF_VLAN_ACTIVE ,/* PF confirmed, filter is in HW */ + IAVF_VLAN_REMOVE, /* filter queued for DEL from PF */ }; struct iavf_vlan_filter {
drivers/net/ethernet/intel/iavf/iavf_main.c +4 -35
@@ -875,27 +875,6 @@ static void iavf_del_vlan(struct iavf_adapter *adapter, struct iavf_vlan vlan)spin_unlock_bh (&adapter->mac_vlan_list_lock); } -/** -* iavf_restore_filters -* @adapter: board private structure -* -* Restore existing non MAC filters when VF netdev comes back up -**/ -static void iavf_restore_filters (struct iavf_adapter *adapter) -{ -struct iavf_vlan_filter *f; - -/* re-add all VLAN filters */ -spin_lock_bh (&adapter->mac_vlan_list_lock); - -list_for_each_entry (f, &adapter->vlan_filter_list, list) { -if (f->state ==IAVF_VLAN_INACTIVE ) - f->state =IAVF_VLAN_ADD ; - } - -spin_unlock_bh (&adapter->mac_vlan_list_lock); - adapter->aq_required |=IAVF_FLAG_AQ_ADD_VLAN_FILTER ; -}/** * iavf_get_num_vlans_added - get number of VLANs added
@@ -1322,13 +1301,12 @@ static void iavf_up_complete(struct iavf_adapter *adapter) }/** -* iavf_clear_mac_vlan_filters - Remove mac and vlan filters not sent to PF -* yet and mark other to be removed. +* iavf_clear_mac_filters - Remove MAC filters not sent to PF yet and mark +* others to be removed. * @adapter: board private structure **/ -static void iavf_clear_mac_vlan_filters (struct iavf_adapter *adapter) +static void iavf_clear_mac_filters (struct iavf_adapter *adapter) { -struct iavf_vlan_filter *vlf, *vlftmp;struct iavf_mac_filter *f, *ftmp;spin_lock_bh (&adapter->mac_vlan_list_lock);
@@ -1347,11 +1325,6 @@ static void iavf_clear_mac_vlan_filters(struct iavf_adapter *adapter) } } -/* disable all VLAN filters */ -list_for_each_entry_safe (vlf, vlftmp, &adapter->vlan_filter_list, - list) - vlf->state =IAVF_VLAN_DISABLE ; -spin_unlock_bh (&adapter->mac_vlan_list_lock); }
@@ -1447,7 +1420,7 @@ void iavf_down(struct iavf_adapter *adapter)iavf_napi_disable_all (adapter);iavf_irq_disable (adapter); -iavf_clear_mac_vlan_filters (adapter); +iavf_clear_mac_filters (adapter);iavf_clear_cloud_filters (adapter);iavf_clear_fdir_filters (adapter);iavf_clear_adv_rss_conf (adapter);
@@ -1462,8 +1435,6 @@ void iavf_down(struct iavf_adapter *adapter)*/ if (!list_empty (&adapter->mac_filter_list)) adapter->aq_required |=IAVF_FLAG_AQ_DEL_MAC_FILTER ; -if (!list_empty (&adapter->vlan_filter_list)) - adapter->aq_required |=IAVF_FLAG_AQ_DEL_VLAN_FILTER ;if (!list_empty (&adapter->cloud_filter_list)) adapter->aq_required |=IAVF_FLAG_AQ_DEL_CLOUD_FILTER ;if (!list_empty (&adapter->fdir_list_head))
@@ -4352,8 +4323,6 @@ static int iavf_open(struct net_device *netdev)spin_unlock_bh (&adapter->mac_vlan_list_lock); -/* Restore filters that were removed with IFF_DOWN */ -iavf_restore_filters (adapter);iavf_restore_fdir_filters (adapter);iavf_configure (adapter);
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +6 -27
@@ -808,22 +808,12 @@ void iavf_del_vlans(struct iavf_adapter *adapter)spin_lock_bh (&adapter->mac_vlan_list_lock);list_for_each_entry_safe (f, ftmp, &adapter->vlan_filter_list, list) { -/* since VLAN capabilities are not allowed, we dont want to send -* a VLAN delete request because it will most likely fail and -* create unnecessary errors/noise, so just free the VLAN -* filters marked for removal to enable bailing out before -* sending a virtchnl message -*/ if (f->state ==IAVF_VLAN_REMOVE && !VLAN_FILTERING_ALLOWED (adapter)) {list_del (&f->list);kfree (f); adapter->num_vlan_filters--; - }else if (f->state ==IAVF_VLAN_DISABLE && - !VLAN_FILTERING_ALLOWED (adapter)) { - f->state =IAVF_VLAN_INACTIVE ; - }else if (f->state ==IAVF_VLAN_REMOVE || - f->state ==IAVF_VLAN_DISABLE ) { + }else if (f->state ==IAVF_VLAN_REMOVE ) { count++; } }
@@ -855,13 +845,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter) vvfl->vsi_id = adapter->vsi_res->vsi_id; vvfl->num_elements = count;list_for_each_entry_safe (f, ftmp, &adapter->vlan_filter_list, list) { -if (f->state ==IAVF_VLAN_DISABLE ) { - vvfl->vlan_id[i] = f->vlan.vid; - f->state =IAVF_VLAN_INACTIVE ; - i++; -if (i == count) -break ; - }else if (f->state ==IAVF_VLAN_REMOVE ) { +if (f->state ==IAVF_VLAN_REMOVE ) { vvfl->vlan_id[i] = f->vlan.vid;list_del (&f->list);kfree (f);
@@ -906,8 +890,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter) vvfl_v2->vport_id = adapter->vsi_res->vsi_id; vvfl_v2->num_elements = count;list_for_each_entry_safe (f, ftmp, &adapter->vlan_filter_list, list) { -if (f->state ==IAVF_VLAN_DISABLE || - f->state ==IAVF_VLAN_REMOVE ) { +if (f->state ==IAVF_VLAN_REMOVE ) {struct virtchnl_vlan_supported_caps *filtering_support = &adapter->vlan_v2_caps.filtering.filtering_support;struct virtchnl_vlan *vlan;
@@ -921,13 +904,9 @@ void iavf_del_vlans(struct iavf_adapter *adapter) vlan->tci = f->vlan.vid; vlan->tpid = f->vlan.tpid; -if (f->state ==IAVF_VLAN_DISABLE ) { - f->state =IAVF_VLAN_INACTIVE ; - }else { -list_del (&f->list); -kfree (f); - adapter->num_vlan_filters--; - } +list_del (&f->list); +kfree (f); + adapter->num_vlan_filters--; i++;if (i == count)break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 785/969 iavf: wait for PF confirmation before removing VLAN filters
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Oros <[email protected]>
[ Upstream commit bbcbe4ed70dea948849549af7edf44bd42bbd695 ]
The VLAN filter DELETE path was asymmetric with the ADD path: ADD waits for PF confirmation (ADD -> ADDING -> ACTIVE), but DELETE immediately frees the filter struct after sending the DEL message without waiting for the PF response.
This is problematic because:
- If the PF rejects the DEL, the filter remains in HW but the driver has already freed the tracking structure, losing sync.
- Race conditions between DEL pending and other operations (add, reset) cannot be properly resolved if the filter struct is already gone.
Add IAVF_VLAN_REMOVING state to make the DELETE path symmetric:
REMOVE -> REMOVING (send DEL) -> PF confirms -> kfree
-> PF rejects -> ACTIVE
In iavf_del_vlans(), transition filters from REMOVE to REMOVING instead of immediately freeing them. The new DEL completion handler in iavf_virtchnl_completion() frees filters on success or reverts them to ACTIVE on error.
Update iavf_add_vlan() to handle the REMOVING state: if a DEL is pending and the user re-adds the same VLAN, queue it for ADD so it gets re-programmed after the PF processes the DEL.
The !VLAN_FILTERING_ALLOWED early-exit path still frees filters directly since no PF message is sent in that case.
Also update iavf_del_vlan() to skip filters already in REMOVING
state: DEL has been sent to PF and the completion handler will free the filter when PF confirms. Without this guard, the sequence DEL(pending) -> user-del -> second DEL could cause the PF to return an error for the second DEL (filter already gone), causing the completion handler to incorrectly revert a deleted filter back to ACTIVE.
--- drivers/net/ethernet/intel/iavf/iavf.h | 1 + drivers/net/ethernet/intel/iavf/iavf_main.c | 13 ++++--- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 37 +++++++++++++------ 3 files changed, 34 insertions(+), 17 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +1 -0
@@ -161,6 +161,7 @@ enum iavf_vlan_state_t {IAVF_VLAN_ADDING ,/* ADD sent to PF, waiting for response */ IAVF_VLAN_ACTIVE ,/* PF confirmed, filter is in HW */ IAVF_VLAN_REMOVE ,/* filter queued for DEL from PF */ + IAVF_VLAN_REMOVING, /* DEL sent to PF, waiting for response */ }; struct iavf_vlan_filter {
drivers/net/ethernet/intel/iavf/iavf_main.c +8 -5
@@ -831,10 +831,10 @@ iavf_vlan_filter *iavf_add_vlan(struct iavf_adapter *adapter, adapter->num_vlan_filters++;iavf_schedule_aq_request (adapter,IAVF_FLAG_AQ_ADD_VLAN_FILTER ); }else if (f->state ==IAVF_VLAN_REMOVE ) { -/* Re-add the filter since we cannot tell whether the -* pending delete has already been processed by the PF. -* A duplicate add is harmless. -*/ +/* DEL not yet sent to PF, cancel it */ + f->state =IAVF_VLAN_ACTIVE ; + }else if (f->state ==IAVF_VLAN_REMOVING ) { +/* DEL already sent to PF, re-add after completion */ f->state =IAVF_VLAN_ADD ;iavf_schedule_aq_request (adapter,IAVF_FLAG_AQ_ADD_VLAN_FILTER );
@@ -865,11 +865,14 @@ static void iavf_del_vlan(struct iavf_adapter *adapter, struct iavf_vlan vlan)list_del (&f->list);kfree (f); adapter->num_vlan_filters--; - }else { + }else if (f->state !=IAVF_VLAN_REMOVING ) { f->state =IAVF_VLAN_REMOVE ;iavf_schedule_aq_request (adapter,IAVF_FLAG_AQ_DEL_VLAN_FILTER ); } +/* If REMOVING, DEL is already sent to PF; completion +* handler will free the filter when PF confirms. +*/ }spin_unlock_bh (&adapter->mac_vlan_list_lock);
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +25 -12
@@ -844,12 +844,10 @@ void iavf_del_vlans(struct iavf_adapter *adapter) vvfl->vsi_id = adapter->vsi_res->vsi_id; vvfl->num_elements = count; -list_for_each_entry_safe (f, ftmp, &adapter->vlan_filter_list, list) { +list_for_each_entry (f, &adapter->vlan_filter_list, list) {if (f->state ==IAVF_VLAN_REMOVE ) { vvfl->vlan_id[i] = f->vlan.vid; -list_del (&f->list); -kfree (f); - adapter->num_vlan_filters--; + f->state =IAVF_VLAN_REMOVING ; i++;if (i == count)break ;
@@ -889,7 +887,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter) vvfl_v2->vport_id = adapter->vsi_res->vsi_id; vvfl_v2->num_elements = count; -list_for_each_entry_safe (f, ftmp, &adapter->vlan_filter_list, list) { +list_for_each_entry (f, &adapter->vlan_filter_list, list) {if (f->state ==IAVF_VLAN_REMOVE ) {struct virtchnl_vlan_supported_caps *filtering_support = &adapter->vlan_v2_caps.filtering.filtering_support;
@@ -904,9 +902,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter) vlan->tci = f->vlan.vid; vlan->tpid = f->vlan.tpid; -list_del (&f->list); -kfree (f); - adapter->num_vlan_filters--; + f->state =IAVF_VLAN_REMOVING ; i++;if (i == count)break ;
@@ -2033,10 +2029,6 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,ether_addr_copy (adapter->hw.mac.addr, netdev->dev_addr);wake_up (&adapter->vc_waitqueue);break ; -case VIRTCHNL_OP_DEL_VLAN : -dev_err (&adapter->pdev->dev,"Failed to delete VLAN filter, error %s\n" , -iavf_stat_str (&adapter->hw, v_retval)); -break ;case VIRTCHNL_OP_DEL_ETH_ADDR :dev_err (&adapter->pdev->dev,"Failed to delete MAC filter, error %s\n" ,iavf_stat_str (&adapter->hw, v_retval));
@@ -2520,6 +2512,27 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,spin_unlock_bh (&adapter->mac_vlan_list_lock); }break ; +case VIRTCHNL_OP_DEL_VLAN : +case VIRTCHNL_OP_DEL_VLAN_V2 : { +struct iavf_vlan_filter *f, *ftmp; + +spin_lock_bh (&adapter->mac_vlan_list_lock); +list_for_each_entry_safe (f, ftmp, &adapter->vlan_filter_list, + list) { +if (f->state ==IAVF_VLAN_REMOVING ) { +if (v_retval) { +/* PF rejected DEL, keep filter */ + f->state =IAVF_VLAN_ACTIVE ; + }else { +list_del (&f->list); +kfree (f); + adapter->num_vlan_filters--; + } + } + } +spin_unlock_bh (&adapter->mac_vlan_list_lock); + } +break ;case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING :/* PF enabled vlan strip on this VF. * Update netdev->features if needed to be in sync with ethtool.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 786/969 iavf: add VIRTCHNL_OP_ADD_VLAN to success completion handler
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Oros <[email protected]>
[ Upstream commit 34d33313b52eeac3a97ad2e3176d523ec70d9283 ]
The V1 ADD_VLAN opcode had no success handler; filters sent via V1 stayed in ADDING state permanently. Add a fallthrough case so V1 filters also transition ADDING -> ACTIVE on PF confirmation.
Critically, add an if (v_retval) break guard: the error switch in iavf_virtchnl_completion() does NOT return after handling errors, it falls through to the success switch. Without this guard, a PF-rejected ADD would incorrectly mark ADDING filters as ACTIVE, creating a driver/HW mismatch where the driver believes the filter is installed but the PF never accepted it.
For V2, this is harmless: iavf_vlan_add_reject() in the error block already kfree'd all ADDING filters, so the success handler finds nothing to transition.
--- drivers/net/ethernet/intel/iavf/iavf_virtchnl.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +4 -0
@@ -2501,9 +2501,13 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,spin_unlock_bh (&adapter->adv_rss_lock); }break ; +case VIRTCHNL_OP_ADD_VLAN :case VIRTCHNL_OP_ADD_VLAN_V2 : {struct iavf_vlan_filter *f; +if (v_retval) +break ; +spin_lock_bh (&adapter->mac_vlan_list_lock);list_for_each_entry (f, &adapter->vlan_filter_list, list) {if (f->state ==IAVF_VLAN_ADDING )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 787/969 ice: Pull common tasks into ice_vf_post_vsi_rebuild
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jacob Keller <[email protected]>
[ Upstream commit aeead3d04fa050a94ed314cc5de97125a957dc9f ]
The Single Root IOV implementation of .post_vsi_rebuild performs some tasks that will ultimately need to be shared with the Scalable IOV implementation such as rebuilding the host configuration.
Refactor by introducing a new wrapper function, ice_vf_post_vsi_rebuild which performs the tasks that will be shared between SR-IOV and Scalable IOV. Move the ice_vf_rebuild_host_cfg and ice_vf_set_initialized calls into this wrapper. Then call the implementation specific post_vsi_rebuild handler afterwards.
This ensures that we will properly re-initialize filters and expected settings for both SR-IOV and Scalable IOV.
Stable-dep-of: 54ef02487914 ("ice: fix NULL pointer dereference in ice_reset_all_vfs()")
--- drivers/net/ethernet/intel/ice/ice_sriov.c | 2 -- drivers/net/ethernet/intel/ice/ice_vf_lib.c | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_sriov.c +0 -2
@@ -841,8 +841,6 @@ static int ice_sriov_vsi_rebuild(struct ice_vf *vf)*/ static void ice_sriov_post_vsi_rebuild (struct ice_vf *vf) { -ice_vf_rebuild_host_cfg (vf); -ice_vf_set_initialized (vf);ice_ena_vf_mappings (vf);wr32 (&vf->pf->hw,VFGEN_RSTAT (vf->vf_id),VIRTCHNL_VFR_VFACTIVE ); }
drivers/net/ethernet/intel/ice/ice_vf_lib.c +17 -2
@@ -270,6 +270,21 @@ static int ice_vf_rebuild_vsi(struct ice_vf *vf)return 0 ; } +/** +* ice_vf_post_vsi_rebuild - Reset tasks that occur after VSI rebuild +* @vf: the VF being reset +* +* Perform reset tasks which must occur after the VSI has been re-created or +* rebuilt during a VF reset. +*/ +static void ice_vf_post_vsi_rebuild (struct ice_vf *vf) +{ +ice_vf_rebuild_host_cfg (vf); +ice_vf_set_initialized (vf); + + vf->vf_ops->post_vsi_rebuild (vf); +} +/** * ice_is_any_vf_in_unicast_promisc - check if any VF(s) * are in unicast promiscuous mode
@@ -495,7 +510,7 @@ void ice_reset_all_vfs(struct ice_pf *pf)ice_vf_pre_vsi_rebuild (vf);ice_vf_rebuild_vsi (vf); - vf->vf_ops->post_vsi_rebuild (vf); +ice_vf_post_vsi_rebuild (vf);mutex_unlock (&vf->cfg_lock); }
@@ -647,7 +662,7 @@ int ice_reset_vf(struct ice_vf *vf, u32 flags) goto out_unlock; } - vf->vf_ops->post_vsi_rebuild (vf); +ice_vf_post_vsi_rebuild (vf); vsi =ice_get_vf_vsi (vf);if (WARN_ON (!vsi)) { err = -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 788/969 ice: fix NULL pointer dereference in ice_reset_all_vfs()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Oros <[email protected]>
[ Upstream commit 54ef02487914c24170c7e1c061e45212dc55365e ]
ice_reset_all_vfs() ignores the return value of ice_vf_rebuild_vsi(). When the VSI rebuild fails (e.g. during NVM firmware update via nvmupdate64e), ice_vsi_rebuild() tears down the VSI on its error path, leaving txq_map and rxq_map as NULL. The subsequent unconditional call to ice_vf_post_vsi_rebuild() leads to a NULL pointer dereference in ice_ena_vf_q_mappings() when it accesses vsi->txq_map[0].
The single-VF reset path in ice_reset_vf() already handles this correctly by checking the return value of ice_vf_reconfig_vsi() and skipping ice_vf_post_vsi_rebuild() on failure.
Apply the same pattern to ice_reset_all_vfs(): check the return value of ice_vf_rebuild_vsi() and skip ice_vf_post_vsi_rebuild() and ice_eswitch_attach_vf() on failure. The VF is left safely disabled (ICE_VF_STATE_INIT not set, VFGEN_RSTAT not set to VFACTIVE) and can be recovered via a VFLR triggered by a PCI reset of the VF (sysfs reset or driver rebind).
Note that this patch does not prevent the VF VSI rebuild from failing during NVM update — the underlying cause is firmware being in a transitional state while the EMP reset is processed, which can cause Admin Queue commands (ice_add_vsi, ice_cfg_vsi_lan) to fail. This patch only prevents the subsequent NULL pointer dereference that crashes the kernel when the rebuild does fail.
crash> bt
PID: 50795 TASK: ff34c9ee708dc680 CPU: 1 COMMAND: "kworker/u512:5"
#0 [ff72159bcfe5bb50] machine_kexec at ffffffffaa8850ee
#1 [ff72159bcfe5bba8] __crash_kexec at ffffffffaaa15fba
#2 [ff72159bcfe5bc68] crash_kexec at ffffffffaaa16540
#3 [ff72159bcfe5bc70] oops_end at ffffffffaa837eda
#4 [ff72159bcfe5bc90] page_fault_oops at ffffffffaa893997
#5 [ff72159bcfe5bce8] exc_page_fault at ffffffffab528595
#6 [ff72159bcfe5bd10] asm_exc_page_fault at ffffffffab600bb2
[exception RIP: ice_ena_vf_q_mappings+0x79]
RIP: ffffffffc0a85b29 RSP: ff72159bcfe5bdc8 RFLAGS: 00010206
RAX: 00000000000f0000 RBX: ff34c9efc9c00000 RCX: 0000000000000000
RDX: 0000000000000000 RSI: 0000000000000010 RDI: ff34c9efc9c00000
RBP: ff34c9efc27d4828 R8: 0000000000000093 R9: 0000000000000040
R10: ff34c9efc27d4828 R11: 0000000000000040 R12: 0000000000100000
R13: 0000000000000010 R14: R15:
ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018
#7 [ff72159bcfe5bdf8] ice_sriov_post_vsi_rebuild at ffffffffc0a85e2e [ice]
#8 [ff72159bcfe5be08] ice_reset_all_vfs at ffffffffc0a920b4 [ice]
#9 [ff72159bcfe5be48] ice_service_task at ffffffffc0a31519 [ice]
#10 [ff72159bcfe5be88] process_one_work at ffffffffaa93dca4
#11 [ff72159bcfe5bec8] worker_thread at ffffffffaa93e9de
#12 [ff72159bcfe5bf18] kthread at ffffffffaa946663
#13 [ff72159bcfe5bf50] ret_from_fork at ffffffffaa8086b9 The panic occurs attempting to dereference the NULL pointer in RDX at ice_sriov.c:294, which loads vsi->txq_map (offset 0x4b8 in ice_vsi).
The faulting VSI is an allocated slab object but not fully initialized after a failed ice_vsi_rebuild():
crash> struct ice_vsi 0xff34c9efc27d4828
netdev = 0x0,
rx_rings = 0x0,
tx_rings = 0x0,
q_vectors = 0x0,
txq_map = 0x0,
rxq_map = 0x0,
alloc_txq = 0x10,
num_txq = 0x10,
alloc_rxq = 0x10,
num_rxq = 0x10,The nvmupdate64e process was performing NVM firmware update:
crash> bt 0xff34c9edd1a30000
PID: 49858 TASK: ff34c9edd1a30000 CPU: 1 COMMAND: "nvmupdate64e"
#0 [ff72159bcd617618] __schedule at ffffffffab5333f8
#4 [ff72159bcd617750] ice_sq_send_cmd at ffffffffc0a35347 [ice] #5 [ff72159bcd6177a8] ice_sq_send_cmd_retry at ffffffffc0a35b47 [ice] #6 [ff72159bcd617810] ice_aq_send_cmd at ffffffffc0a38018 [ice] #7 [ff72159bcd617848] ice_aq_read_nvm at ffffffffc0a40254 [ice] #8 [ff72159bcd6178b8] ice_read_flat_nvm at ffffffffc0a4034c [ice] #9 [ff72159bcd617918] ice_devlink_nvm_snapshot at ffffffffc0a6ffa5 [ice]
dmesg:
ice 0000:13:00.0: firmware recommends not updating fw.mgmt, as it
may result in a downgrade. continuing anyways
ice 0000:13:00.1: ice_init_nvm failed -5
ice 0000:13:00.1: Rebuild failed, unload and reload driver
--- drivers/net/ethernet/intel/ice/ice_vf_lib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_vf_lib.c +6 -1
@@ -509,7 +509,12 @@ void ice_reset_all_vfs(struct ice_pf *pf)ice_vf_ctrl_invalidate_vsi (vf);ice_vf_pre_vsi_rebuild (vf); -ice_vf_rebuild_vsi (vf); +if (ice_vf_rebuild_vsi (vf)) { +dev_err (dev,"VF %u VSI rebuild failed, leaving VF disabled\n" , + vf->vf_id); +mutex_unlock (&vf->cfg_lock); +continue ; + }ice_vf_post_vsi_rebuild (vf);mutex_unlock (&vf->cfg_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 789/969 net: tls: fix strparser anchor skb leak on offload RX setup failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 58689498ca3384851145a754dbb1d8ed1cf9fb54 ]
When tls_set_device_offload_rx() fails at tls_dev_add(), the error path calls tls_sw_free_resources_rx() to clean up the SW context that was initialized by tls_set_sw_offload(). This function calls tls_sw_release_resources_rx() (which stops the strparser via tls_strp_stop()) and tls_sw_free_ctx_rx() (which kfrees the context), but never frees the anchor skb that was allocated by alloc_skb(0) in tls_strp_init().
Note that tls_sw_free_resources_rx() is exclusively used for this "failed to start offload" code path, there's no other caller.
The leak did not exist before commit 84c61fe1a75b ("tls: rx: do not use the standard strparser"), because the standard strparser doesn't try to pre-allocate an skb.
The normal close path in tls_sk_proto_close() handles cleanup by calling tls_sw_strparser_done() (which calls tls_strp_done()) after dropping the socket lock, because tls_strp_done() does cancel_work_sync() and the strparser work handler takes the socket lock.
--- net/tls/tls.h | 1 + net/tls/tls_strp.c | 6 ++++++ net/tls/tls_sw.c | 4 ++++ 3 files changed, 11 insertions(+)
net/tls/tls.h +1 -0
@@ -136,6 +136,7 @@ int tls_strp_dev_init(void);void tls_strp_dev_exit (void );void tls_strp_done (struct tls_strparser *strp); +void __tls_strp_done (struct tls_strparser *strp);void tls_strp_stop (struct tls_strparser *strp);int tls_strp_init (struct tls_strparser *strp,struct sock *sk);void tls_strp_data_ready (struct tls_strparser *strp);
net/tls/tls_strp.c +6 -0
@@ -619,6 +619,12 @@ void tls_strp_done(struct tls_strparser *strp)WARN_ON (!strp->stopped);cancel_work_sync (&strp->work); +__tls_strp_done (strp); +} + +/* For setup error paths where the strparser was initialized but never armed. */ +void __tls_strp_done (struct tls_strparser *strp) +{tls_strp_anchor_free (strp); }
net/tls/tls_sw.c +4 -0
@@ -2584,8 +2584,12 @@ void tls_sw_free_ctx_rx(struct tls_context *tls_ctx)void tls_sw_free_resources_rx (struct sock *sk) {struct tls_context *tls_ctx =tls_get_ctx (sk); +struct tls_sw_context_rx *ctx; + + ctx =tls_sw_ctx_rx (tls_ctx);tls_sw_release_resources_rx (sk); +__tls_strp_done (&ctx->strp);tls_sw_free_ctx_rx (tls_ctx); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 790/969 net/sched: cls_flower: revert unintended changes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit 1e01abec856593e02cd69fd95b784c10dd46880c ]
While applying the blamed commit 4ca07b9239bd ("net: mctp i2c: check length before marking flow active"), I unintentionally included unrelated and unacceptable changes.
Revert them.
--- net/sched/cls_flower.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/sched/cls_flower.c +1 -3
@@ -537,7 +537,6 @@ static int __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f, struct netlink_ext_ack *extack) {struct cls_fl_head *head =fl_head_dereference (tp); -struct fl_flow_mask *mask; *last = false;
@@ -554,12 +553,11 @@ static int __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f,list_del_rcu (&f->list);spin_unlock (&tp->lock); - mask = f->mask; + *last =fl_mask_put (head, f->mask);if (!tc_skip_hw (f->flags))fl_hw_destroy_filter (tp, f, rtnl_held, extack);tcf_unbind_filter (tp, &f->res);__fl_put (f); - *last =fl_mask_put (head, mask);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 791/969 smb: client: correctly handle ErrorContextData as a flexible array
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liang Jie <[email protected]>
[ Upstream commit 215b7f9ecb8d7c14d56febdcdd246f3579c32aba ]
The smb2_symlink_err_rsp structure was previously defined with ErrorContextData as a single __u8 byte. However, the ErrorContextData field is intended to be a variable-length array based on ErrorDataLength. This mismatch leads to incorrect pointer arithmetic and potential memory access issues when processing error contexts.
Updates the ErrorContextData field to be a flexible array (__u8 ErrorContextData[]). Additionally, it modifies the corresponding casts in the symlink_data() function to properly handle the flexible array, ensuring correct memory calculations and data handling.
These changes improve the robustness of SMB2 symlink error processing.
--- fs/smb/client/smb2file.c | 4 ++-- fs/smb/client/smb2pdu.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/smb/client/smb2file.c +2 -2
@@ -41,14 +41,14 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov) end = (struct smb2_error_context_rsp *)((u8 *)err + iov->iov_len);do {if (le32_to_cpu (p->ErrorId) ==SMB2_ERROR_ID_DEFAULT ) { - sym = (struct smb2_symlink_err_rsp *)&p->ErrorContextData; + sym = (struct smb2_symlink_err_rsp *)p->ErrorContextData;break ; }cifs_dbg (FYI ,"%s: skipping unhandled error context: 0x%x\n" , __func__,le32_to_cpu (p->ErrorId)); len =ALIGN (le32_to_cpu (p->ErrorDataLength),8 ); - p = (struct smb2_error_context_rsp *)((u8 *)&p->ErrorContextData + len); + p = (struct smb2_error_context_rsp *)(p->ErrorContextData + len); }while (p < end); }else if (le32_to_cpu (err->ByteCount) >=sizeof (*sym) && iov->iov_len >=SMB2_SYMLINK_STRUCT_SIZE ) {
fs/smb/client/smb2pdu.h +1 -1
@@ -79,7 +79,7 @@ struct smb2_symlink_err_rsp {struct smb2_error_context_rsp {__le32 ErrorDataLength;__le32 ErrorId; -__u8 ErrorContextData;/* ErrorDataLength long array */ +__u8 ErrorContextData[]; } __packed;/* ErrorId values */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 792/969 smb: client: fix OOB reads parsing symlink error response
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit 3df690bba28edec865cf7190be10708ad0ddd67e ]
When a CREATE returns STATUS_STOPPED_ON_SYMLINK, smb2_check_message() returns success without any length validation, leaving the symlink parsers as the only defense against an untrusted server.
symlink_data() walks SMB 3.1.1 error contexts with the loop test "p < end", but reads p->ErrorId at offset 4 and p->ErrorDataLength at offset
0. When the server-controlled ErrorDataLength advances p to within 1-7 bytes of end, the next iteration will read past it. When the matching context is found, sym->SymLinkErrorTag is read at offset 4 from p->ErrorContextData with no check that the symlink header itself fits.
smb2_parse_symlink_response() then bounds-checks the substitute name using SMB2_SYMLINK_STRUCT_SIZE as the offset of PathBuffer from iov_base. That value is computed as sizeof(smb2_err_rsp) + sizeof(smb2_symlink_err_rsp), which is correct only when ErrorContextCount == 0.
With at least one error context the symlink data sits 8 bytes deeper, and each skipped non-matching context shifts it further by 8 + ALIGN(ErrorDataLength, 8). The check is too short, allowing the substitute name read to run past iov_len. The out-of-bound heap bytes are UTF-16-decoded into the symlink target and returned to userspace via readlink(2).
Fix this all up by making the loops test require the full context header to fit, rejecting sym if its header runs past end, and bound the substitute name against the actual position of sym->PathBuffer rather than a fixed offset.
Because sub_offs and sub_len are 16bits, the pointer math will not overflow here with the new greater-than.
--- fs/smb/client/smb2file.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
fs/smb/client/smb2file.c +12 -8
@@ -26,10 +26,11 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov) {struct smb2_err_rsp *err = iov->iov_base;struct smb2_symlink_err_rsp *sym =ERR_PTR (-EINVAL ); +u8 *end = (u8 *)err + iov->iov_len;u32 len;if (err->ErrorContextCount) { -struct smb2_error_context_rsp *p, *end; +struct smb2_error_context_rsp *p; len = (u32)err->ErrorContextCount * (offsetof(struct smb2_error_context_rsp, ErrorContextData) +
@@ -38,8 +39,7 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov)return ERR_PTR (-EINVAL ); p = (struct smb2_error_context_rsp *)err->ErrorData; - end = (struct smb2_error_context_rsp *)((u8 *)err + iov->iov_len); - do { +while ((u8 *)p +sizeof (*p) <= end) {if (le32_to_cpu (p->ErrorId) ==SMB2_ERROR_ID_DEFAULT ) { sym = (struct smb2_symlink_err_rsp *)p->ErrorContextData;break ;
@@ -49,14 +49,16 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov) len =ALIGN (le32_to_cpu (p->ErrorDataLength),8 ); p = (struct smb2_error_context_rsp *)(p->ErrorContextData + len); - }while (p < end); + } }else if (le32_to_cpu (err->ByteCount) >=sizeof (*sym) && iov->iov_len >=SMB2_SYMLINK_STRUCT_SIZE ) { sym = (struct smb2_symlink_err_rsp *)err->ErrorData; } -if (!IS_ERR (sym) && (le32_to_cpu (sym->SymLinkErrorTag) !=SYMLINK_ERROR_TAG || -le32_to_cpu (sym->ReparseTag) !=IO_REPARSE_TAG_SYMLINK )) +if (!IS_ERR (sym) && + ((u8 *)sym +sizeof (*sym) > end || +le32_to_cpu (sym->SymLinkErrorTag) !=SYMLINK_ERROR_TAG || +le32_to_cpu (sym->ReparseTag) !=IO_REPARSE_TAG_SYMLINK )) sym =ERR_PTR (-EINVAL );return sym;
@@ -81,8 +83,10 @@ int smb2_parse_symlink_response(struct cifs_sb_info *cifs_sb, const struct kvec print_len =le16_to_cpu (sym->PrintNameLength); print_offs =le16_to_cpu (sym->PrintNameOffset); -if (iov->iov_len <SMB2_SYMLINK_STRUCT_SIZE + sub_offs + sub_len || - iov->iov_len <SMB2_SYMLINK_STRUCT_SIZE + print_offs + print_len) +if ((char *)sym->PathBuffer + sub_offs + sub_len > + (char *)iov->iov_base + iov->iov_len || + (char *)sym->PathBuffer + print_offs + print_len > + (char *)iov->iov_base + iov->iov_len)return -EINVAL ; s = cifs_strndup_from_utf16((char *)sym->PathBuffer + sub_offs, sub_len, true,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 793/969 net/sched: sch_pie: annotate more data-races in pie_dump_stats()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 6d4106e8df94c0c52cf3ca6a6a0d01567fb3844e ]
My prior patch missed few READ_ONCE()/WRITE_ONCE() annotations.
--- net/sched/sch_pie.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
net/sched/sch_pie.c +6 -8
@@ -212,16 +212,14 @@ void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params,* packet timestamp. */ if (!params->dq_rate_estimator) { - vars->qdelay = now -pie_get_enqueue_time (skb); +WRITE_ONCE (vars->qdelay, + backlog ? now -pie_get_enqueue_time (skb) :0 );if (vars->dq_tstamp !=DTIME_INVALID ) dtime = now - vars->dq_tstamp; vars->dq_tstamp = now; -if (backlog ==0 ) - vars->qdelay =0 ; -if (dtime ==0 )return ;
@@ -369,7 +367,7 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,if (qdelay > (PSCHED_NS2TICKS (250 *NSEC_PER_MSEC ))) delta +=MAX_PROB / (100 /2 ); - vars->prob += delta; +WRITE_ONCE (vars->prob, vars->prob + delta);if (delta >0 ) {/* prevent overflow */
@@ -394,7 +392,7 @@ void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars,if (qdelay ==0 && qdelay_old ==0 && update_prob)/* Reduce drop probability to 98.4% */ - vars->prob -= vars->prob /64 ; +WRITE_ONCE (vars->prob, vars->prob - vars->prob /64 );WRITE_ONCE (vars->qdelay, qdelay); vars->backlog_old = backlog;
@@ -493,7 +491,7 @@ static int pie_dump_stats(struct Qdisc *sch, struct gnet_dump *d) {struct pie_sched_data *q =qdisc_priv (sch);struct tc_pie_xstats st = { - .prob = q->vars.prob <<BITS_PER_BYTE , + .prob =READ_ONCE (q->vars.prob) <<BITS_PER_BYTE , .delay = ((u32 )PSCHED_TICKS2NS (READ_ONCE (q->vars.qdelay))) /NSEC_PER_USEC , .packets_in =READ_ONCE (q->stats.packets_in),
@@ -504,7 +502,7 @@ static int pie_dump_stats(struct Qdisc *sch, struct gnet_dump *d) };/* avg_dq_rate is only valid if dq_rate_estimator is enabled */ - st.dq_rate_estimating = q->params.dq_rate_estimator; + st.dq_rate_estimating =READ_ONCE (q->params.dq_rate_estimator);/* unscale and return dq_rate in bytes per sec */ if (st.dq_rate_estimating)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 794/969 net: bcmgenet: Initialize u64 stats seq counter
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryo Takakura <[email protected]>
[ Upstream commit ffc2c8c4a714df53a715827d6334ab9474424f6a ]
Initialize u64 stats as it uses seq counter on 32bit machines as suggested by lockdep below.
[ 1.830953][ T1] INFO: trying to register non-static key. [ 1.830993][ T1] The code is fine but needs lockdep annotation, or maybe [ 1.831027][ T1] you didn't initialize this object before use? [ 1.831057][ T1] turning off the locking correctness validator. [ 1.831090][ T1] CPU: 1 UID: 0 PID: 1 Comm: swapper/0 Tainted: G W 6.16.0-rc2-v7l+ #1 PREEMPT [ 1.831097][ T1] Tainted: [W]=WARN [ 1.831099][ T1] Hardware name: BCM2711 [ 1.831101][ T1] Call trace: [ 1.831104][ T1] unwind_backtrace from show_stack+0x18/0x1c [ 1.831120][ T1] show_stack from dump_stack_lvl+0x8c/0xcc [ 1.831129][ T1] dump_stack_lvl from register_lock_class+0x9e8/0x9fc [ 1.831141][ T1] register_lock_class from __lock_acquire+0x420/0x22c0 [ 1.831154][ T1] __lock_acquire from lock_acquire+0x130/0x3f8 [ 1.831166][ T1] lock_acquire from bcmgenet_get_stats64+0x4a4/0x4c8 [ 1.831176][ T1] bcmgenet_get_stats64 from dev_get_stats+0x4c/0x408 [ 1.831184][ T1] dev_get_stats from rtnl_fill_stats+0x38/0x120 [ 1.831193][ T1] rtnl_fill_stats from rtnl_fill_ifinfo+0x7f8/0x1890 [ 1.831203][ T1] rtnl_fill_ifinfo from rtmsg_ifinfo_build_skb+0xd0/0x138 [ 1.831214][ T1] rtmsg_ifinfo_build_skb from rtmsg_ifinfo+0x48/0x8c [ 1.831225][ T1] rtmsg_ifinfo from register_netdevice+0x8c0/0x95c [ 1.831237][ T1] register_netdevice from register_netdev+0x28/0x40 [ 1.831247][ T1] register_netdev from bcmgenet_probe+0x690/0x6bc [ 1.831255][ T1] bcmgenet_probe from platform_probe+0x64/0xbc [ 1.831263][ T1] platform_probe from really_probe+0xd0/0x2d4 [ 1.831269][ T1] really_probe from __driver_probe_device+0x90/0x1a4 [ 1.831273][ T1] __driver_probe_device from driver_probe_device+0x38/0x11c [ 1.831278][ T1] driver_probe_device from __driver_attach+0x9c/0x18c [ 1.831282][ T1] __driver_attach from bus_for_each_dev+0x84/0xd4 [ 1.831291][ T1] bus_for_each_dev from bus_add_driver+0xd4/0x1f4 [ 1.831303][ T1] bus_add_driver from driver_register+0x88/0x120 [ 1.831312][ T1] driver_register from do_one_initcall+0x78/0x360 [ 1.831320][ T1] do_one_initcall from kernel_init_freeable+0x2bc/0x314 [ 1.831331][ T1] kernel_init_freeable from kernel_init+0x1c/0x144 [ 1.831339][ T1] kernel_init from ret_from_fork+0x14/0x20 [ 1.831344][ T1] Exception stack(0xf082dfb0 to 0xf082dff8) [ 1.831349][ T1] dfa0: 00000000 00000000 00000000 00000000 [ 1.831353][ T1] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 1.831356][ T1] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +6 -0
@@ -4079,6 +4079,12 @@ static int bcmgenet_probe(struct platform_device *pdev)for (i =0 ; i <= priv->hw_params->rx_queues; i++) priv->rx_rings[i].rx_max_coalesced_frames =1 ; +/* Initialize u64 stats seq counter for 32bit machines */ +for (i =0 ; i <= priv->hw_params->rx_queues; i++) +u64_stats_init (&priv->rx_rings[i].stats64.syncp); +for (i =0 ; i <= priv->hw_params->tx_queues; i++) +u64_stats_init (&priv->tx_rings[i].stats64.syncp); +/* libphy will determine the link state */ netif_carrier_off (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 795/969 net: bcmgenet: fix leaking free_bds
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Chen <[email protected]>
[ Upstream commit 3f3168300efb839028328d720ab3962f91d6a0d0 ]
While reclaiming the tx queue we fast forward the write pointer to drop any data in flight. These dropped frames are not added back to the pool of free bds. We also need to tell the netdev that we are dropping said data.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +2 -0
@@ -1937,6 +1937,7 @@ static unsigned int bcmgenet_tx_reclaim(struct net_device *dev, drop = (ring->prod_index - ring->c_index) &DMA_C_INDEX_MASK ; released += drop; ring->prod_index = ring->c_index &DMA_C_INDEX_MASK ; + ring->free_bds += drop;while (drop--) { cb_ptr =bcmgenet_put_txcb (priv, ring); skb = cb_ptr->skb;
@@ -1948,6 +1949,7 @@ static unsigned int bcmgenet_tx_reclaim(struct net_device *dev, }if (skb)dev_consume_skb_any (skb); +netdev_tx_reset_queue (netdev_get_tx_queue (dev, ring->index));bcmgenet_tdma_ring_writel (priv, ring->index, ring->prod_index,TDMA_PROD_INDEX ); wr_ptr = ring->write_ptr *WORDS_PER_BD (priv);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 796/969 btrfs: tracepoints: fix sleep while in atomic context in btrfs_sync_file()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit c73370c677646e86fc4b1780fb07027bdf847375 ]
The trace event btrfs_sync_file() is called in an atomic context (all trace events are) and its call to dput(), which is needed due to the call to dget_parent(), can sleep, triggering a kernel splat.
This can be reproduced by enabling the trace event and running btrfs/056 from fstests for example. The splat shown in dmesg is the following:
[53.919] BUG: sleeping function called from invalid context at fs/dcache.c:970 [53.947] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 32773, name: xfs_io [53.988] preempt_count: 2, expected: 0 [53.967] RCU nest depth: 0, expected: 0 [53.943] Preemption disabled at: [53.944] [<0000000000000000>] 0x0 [54.078] CPU: 0 UID: 0 PID: 32773 Comm: xfs_io Tainted: G W 7.1.0-rc1-btrfs-next-232+ #1 PREEMPT(full) [54.070] Tainted: [W]=WARN [54.071] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org 04/01/2014 [54.072] Call Trace: [54.074] <TASK> [54.076] dump_stack_lvl+0x56/0x80 [54.079] __might_resched.cold+0xd6/0x10f [54.072] dput.part.0+0x24/0x110 [54.078] trace_event_raw_event_btrfs_sync_file+0x75/0x140 [btrfs] [54.089] btrfs_sync_file+0x1ed/0x530 [btrfs] [54.087] ? __handle_mm_fault+0x8ae/0xed0 [54.089] btrfs_do_write_iter+0x172/0x210 [btrfs] [54.091] vfs_write+0x21f/0x450 [54.094] __x64_sys_pwrite64+0x8d/0xc0 [54.096] ? do_user_addr_fault+0x20c/0x670 [54.099] do_syscall_64+0x60/0xf20 [54.092] ? clear_bhb_loop+0x60/0xb0 [54.094] entry_SYSCALL_64_after_hwframe+0x76/0x7e
So stop using dget_parent() and dput() and access the parent dentry directly as dentry->d_parent. This is also what ext4 is doing in its equivalent trace event ext4_sync_file_enter().
--- include/trace/events/btrfs.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
include/trace/events/btrfs.h +1 -3
@@ -762,10 +762,8 @@ TRACE_EVENT(btrfs_sync_file,TP_fast_assign ( struct dentry *dentry = file_dentry(file);struct inode *inode =file_inode (file); -struct dentry *parent =dget_parent (dentry); -struct inode *parent_inode =d_inode (parent); +struct inode *parent_inode =d_inode (dentry->d_parent); -dput (parent);TP_fast_assign_fsid (btrfs_sb (inode->i_sb)); __entry->ino =btrfs_ino (BTRFS_I (inode)); __entry->parent =btrfs_ino (BTRFS_I (parent_inode));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 797/969 ALSA: misc: Use guard() for spin locks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit b8e1684163ae52db90f428965bd9aaff7205c02e ]
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Stable-dep-of: 5337213381df ("ALSA: core: Serialize deferred fasync state checks")
--- sound/core/misc.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
sound/core/misc.c +10 -15
@@ -202,35 +202,30 @@ int snd_fasync_helper(int fd, struct file *file, int on,INIT_LIST_HEAD (&fasync->list); } -spin_lock_irq (&snd_fasync_lock); -if (*fasyncp) { -kfree (fasync); - fasync = *fasyncp; - }else { -if (!fasync) { -spin_unlock_irq (&snd_fasync_lock); -return 0 ; + scoped_guard(spinlock_irq, &snd_fasync_lock) { +if (*fasyncp) { +kfree (fasync); + fasync = *fasyncp; + }else { +if (!fasync) +return 0 ; + *fasyncp = fasync; } - *fasyncp = fasync; + fasync->on = on; } - fasync->on = on; -spin_unlock_irq (&snd_fasync_lock);return fasync_helper (fd, file, on, &fasync->fasync); }EXPORT_SYMBOL_GPL (snd_fasync_helper);void snd_kill_fasync (struct snd_fasync *fasync,int signal,int poll) { -unsigned long flags; -if (!fasync || !fasync->on)return ; -spin_lock_irqsave (&snd_fasync_lock, flags); +guard (spinlock_irqsave)(&snd_fasync_lock); fasync->signal = signal; fasync->poll = poll;list_move (&fasync->list, &snd_fasync_list);schedule_work (&snd_fasync_work); -spin_unlock_irqrestore (&snd_fasync_lock, flags); }EXPORT_SYMBOL_GPL (snd_kill_fasync);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 798/969 ALSA: core: Serialize deferred fasync state checks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cássio Gabriel <[email protected]>
[ Upstream commit 5337213381df578058e2e41da93cbd0e4639935f ]
snd_fasync_helper() updates fasync->on under snd_fasync_lock, and snd_fasync_work_fn() now also evaluates fasync->on under the same lock. snd_kill_fasync() still tests the flag before taking the lock, leaving an unsynchronized read against FASYNC enable/disable updates.
Move the enabled-state check into the locked section.
Also clear fasync->on under snd_fasync_lock in snd_fasync_free() before unlinking the pending entry. Together with the locked sender-side check, this publishes teardown before flushing the deferred work and prevents a racing sender from requeueing the entry after free has started.
--- sound/core/misc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
sound/core/misc.c +6 -2
@@ -219,9 +219,11 @@ EXPORT_SYMBOL_GPL(snd_fasync_helper);void snd_kill_fasync (struct snd_fasync *fasync,int signal,int poll) { -if (!fasync || !fasync->on) +if (!fasync)return ;guard (spinlock_irqsave)(&snd_fasync_lock); +if (!fasync->on) +return ; fasync->signal = signal; fasync->poll = poll;list_move (&fasync->list, &snd_fasync_list);
@@ -234,8 +236,10 @@ void snd_fasync_free(struct snd_fasync *fasync)if (!fasync)return ; - scoped_guard(spinlock_irq, &snd_fasync_lock) + scoped_guard(spinlock_irq, &snd_fasync_lock) { + fasync->on =0 ;list_del_init (&fasync->list); + }flush_work (&snd_fasync_work);kfree (fasync);
Signature · 1 line
2.53.0