Skip to content

Commit c2d27b3

Browse files
ummakynesgregkh
authored andcommitted
netfilter: nfnetlink_cttimeout: pass default timeout policy to obj_to_nlattr
commit 8866df9 upstream Otherwise, we hit a NULL pointer deference since handlers always assume default timeout policy is passed. netlink: 24 bytes leftover after parsing attributes in process `syz-executor2'. kasan: CONFIG_KASAN_INLINE enabled kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] PREEMPT SMP KASAN CPU: 0 PID: 9575 Comm: syz-executor1 Not tainted 4.19.0+ torvalds#312 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:icmp_timeout_obj_to_nlattr+0x77/0x170 net/netfilter/nf_conntrack_proto_icmp.c:297 Fixes: c779e84 ("netfilter: conntrack: remove get_timeout() indirection") Reported-by: Eric Dumazet <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Zubin Mithra <[email protected]> Signed-off-by: Sasha Levin (Microsoft) <[email protected]>
1 parent 564f039 commit c2d27b3

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

net/netfilter/nfnetlink_cttimeout.c

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ static int cttimeout_default_set(struct net *net, struct sock *ctnl,
392392
static int
393393
cttimeout_default_fill_info(struct net *net, struct sk_buff *skb, u32 portid,
394394
u32 seq, u32 type, int event,
395-
const struct nf_conntrack_l4proto *l4proto)
395+
const struct nf_conntrack_l4proto *l4proto,
396+
const unsigned int *timeouts)
396397
{
397398
struct nlmsghdr *nlh;
398399
struct nfgenmsg *nfmsg;
@@ -421,7 +422,7 @@ cttimeout_default_fill_info(struct net *net, struct sk_buff *skb, u32 portid,
421422
if (!nest_parms)
422423
goto nla_put_failure;
423424

424-
ret = l4proto->ctnl_timeout.obj_to_nlattr(skb, NULL);
425+
ret = l4proto->ctnl_timeout.obj_to_nlattr(skb, timeouts);
425426
if (ret < 0)
426427
goto nla_put_failure;
427428

@@ -444,6 +445,7 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl,
444445
struct netlink_ext_ack *extack)
445446
{
446447
const struct nf_conntrack_l4proto *l4proto;
448+
unsigned int *timeouts = NULL;
447449
struct sk_buff *skb2;
448450
int ret, err;
449451
__u16 l3num;
@@ -456,12 +458,44 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl,
456458
l4num = nla_get_u8(cda[CTA_TIMEOUT_L4PROTO]);
457459
l4proto = nf_ct_l4proto_find_get(l3num, l4num);
458460

459-
/* This protocol is not supported, skip. */
460-
if (l4proto->l4proto != l4num) {
461-
err = -EOPNOTSUPP;
461+
err = -EOPNOTSUPP;
462+
if (l4proto->l4proto != l4num)
462463
goto err;
464+
465+
switch (l4proto->l4proto) {
466+
case IPPROTO_ICMP:
467+
timeouts = &net->ct.nf_ct_proto.icmp.timeout;
468+
break;
469+
case IPPROTO_TCP:
470+
timeouts = net->ct.nf_ct_proto.tcp.timeouts;
471+
break;
472+
case IPPROTO_UDP:
473+
timeouts = net->ct.nf_ct_proto.udp.timeouts;
474+
break;
475+
case IPPROTO_DCCP:
476+
#ifdef CONFIG_NF_CT_PROTO_DCCP
477+
timeouts = net->ct.nf_ct_proto.dccp.dccp_timeout;
478+
#endif
479+
break;
480+
case IPPROTO_ICMPV6:
481+
timeouts = &net->ct.nf_ct_proto.icmpv6.timeout;
482+
break;
483+
case IPPROTO_SCTP:
484+
#ifdef CONFIG_NF_CT_PROTO_SCTP
485+
timeouts = net->ct.nf_ct_proto.sctp.timeouts;
486+
#endif
487+
break;
488+
case 255:
489+
timeouts = &net->ct.nf_ct_proto.generic.timeout;
490+
break;
491+
default:
492+
WARN_ON_ONCE(1);
493+
break;
463494
}
464495

496+
if (!timeouts)
497+
goto err;
498+
465499
skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
466500
if (skb2 == NULL) {
467501
err = -ENOMEM;
@@ -472,7 +506,7 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl,
472506
nlh->nlmsg_seq,
473507
NFNL_MSG_TYPE(nlh->nlmsg_type),
474508
IPCTNL_MSG_TIMEOUT_DEFAULT_SET,
475-
l4proto);
509+
l4proto, timeouts);
476510
if (ret <= 0) {
477511
kfree_skb(skb2);
478512
err = -ENOMEM;

0 commit comments

Comments
 (0)