2022-05-08 19:06:40

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [PATCH RFC v1 net-next 1/4] net: Introduce Qdisc backpressure infrastructure

On Fri, 6 May 2022 12:44:22 -0700
Peilin Ye <[email protected]> wrote:

> +static inline void qdisc_backpressure_overlimit(struct Qdisc *sch, struct sk_buff *skb)
> +{
> + struct sock *sk = skb->sk;
> +
> + if (!sk || !sk_fullsock(sk))
> + return;
> +
> + if (cmpxchg(&sk->sk_backpressure_status, SK_UNTHROTTLED, SK_OVERLIMIT) == SK_UNTHROTTLED) {
> + sock_hold(sk);
> + list_add_tail(&sk->sk_backpressure_node, &sch->backpressure_list);
> + }
> +}

What if socket is closed? You are holding reference but application maybe gone.

Or if output is stalled indefinitely?


2022-05-09 04:38:23

by Peilin Ye

[permalink] [raw]
Subject: Re: [PATCH RFC v1 net-next 1/4] net: Introduce Qdisc backpressure infrastructure

Hi Stephen,

On Fri, May 06, 2022 at 01:31:11PM -0700, Stephen Hemminger wrote:
> On Fri, 6 May 2022 12:44:22 -0700, Peilin Ye <[email protected]> wrote:
> > +static inline void qdisc_backpressure_overlimit(struct Qdisc *sch, struct sk_buff *skb)
> > +{
> > + struct sock *sk = skb->sk;
> > +
> > + if (!sk || !sk_fullsock(sk))
> > + return;
> > +
> > + if (cmpxchg(&sk->sk_backpressure_status, SK_UNTHROTTLED, SK_OVERLIMIT) == SK_UNTHROTTLED) {
> > + sock_hold(sk);
> > + list_add_tail(&sk->sk_backpressure_node, &sch->backpressure_list);
> > + }
> > +}
>
> What if socket is closed? You are holding reference but application maybe gone.

Thanks for pointing this out! I just understood how sk_refcnt works
together with sk_wmem_alloc.

By the time we process this in-flight skb, sk_refcnt may have already
reached 0, which means sk_free() may have already decreased that "extra" 1
sk_wmem_alloc, so skb->destructor() may call __sk_free() while I "hold"
the sock here. Seems like a UAF.

> Or if output is stalled indefinitely?

It would be better to do a cleanup in sock destroying code, but I am
trying to avoid acquiring Qdisc root_lock there. I will try to come up
with a better solution.

Thanks,
Peilin Ye