Skip to content

Commit 6edd78a

Browse files
amkgiummakynes
authored andcommitted
netfilter: nft_exthdr: fix offset with ipv4_find_option()
There is an incorrect calculation in the offset variable which causes the nft_skb_copy_to_reg() function to always return -EFAULT. Adding the start variable is redundant. In the __ip_options_compile() function the correct offset is specified when finding the function. There is no need to add the size of the iphdr structure to the offset. Fixes: dbb5281 ("netfilter: nf_tables: add support for matching IPv4 options") Signed-off-by: Alexey Kashavkin <akashavkin@gmail.com> Reviewed-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 80b78c3 commit 6edd78a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

net/netfilter/nft_exthdr.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,13 @@ static int ipv4_find_option(struct net *net, struct sk_buff *skb,
8585
unsigned char optbuf[sizeof(struct ip_options) + 40];
8686
struct ip_options *opt = (struct ip_options *)optbuf;
8787
struct iphdr *iph, _iph;
88-
unsigned int start;
8988
bool found = false;
9089
__be32 info;
9190
int optlen;
9291

9392
iph = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
9493
if (!iph)
9594
return -EBADMSG;
96-
start = sizeof(struct iphdr);
9795

9896
optlen = iph->ihl * 4 - (int)sizeof(struct iphdr);
9997
if (optlen <= 0)
@@ -103,7 +101,7 @@ static int ipv4_find_option(struct net *net, struct sk_buff *skb,
103101
/* Copy the options since __ip_options_compile() modifies
104102
* the options.
105103
*/
106-
if (skb_copy_bits(skb, start, opt->__data, optlen))
104+
if (skb_copy_bits(skb, sizeof(struct iphdr), opt->__data, optlen))
107105
return -EBADMSG;
108106
opt->optlen = optlen;
109107

@@ -118,18 +116,18 @@ static int ipv4_find_option(struct net *net, struct sk_buff *skb,
118116
found = target == IPOPT_SSRR ? opt->is_strictroute :
119117
!opt->is_strictroute;
120118
if (found)
121-
*offset = opt->srr + start;
119+
*offset = opt->srr;
122120
break;
123121
case IPOPT_RR:
124122
if (!opt->rr)
125123
break;
126-
*offset = opt->rr + start;
124+
*offset = opt->rr;
127125
found = true;
128126
break;
129127
case IPOPT_RA:
130128
if (!opt->router_alert)
131129
break;
132-
*offset = opt->router_alert + start;
130+
*offset = opt->router_alert;
133131
found = true;
134132
break;
135133
default:

0 commit comments

Comments
 (0)