netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf 1/1] netfilter: seqadj: Fix possible non-linear data access for TCP header
@ 2017-04-10 10:36 gfree.wind
  2017-04-10 12:06 ` Pablo Neira Ayuso
  2017-04-13 21:37 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 10+ messages in thread
From: gfree.wind @ 2017-04-10 10:36 UTC (permalink / raw)
  To: pablo, netfilter-devel; +Cc: Gao Feng

From: Gao Feng <fgao@ikuai8.com>

The current call path of nf_ct_tcp_seqadj_set is the following.

nfqnl_recv_verdict->ctnetlink_glue_hook->ctnetlink_glue_seqadj
->nf_ct_tcp_seqadj_set.

It couldn't make sure the TCP header is in the linear data part.
So use the skb_header_pointer instead of the current codes.

BTW, the nf_ct_tcp_seqadj_set is one external function of netfilter
which works in the network layer, it should not assume the transport
header is in the linear data.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
 net/netfilter/nf_conntrack_seqadj.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_conntrack_seqadj.c b/net/netfilter/nf_conntrack_seqadj.c
index ef7063e..80394ab 100644
--- a/net/netfilter/nf_conntrack_seqadj.c
+++ b/net/netfilter/nf_conntrack_seqadj.c
@@ -61,11 +61,14 @@ void nf_ct_tcp_seqadj_set(struct sk_buff *skb,
 			  s32 off)
 {
 	const struct tcphdr *th;
+	struct tcphdr tcph;
 
 	if (nf_ct_protonum(ct) != IPPROTO_TCP)
 		return;
 
-	th = (struct tcphdr *)(skb_network_header(skb) + ip_hdrlen(skb));
+	th = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(tcph), &tcph);
+	if (!th)
+		return;
 	nf_ct_seqadj_set(ct, ctinfo, th->seq, off);
 }
 EXPORT_SYMBOL_GPL(nf_ct_tcp_seqadj_set);
-- 
1.9.1





^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-04-13 22:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-10 10:36 [PATCH nf 1/1] netfilter: seqadj: Fix possible non-linear data access for TCP header gfree.wind
2017-04-10 12:06 ` Pablo Neira Ayuso
2017-04-11  0:59   ` 高峰
2017-04-11  2:44   ` Gao Feng
2017-04-11  2:47   ` 高峰
2017-04-11  2:53   ` Gao Feng
2017-04-13 21:37 ` Pablo Neira Ayuso
2017-04-13 21:42   ` Pablo Neira Ayuso
2017-04-13 21:44     ` Pablo Neira Ayuso
2017-04-13 22:17       ` Gao Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).