Skip to content

Commit

Permalink
netfilter: nft_exthdr: Fix non-linear header modification
Browse files Browse the repository at this point in the history
commit 28427f3 upstream.

Fix skb_ensure_writable() size. Don't use nft_tcp_header_pointer() to
make it explicit that pointers point to the packet (not local buffer).

Fixes: 99d1712 ("netfilter: exthdr: tcp option set support")
Fixes: 7890cbe ("netfilter: exthdr: add support for tcp option removal")
Cc: stable@vger.kernel.org
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
leonshaw authored and gregkh committed Sep 13, 2023
1 parent 7ca0706 commit bcdb4a5
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions net/netfilter/nft_exthdr.c
Expand Up @@ -238,7 +238,12 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,
if (!tcph)
goto err;

if (skb_ensure_writable(pkt->skb, nft_thoff(pkt) + tcphdr_len))
goto err;

tcph = (struct tcphdr *)(pkt->skb->data + nft_thoff(pkt));
opt = (u8 *)tcph;

for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) {
union {
__be16 v16;
Expand All @@ -253,15 +258,6 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,
if (i + optl > tcphdr_len || priv->len + priv->offset > optl)
goto err;

if (skb_ensure_writable(pkt->skb,
nft_thoff(pkt) + i + priv->len))
goto err;

tcph = nft_tcp_header_pointer(pkt, sizeof(buff), buff,
&tcphdr_len);
if (!tcph)
goto err;

offset = i + priv->offset;

switch (priv->len) {
Expand Down Expand Up @@ -325,9 +321,9 @@ static void nft_exthdr_tcp_strip_eval(const struct nft_expr *expr,
if (skb_ensure_writable(pkt->skb, nft_thoff(pkt) + tcphdr_len))
goto drop;

opt = (u8 *)nft_tcp_header_pointer(pkt, sizeof(buff), buff, &tcphdr_len);
if (!opt)
goto err;
tcph = (struct tcphdr *)(pkt->skb->data + nft_thoff(pkt));
opt = (u8 *)tcph;

for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) {
unsigned int j;

Expand Down

0 comments on commit bcdb4a5

Please sign in to comment.