Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1647567pxy; Mon, 2 Aug 2021 07:02:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl5HRc6Bzvozyltdrw5H13nzGpl4xANXi7tbjVNCLok8KcC8pKpBls5YnYLTUqQNjCfvGj X-Received: by 2002:a5e:c311:: with SMTP id a17mr1311284iok.22.1627912965864; Mon, 02 Aug 2021 07:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627912965; cv=none; d=google.com; s=arc-20160816; b=ytp/9UW94a2TRUWLhHJX2yDyYspYwQ09mVq/dtKTbRSO6H0v0uJmbf2SCysIkEKJYx E+4QIxsXAPu7P/LoVrxN3+F02XVdqjU366BfmNB6U4fXhG4HPABBT6H0YC3L1REdOUQ1 aIaPgyP2UCHEUlR9YsLe2349+0ATspQKGTKBTpnzU9P/2dgPZJ797xdMioikw7GZ/Hhg AVYnz03meIEhv3bpi9l1oiNBJ556UYCQcSWq6rTs22AWRwVN8y/TB+30+xglZ9kl8ITw +weRSxoez+R3Sd0jkSRcbc9wemnTvbUUWtlu0egxmHk4x30hb97mLvWFsvfHl62A22fx hk7w== 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=UV9ANU7Qqf8PPFHCiiE09SHBHkCvY6qGco89lDBg9ZU=; b=bI3IT3i0uaoDEAC3avw/7LC/L+YeTKmTZDQce9gFZfq/RzpZ494eNjnnt/J9W4MgKm aBP7EbRgj+snvvWD/+f6cx6qHZ3Ck9JQayS2f0+g9dpXORk7iuevKoUdiVAY9kR3yMls X2c4ore3qN9mYvTKx/uyQagv/gSVZAMMWhCkQgg4RYo891+G8H4rhzrF5JN82Qk/vQTa vaFnGVqPvhgXf7tdkkdjUPR4u5tJmeXf9cptQ3ZeZjfarsT6HFYTTNgBaGGOaBkqmLkZ fLzfcHKhfYGjWleCLsA4btRweY3Q5yt/PoRRNU6wqzjr2kzsU2l0wJZ7f0Bs65N4EcMs KN0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jOwVDlJo; 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 y7si11645021ila.59.2021.08.02.07.02.34; Mon, 02 Aug 2021 07:02:45 -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=jOwVDlJo; 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 S234741AbhHBOAw (ORCPT + 99 others); Mon, 2 Aug 2021 10:00:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:40754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236142AbhHBNzA (ORCPT ); Mon, 2 Aug 2021 09:55:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EEA8761181; Mon, 2 Aug 2021 13:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912404; bh=HQxIcOAvhNI2I91G09vCuSLtsqulbba5cNQQCXjJzjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jOwVDlJooSqfRI6GvBOSTS0Njk6A/rL7SoSkD5RnL74TgWPYdadWneJys5piIfyhi sj0J2Vv0Uo86OrNT2OAJFdCZwwomtCVuE1O+IqIXuWynIj1y+7ieuZSMouc0HJrTx9 QOw9q3mlZz26vynsOXurqEv1GolldfC5hu1AyaIw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuang Li , Xin Long , Jon Maloy , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 44/67] tipc: do not write skb_shinfo frags when doing decrytion Date: Mon, 2 Aug 2021 15:45:07 +0200 Message-Id: <20210802134340.523356311@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134339.023067817@linuxfoundation.org> References: <20210802134339.023067817@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: Xin Long [ Upstream commit 3cf4375a090473d240281a0d2b04a3a5aaeac34b ] One skb's skb_shinfo frags are not writable, and they can be shared with other skbs' like by pskb_copy(). To write the frags may cause other skb's data crash. So before doing en/decryption, skb_cow_data() should always be called for a cloned or nonlinear skb if req dst is using the same sg as req src. While at it, the likely branch can be removed, as it will be covered by skb_cow_data(). Note that esp_input() has the same issue, and I will fix it in another patch. tipc_aead_encrypt() doesn't have this issue, as it only processes linear data in the unlikely branch. Fixes: fc1b6d6de220 ("tipc: introduce TIPC encryption & authentication") Reported-by: Shuang Li Signed-off-by: Xin Long Acked-by: Jon Maloy Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/tipc/crypto.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c index 2301b66280de..f8e73c4a0093 100644 --- a/net/tipc/crypto.c +++ b/net/tipc/crypto.c @@ -891,16 +891,10 @@ static int tipc_aead_decrypt(struct net *net, struct tipc_aead *aead, if (unlikely(!aead)) return -ENOKEY; - /* Cow skb data if needed */ - if (likely(!skb_cloned(skb) && - (!skb_is_nonlinear(skb) || !skb_has_frag_list(skb)))) { - nsg = 1 + skb_shinfo(skb)->nr_frags; - } else { - nsg = skb_cow_data(skb, 0, &unused); - if (unlikely(nsg < 0)) { - pr_err("RX: skb_cow_data() returned %d\n", nsg); - return nsg; - } + nsg = skb_cow_data(skb, 0, &unused); + if (unlikely(nsg < 0)) { + pr_err("RX: skb_cow_data() returned %d\n", nsg); + return nsg; } /* Allocate memory for the AEAD operation */ -- 2.30.2