提交 c8926713 编写于 作者: X Xin Long 提交者: Zheng Zengkai

tipc: do not write skb_shinfo frags when doing decrytion

stable inclusion
from stable-5.10.56
commit 4951ffa3fac8892949a09b630191ff12f35f4b72
bugzilla: 176004 https://gitee.com/openeuler/kernel/issues/I4DYZ4

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4951ffa3fac8892949a09b630191ff12f35f4b72

--------------------------------

[ Upstream commit 3cf4375a ]

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: fc1b6d6d ("tipc: introduce TIPC encryption & authentication")
Reported-by: NShuang Li <shuali@redhat.com>
Signed-off-by: NXin Long <lucien.xin@gmail.com>
Acked-by: NJon Maloy <jmaloy@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 d06db05a
...@@ -891,17 +891,11 @@ static int tipc_aead_decrypt(struct net *net, struct tipc_aead *aead, ...@@ -891,17 +891,11 @@ static int tipc_aead_decrypt(struct net *net, struct tipc_aead *aead,
if (unlikely(!aead)) if (unlikely(!aead))
return -ENOKEY; 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); nsg = skb_cow_data(skb, 0, &unused);
if (unlikely(nsg < 0)) { if (unlikely(nsg < 0)) {
pr_err("RX: skb_cow_data() returned %d\n", nsg); pr_err("RX: skb_cow_data() returned %d\n", nsg);
return nsg; return nsg;
} }
}
/* Allocate memory for the AEAD operation */ /* Allocate memory for the AEAD operation */
tfm = tipc_aead_tfm_next(aead); tfm = tipc_aead_tfm_next(aead);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册