Skip to content

Commit 28427f3

Browse files
leonshawummakynes
authored andcommitted
netfilter: nft_exthdr: Fix non-linear header modification
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: [email protected] Signed-off-by: Xiao Liang <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent bd6c11b commit 28427f3

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

net/netfilter/nft_exthdr.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,
238238
if (!tcph)
239239
goto err;
240240

241+
if (skb_ensure_writable(pkt->skb, nft_thoff(pkt) + tcphdr_len))
242+
goto err;
243+
244+
tcph = (struct tcphdr *)(pkt->skb->data + nft_thoff(pkt));
241245
opt = (u8 *)tcph;
246+
242247
for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) {
243248
union {
244249
__be16 v16;
@@ -253,15 +258,6 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,
253258
if (i + optl > tcphdr_len || priv->len + priv->offset > optl)
254259
goto err;
255260

256-
if (skb_ensure_writable(pkt->skb,
257-
nft_thoff(pkt) + i + priv->len))
258-
goto err;
259-
260-
tcph = nft_tcp_header_pointer(pkt, sizeof(buff), buff,
261-
&tcphdr_len);
262-
if (!tcph)
263-
goto err;
264-
265261
offset = i + priv->offset;
266262

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

328-
opt = (u8 *)nft_tcp_header_pointer(pkt, sizeof(buff), buff, &tcphdr_len);
329-
if (!opt)
330-
goto err;
324+
tcph = (struct tcphdr *)(pkt->skb->data + nft_thoff(pkt));
325+
opt = (u8 *)tcph;
326+
331327
for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) {
332328
unsigned int j;
333329

0 commit comments

Comments
 (0)