Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2680913pxj; Mon, 31 May 2021 08:07:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxD0YCAVtDx0x/wJ9cXi7i/fEKkQc9KS8nE4kktGXT2o9yQLunPmvy1G+zc+sfA9zz3f9Zj X-Received: by 2002:a6b:4105:: with SMTP id n5mr17115462ioa.148.1622473670192; Mon, 31 May 2021 08:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473670; cv=none; d=google.com; s=arc-20160816; b=Gxq8gw8vpXrk/c9n9KDrhFXRQBvmvtVEY9DQecti0Tz3bdchZet+5tJOWV2LDDr9fq Rfb7U705iR41fbkCnW971A/jI0qwIq2JjLrT8R8Yl2cYRwapuij85vhn8sHV+7pR6pOS +AihkdQSS6j51YWPjQ5KwfjEMyj9USLyIj4QBsU8IWJFKzjSfeVT4IVjyneCJFsblSOQ H5u8w/oz1nFGOCKfci8xqnUAMoAqvxjCPUGg9e1hbhHumvCYt0G5AcY7MgUXoZL52ma+ KT209t/MNDe0u4s5XtAjuB+L+oZS2W1sMRk/88FfvzZasuwdmsaFHXQ86CRhCBKRMxTb bsag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=w81XSWO8nQlzH5mRRFxfYVXeV19P1pBXnugCYv2iLbo=; b=n1i+6q4f3slxapffSsq2U817oFEdI705Cmg7Yg5qJO5u9q3n4pdkRG/A4cdFNLZfQG 2KgYkOYb9utmkX0AhM/m8gm8UuU6vwAtZ9T+Hu6+Iu0zUSRhIWccFd5+ONcctjlk9cnU bzhgjMtQmBoHP22mlZ8B9A57LA/6GCJbcZTB4Oib5djbmiKmXxryUEfpag8tsDC3wchd ZKIEZzwKYd9TANE9plBpXCFpQTaNFvpeP2PbZE45tcR54lnTYmCnJQcKokDfUHH39X1+ hOTXebHByUTRN69gyVHsoRj9kijT9oCQvAg7BbHxnqHIcIP/5X3fm6IsJM64Xb7fSY9m fUCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CBOZLmtg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p12si13426388ilq.5.2021.05.31.08.07.36; Mon, 31 May 2021 08:07:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CBOZLmtg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233067AbhEaPIX (ORCPT + 99 others); Mon, 31 May 2021 11:08:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:40220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233480AbhEaOJb (ORCPT ); Mon, 31 May 2021 10:09:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1087A6145F; Mon, 31 May 2021 13:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468413; bh=SUSzlEVEmHgMiHeLtBCO7zpTUDU7+Muby84fd2VYuMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CBOZLmtg77+aGZ8HCA4mDni5wvUBWmotqVff69YCNehnkEEnJyDKfmW+cDxZZ+0HX TWg7YEwFUF6DIsYehuoxD6PBctEYnV3+opfWwXHd5QKQMucdg4QtdjKZ90fUuGzRuK iTLiba2G93bb3A5R9vKx+OtmZw+SaT8z3E55BT8A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Abeni , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 198/252] net: really orphan skbs tied to closing sk Date: Mon, 31 May 2021 15:14:23 +0200 Message-Id: <20210531130704.743041050@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Abeni [ Upstream commit 098116e7e640ba677d9e345cbee83d253c13d556 ] If the owing socket is shutting down - e.g. the sock reference count already dropped to 0 and only sk_wmem_alloc is keeping the sock alive, skb_orphan_partial() becomes a no-op. When forwarding packets over veth with GRO enabled, the above causes refcount errors. This change addresses the issue with a plain skb_orphan() call in the critical scenario. Fixes: 9adc89af724f ("net: let skb_orphan_partial wake-up waiters.") Signed-off-by: Paolo Abeni Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/sock.h | 4 +++- net/core/sock.c | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 261195598df3..f68184b8c0aa 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2197,13 +2197,15 @@ static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk) sk_mem_charge(sk, skb->truesize); } -static inline void skb_set_owner_sk_safe(struct sk_buff *skb, struct sock *sk) +static inline __must_check bool skb_set_owner_sk_safe(struct sk_buff *skb, struct sock *sk) { if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) { skb_orphan(skb); skb->destructor = sock_efree; skb->sk = sk; + return true; } + return false; } void sk_reset_timer(struct sock *sk, struct timer_list *timer, diff --git a/net/core/sock.c b/net/core/sock.c index c75c1e723a84..dee29f41beaf 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2099,10 +2099,10 @@ void skb_orphan_partial(struct sk_buff *skb) if (skb_is_tcp_pure_ack(skb)) return; - if (can_skb_orphan_partial(skb)) - skb_set_owner_sk_safe(skb, skb->sk); - else - skb_orphan(skb); + if (can_skb_orphan_partial(skb) && skb_set_owner_sk_safe(skb, skb->sk)) + return; + + skb_orphan(skb); } EXPORT_SYMBOL(skb_orphan_partial); -- 2.30.2