From patchwork Thu Jul 12 00:40:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 942742 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="AxeJgSMI"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41Qxtf4wNwz9s01 for ; Thu, 12 Jul 2018 10:40:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389572AbeGLAre (ORCPT ); Wed, 11 Jul 2018 20:47:34 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40455 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389523AbeGLAre (ORCPT ); Wed, 11 Jul 2018 20:47:34 -0400 Received: by mail-pg1-f196.google.com with SMTP id x5-v6so3371341pgp.7 for ; Wed, 11 Jul 2018 17:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=tu4ujkRbTo2zDjGZsrnlomuw6GQUHm6nBp+OimEqrdc=; b=AxeJgSMIU/+Heh0zYXWwKMQoRpGDGOvVHjX99vyNLrk/lQfSuR/H9qt4mVFO8vOMty 3lACSUqAdLSqNC0qzwJt9ttWgitXgVGTv7aKO0g7AIGjg5dThBxqDSqGDO2br9NcFL1a lt1ZFwWzkvedT5SrWgwVl2ybUIDTK2dX/nt1E54MR5/00+UZQome0pdwRY+0LodNEFoh RAGp8G3qiCJP2OJDhoxHNFlt/FffEHItkYw6uBfQkebofoWK4bBFibRbA0jlRuhW1fgA B2y7FMXsBE6CQ/7fuhlQrnZWtXlyjlqM30Ev4sQkOXyB85tCSoAFXIAqCW5g6Dais1kO 7HTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tu4ujkRbTo2zDjGZsrnlomuw6GQUHm6nBp+OimEqrdc=; b=FVrAIkVKbFSlxg5BnFqerxpmRozoKvPswcKTp2s00haDPlsP0Y8a++0upQ1NuIYLF1 zSTwA3bKCkUrBdUPx7e3n5YNR/WZRQ70CBJrP4y5b8lpeOvmWwJ+cuxV1pAsJ2eRkg2k capsuAAx5gLSoO230lFtSgZH4gCWCSRxCq3gcs8nvdbckNNDRauutM5VJWfFLh+z1Hed Zf32sdOCrZOBYuJfk7XZE3IMeuYjzlg+w1Gd4q/yRLTJC/s0FpXfaj63ud3mGm7F1RlJ ZtqYkdzmEEL75G2DIJDLJRDm26jtmh1J1Kp69yrGWobSA4GwDZbvBrz4ZoDhJy4Nn0GV fNyQ== X-Gm-Message-State: AOUpUlGJLQcLxkPT6HVIh/z6czptOGc4BfVg3n+DCWF+8Ob9GXsY4FhW PLUBjUzE5TCE2ZrLVcqlgcDksg== X-Google-Smtp-Source: AAOMgpcX84Ohol3htwaempZzfqkLyd0ZAVJUo74QImFMjZwKPqSJGV1mDO8eerkvBwc1+UT3l2CVVg== X-Received: by 2002:a65:6104:: with SMTP id z4-v6mr56808pgu.361.1531356040304; Wed, 11 Jul 2018 17:40:40 -0700 (PDT) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id c29-v6sm10233729pfe.169.2018.07.11.17.40.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Jul 2018 17:40:39 -0700 (PDT) From: Eric Dumazet To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal Cc: netfilter-devel@vger.kernel.org, netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net] netfilter: nf_conntrack: prevent uninit-value in gc_worker Date: Wed, 11 Jul 2018 17:40:37 -0700 Message-Id: <20180712004037.197064-1-edumazet@google.com> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org KMSAN reported use of uninit-value in gc_worker [1] We need to clear ct->timeout in __nf_conntrack_alloc() otherwise __nf_conntrack_confirm() might propagate garbage when adding nfct_time_stamp to ct->timeout : ct->timeout += nfct_time_stamp; [1] BUG: KMSAN: uninit-value in gc_worker+0x89e/0x1530 net/netfilter/nf_conntrack_core.c:1028 CPU: 1 PID: 19 Comm: kworker/1:0 Not tainted 4.18.0-rc4+ #24 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: events_power_efficient gc_worker Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x185/0x1e0 lib/dump_stack.c:113 kmsan_report+0x195/0x2c0 mm/kmsan/kmsan.c:1092 __msan_warning_32+0x7d/0xe0 mm/kmsan/kmsan_instr.c:640 gc_worker+0x89e/0x1530 net/netfilter/nf_conntrack_core.c:1028 process_one_work+0x1655/0x2000 kernel/workqueue.c:2153 worker_thread+0x1136/0x2490 kernel/workqueue.c:2296 kthread+0x473/0x4b0 kernel/kthread.c:247 ret_from_fork+0x35/0x40 arch/x86/entry/entry_64.S:415 Uninit was stored to memory at: kmsan_save_stack_with_flags mm/kmsan/kmsan.c:256 [inline] kmsan_save_stack mm/kmsan/kmsan.c:271 [inline] kmsan_internal_chain_origin+0x13c/0x240 mm/kmsan/kmsan.c:683 __msan_chain_origin+0x76/0xd0 mm/kmsan/kmsan_instr.c:483 __nf_conntrack_confirm+0x2700/0x3f70 net/netfilter/nf_conntrack_core.c:793 nf_conntrack_confirm include/net/netfilter/nf_conntrack_core.h:71 [inline] ipv6_confirm+0x573/0x740 net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c:165 nf_hook_entry_hookfn include/linux/netfilter.h:119 [inline] nf_hook_slow+0x15d/0x3e0 net/netfilter/core.c:511 nf_hook include/linux/netfilter.h:242 [inline] NF_HOOK_COND include/linux/netfilter.h:275 [inline] ip6_output+0x37d/0x710 net/ipv6/ip6_output.c:171 dst_output include/net/dst.h:444 [inline] ip6_local_out+0x164/0x1d0 net/ipv6/output_core.c:176 ip6_send_skb net/ipv6/ip6_output.c:1696 [inline] ip6_push_pending_frames+0x218/0x4d0 net/ipv6/ip6_output.c:1716 rawv6_push_pending_frames net/ipv6/raw.c:616 [inline] rawv6_sendmsg+0x45f0/0x5410 net/ipv6/raw.c:935 inet_sendmsg+0x3fc/0x760 net/ipv4/af_inet.c:798 sock_sendmsg_nosec net/socket.c:641 [inline] sock_sendmsg net/socket.c:651 [inline] __sys_sendto+0x798/0x8e0 net/socket.c:1797 __do_sys_sendto net/socket.c:1809 [inline] __se_sys_sendto net/socket.c:1805 [inline] __x64_sys_sendto+0x1a1/0x210 net/socket.c:1805 do_syscall_64+0x15b/0x230 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x63/0xe7 Uninit was created at: kmsan_save_stack_with_flags mm/kmsan/kmsan.c:256 [inline] kmsan_internal_poison_shadow+0xc8/0x1d0 mm/kmsan/kmsan.c:181 kmsan_kmalloc+0xa1/0x120 mm/kmsan/kmsan_hooks.c:91 kmem_cache_alloc+0xad2/0xbb0 mm/slub.c:2739 __nf_conntrack_alloc+0x166/0x670 net/netfilter/nf_conntrack_core.c:1137 init_conntrack+0x635/0x2840 net/netfilter/nf_conntrack_core.c:1219 resolve_normal_ct net/netfilter/nf_conntrack_core.c:1333 [inline] nf_conntrack_in+0x1812/0x2070 net/netfilter/nf_conntrack_core.c:1416 ipv6_conntrack_local+0xc3/0xf0 net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c:179 nf_hook_entry_hookfn include/linux/netfilter.h:119 [inline] nf_hook_slow+0x15d/0x3e0 net/netfilter/core.c:511 nf_hook include/linux/netfilter.h:242 [inline] __ip6_local_out+0x64c/0x770 net/ipv6/output_core.c:164 ip6_local_out+0xa4/0x1d0 net/ipv6/output_core.c:174 ip6_send_skb net/ipv6/ip6_output.c:1696 [inline] ip6_push_pending_frames+0x218/0x4d0 net/ipv6/ip6_output.c:1716 rawv6_push_pending_frames net/ipv6/raw.c:616 [inline] rawv6_sendmsg+0x45f0/0x5410 net/ipv6/raw.c:935 inet_sendmsg+0x3fc/0x760 net/ipv4/af_inet.c:798 sock_sendmsg_nosec net/socket.c:641 [inline] sock_sendmsg net/socket.c:651 [inline] __sys_sendto+0x798/0x8e0 net/socket.c:1797 __do_sys_sendto net/socket.c:1809 [inline] __se_sys_sendto net/socket.c:1805 [inline] __x64_sys_sendto+0x1a1/0x210 net/socket.c:1805 do_syscall_64+0x15b/0x230 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x63/0xe7 Fixes: f330a7fdbe16 ("netfilter: conntrack: get rid of conntrack timer") Signed-off-by: Eric Dumazet Cc: Pablo Neira Ayuso Cc: Florian Westphal Reported-by: syzbot --- net/netfilter/nf_conntrack_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 3d52804250274602c521f3cfe6c0c3b8fa9e78e9..759d09bd27140c85f1a19fdb20390558e7e8f161 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1145,6 +1145,7 @@ __nf_conntrack_alloc(struct net *net, /* save hash for reusing when confirming */ *(unsigned long *)(&ct->tuplehash[IP_CT_DIR_REPLY].hnnode.pprev) = hash; ct->status = 0; + ct->timeout = 0; write_pnet(&ct->ct_net, net); memset(&ct->__nfct_init_offset[0], 0, offsetof(struct nf_conn, proto) -