Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2746798pxj; Mon, 31 May 2021 09:42:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSvJ2/m5T+oaA+dckqU+9O52GdyhR8J3blp4eG9YYSkxKdZKkOEF1Xkcq9z+1TH0L095zE X-Received: by 2002:a05:6638:38a8:: with SMTP id b40mr21430251jav.37.1622479330989; Mon, 31 May 2021 09:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622479330; cv=none; d=google.com; s=arc-20160816; b=g2H4gJ+u26QCDi5PhO0dqI2MiqGHi6safmIV5zVFHK6hjzSfszWeLJriZKyO+cXd8A VOH2dx0WzTUfJAISEHDDxzScEa/+htzeM0qynyBkl374YNwKtvE1uO7a4b9YK9hPPi2Z Ekb18g8oF7V8JgCAt1CA3NX3LfpSzX8UisKQ3wro8ESbXIDJzGF9rcD8abk9L8wE4+p2 lkczZ/hqEevu9EJXph6I9y3h/ZHqK3d0z7y/lI8xLCthDt3me6tnGvq/9tR/efY/GRAr BCloXSJ26yN6hS3uJfxAmU7gl9tlO95RtE6mCK4RaZbebXkEtoEX7cU5oerqPNkir46W DBmg== 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=B4louGi4ZbpIhJmxY59fxhViMVMXt+my5D913ywGvGY=; b=sVzdssIfs+v49tOxUXSp7p6goIO4QLw2pKERfaLr2iiHLMOaOSer2Vp8Gh2bvUCYg8 38ey4TdAMxrP5AbxF8KEOPGRf1FZiCY4krB4CNX0N3cekwv0rK7Jx4HT8Xn91xNu8b+O 2UoPZSwWy16vGAjTfW5sghecJXHuiIEDm6lCcZ35rjJxLvGn8m9cydrlWjbok/N/oHgH 2QerbigtZQFoLDvKCR5ffNpiJyJD0RAUBneWuvkEWx6ZPAVa9DU+Qw84Is0gViMa9DQ9 jSdwwfnTTJpbYhP4+kuqVsaFWXJIJ1/pF8TkIfuL+1aN+hingRN3Cy5UhwYrd8Cic/jx dlMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yO6p8I4Y; 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 r1si10118182iom.52.2021.05.31.09.41.58; Mon, 31 May 2021 09:42:10 -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=yO6p8I4Y; 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 S234049AbhEaQnE (ORCPT + 99 others); Mon, 31 May 2021 12:43:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:47902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234054AbhEaOxR (ORCPT ); Mon, 31 May 2021 10:53:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DBA6F61CB0; Mon, 31 May 2021 13:58:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469527; bh=TH/iVztw0bSKWElDHsp7M5gULAbAxyB6k1D4iKkmr1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yO6p8I4YYI6k29d6wF2vDS0ojCL8SMoLzxDqucdv8EpuYuDOI/vXuXb/n47ZkL68j n56708/bLXQ1O2G76yGbK9JxzO2w2UvGnDe4epc3PzsnHdWTTuEUFON2ogVqxP4zBv oWVnolALo2JOZsGPJXa45MpTzJGSxjhu2J1lvn3U= 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.12 231/296] net: really orphan skbs tied to closing sk Date: Mon, 31 May 2021 15:14:46 +0200 Message-Id: <20210531130711.577587470@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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 8487f58da36d..62e3811e95a7 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2225,13 +2225,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 5ec90f99e102..9c7b143e7a96 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2132,10 +2132,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