Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2708170pxj; Mon, 31 May 2021 08:45:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYG/D4qpAGB3cGy6eNSdiAAGN+WfAmpofZClKH2If5wy42GyL4SkiQX3ipnbwc+EzRG4s5 X-Received: by 2002:a6b:b214:: with SMTP id b20mr1304585iof.199.1622475936943; Mon, 31 May 2021 08:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475936; cv=none; d=google.com; s=arc-20160816; b=YQCsFaTN2OXGgLbMzajywn9sx45o7st0zFsrlwQcAOO/oLopF9kumQrkcM5zKEto5A 6OZJf36QNObxjY9JZH7zqUCV89OR7BVD1jWAjttrciSQY88kbDUG3//MIWfdZSB0hjEr tOtpUArAe1NYGHHRl/DKBtuAeFREL2yQj2Yk5qBPkHaekRI+pd+IvnSdCHehalOaPoaC 0Ufa+U76MKPRVa7wvcS0ezEVbZwBYtfKe8QTjND1BK5fO4CLBcTUFqGkNqkdmH2Idysa VOZ22nnLOzKApyZNE/I/geVg6/XIqoU3DhnYsv357yNvbOg5OWDT7D4VftDumIhTy0Va BZUQ== 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=EEkoGCc/YiFRExKt0FNVfqPh8oIA7eubM0zohgUQoAw=; b=w2QrylvEqHsWzzxyoWtJ98J/P8cwIHb5YR6UPdeCU9DdJ9FfVHBCN2TUwCy7qjPBZl y7pLKFWUNPw4HvwHHMgRnQg5iMYf3COCyuq80/CCjld4AnDQbtDr7xPndnGSfwQR8va2 d0+xK3g4GPQnuBX7z6kl124fJCDjCnLliZyVSJJ5lM1zvSznm8QauvpsoSi9tPwqY/L1 ZAUCQnjOn8tqQcdTzSVR/ZmsgKlyPXtE8sVp/I7XImE1D/NsSkX14nQ+2rwOh7ZNgTRa JbVbU94BSBVq3shmT+7v/gfoS6ZvOFslq8onTx6jtn0gF+nDFYXdb3zWAyrSgGFSQrks xM5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wy8+Ogpe; 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 l11si15657842jaj.50.2021.05.31.08.45.23; Mon, 31 May 2021 08:45:36 -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=Wy8+Ogpe; 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 S230382AbhEaPqc (ORCPT + 99 others); Mon, 31 May 2021 11:46:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:54710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233877AbhEaOZe (ORCPT ); Mon, 31 May 2021 10:25:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BB6D861582; Mon, 31 May 2021 13:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468813; bh=uuSa62LUBG+sg8P1mQOXGE60OHymgz7NnUAAnjDaNZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wy8+OgpeNHOEOFRpIrpSBtGAdrRkxOvvF/LQS7F5hsjS0SjSTKrIhuZQqKC9bhZxh PQjidz3xSd37muNBLsJEL3XtjepxXtW+uGindW9gnHsi8FpVPMRMfik+KDM9rtChW4 s9cTa1xpWqP6Egc80EzCEcbdw6QKzds4SlW39tgQ= 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.4 139/177] net: really orphan skbs tied to closing sk Date: Mon, 31 May 2021 15:14:56 +0200 Message-Id: <20210531130652.738472172@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 4137fa178790..a0728f24ecc5 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2150,13 +2150,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 19c178aac0ae..68f84fac63e0 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2026,10 +2026,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