From patchwork Wed Oct 24 17:29:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: He Zhe X-Patchwork-Id: 10654829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6484814BD for ; Wed, 24 Oct 2018 17:32:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 533A82AFEE for ; Wed, 24 Oct 2018 17:32:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 436A22AFFC; Wed, 24 Oct 2018 17:32:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D20AF2AFEE for ; Wed, 24 Oct 2018 17:32:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C91336B0010; Wed, 24 Oct 2018 13:32:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C40406B0266; Wed, 24 Oct 2018 13:32:11 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2DE26B0269; Wed, 24 Oct 2018 13:32:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 721FF6B0010 for ; Wed, 24 Oct 2018 13:32:11 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id c6-v6so3316210pls.15 for ; Wed, 24 Oct 2018 10:32:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to :subject:date:message-id:mime-version; bh=5BVPIxQ3CKixdC0pzNg+wqRv35UZpz1PsfCjSL16X8o=; b=B+64wAqFBIU2QIKsI1Q+SDr47/9SU5HpweZOOPCA8TwvDDyPDfH0nKMgLK/L8ZHjqy i8nEFwwv3gXtFEG9KIvEb4WODhoD8Xi4+Ce6MsSAOAYHAqZOOvtzis7hLMhJBhhQCjJs kgN+63xFyn7mMWwVJECJltrr2ExwVRHd9qcsthBx2ODqGlyg/SSsvdt3Me8OutLv2weB jwYRSRa2/afAuEH93XPhBhXYV7dWOl7gryT/CNt3+PcoNgf2gaQ77r0p6zLsW1SFRRaK +RyhKSbcVwJxZtHoTE71ICAdFO+ifRNDCqfXUqd4HqfwGBhJ+kfFfcbXi1UptGZyeB/O sP6A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of zhe.he@windriver.com designates 192.103.53.11 as permitted sender) smtp.mailfrom=Zhe.He@windriver.com X-Gm-Message-State: AGRZ1gIRFRdtKpXdEBcPbLem7BimHzhRBogBfJuGxurU6tRCqLZn36hJ fyNrRJ/uqgyXzEoRYY0lv1DfLc4KO5d/6kJzzf2bmXV+mzDyit/xQDACpsAcx4Qm+3MRUD7xQ3q UdVyz1LaNOkZHk+jlIjRsGkTB3i3OKklbbjEMUfHNUvViQGFt5/YStSj+z6R4bQbj7w== X-Received: by 2002:a17:902:e81:: with SMTP id 1-v6mr3330090plx.314.1540402331074; Wed, 24 Oct 2018 10:32:11 -0700 (PDT) X-Google-Smtp-Source: AJdET5fuNeT5ul46ZRjolC0VZY9qJqzblDJaIrzq+0FLG1387rniGLjYzwar/D90/8WC5e5R8s4S X-Received: by 2002:a17:902:e81:: with SMTP id 1-v6mr3330039plx.314.1540402330233; Wed, 24 Oct 2018 10:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540402330; cv=none; d=google.com; s=arc-20160816; b=dWUgtlDLs3L+CovgWjaHzPHbP8U8UOoZp2Z1Q5YhJHDf8DxeusBJr8c7rgy4gGdEZq /KNhuAnfle3F60T2wPH0SMh9eTiiZZOZCG05EergMw1pNpft1poIwXRxvhwHx5Eyy2F4 ci2n158W3n8c6ALeQ6yhlP9iYw+HGO6DTQYFTWTHnhpnCqdVB+19V1Ype0v0V194XUR/ r70lUxTzkG9B8d96AliJkWjpx5giHIETHw+1Wrg+bJm8QbvBmDf6Af0d4RrsKRdf3h4D TZuQP0zHroct9pg62JhhItp77uPyJvAgyxRpdx5RrrE7hyEUfEBEgan/v0ZDNF2tJFYR C3Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:subject:to:from; bh=5BVPIxQ3CKixdC0pzNg+wqRv35UZpz1PsfCjSL16X8o=; b=nQx8Q+YaKXG5hRDejpfde14e3M89b7iCJa6lauh4tm6OQxbHhvotWfIJZxwTpRhnKl 4YqHkd3Yt347hOXyST036otN30UpIDY+N8/0I61k2zNK+yeOs4eCBBnmWZZ+NT04LP1B A5CPndfeSPT6uLbP3yBuBNmIRpGz8geHJaEJThK/u/5Bp+6VFo/187FX+JLFFWt2ct4H oUld7lGQFibKxgkTTFC/is/zcjbiNmBQH098DJu6pk9bwMBd1bGmYfhGqYmrdNfp8+X/ SxkBcOyzc6OZk+8GZTTPhELNp0l5xs4+zrKxxx3VOZTsM6Q1NHkqznSAR0R3mzyW/Q+m NSVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of zhe.he@windriver.com designates 192.103.53.11 as permitted sender) smtp.mailfrom=Zhe.He@windriver.com Received: from mail5.wrs.com (mail5.windriver.com. [192.103.53.11]) by mx.google.com with ESMTPS id p64-v6si1781952pga.163.2018.10.24.10.32.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Oct 2018 10:32:10 -0700 (PDT) Received-SPF: pass (google.com: domain of zhe.he@windriver.com designates 192.103.53.11 as permitted sender) client-ip=192.103.53.11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of zhe.he@windriver.com designates 192.103.53.11 as permitted sender) smtp.mailfrom=Zhe.He@windriver.com Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id w9OHUCJW013430 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 24 Oct 2018 10:30:22 -0700 Received: from pek-lpg-core2.corp.ad.wrs.com (128.224.153.41) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.408.0; Wed, 24 Oct 2018 10:30:00 -0700 From: To: , , , , , , , , , , Subject: [RFC] [PATCH] netfilter: Fix kmemleak false positive reports Date: Thu, 25 Oct 2018 01:29:57 +0800 Message-ID: <1540402197-173015-1-git-send-email-zhe.he@windriver.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: He Zhe unreferenced object 0xffff9643edb89900 (size 256): comm "sd-resolve", pid 220, jiffies 4295016710 (age 208.256s) hex dump (first 32 bytes): 01 00 00 00 00 00 00 00 03 00 74 f3 ba b1 b6 b5 ..........t..... 65 3e 00 00 00 00 00 00 90 f9 a0 ed 43 96 ff ff e>..........C... backtrace: [<0000000070d5b185>] kmem_cache_alloc+0x146/0x200 [<0000000007a27faa>] __nf_conntrack_alloc.isra.13+0x4d/0x170 [nf_conntrack] [<00000000ecc5b0ec>] init_conntrack+0x6a/0x2f0 [nf_conntrack] [<000000003d38809f>] nf_conntrack_in+0x2c5/0x360 [nf_conntrack] [<000000001fe154e3>] ipv4_conntrack_local+0x5d/0x70 [nf_conntrack_ipv4] [<0000000027adadb2>] nf_hook_slow+0x48/0xd0 [<000000009893511f>] __ip_local_out+0xbd/0xf0 [<00000000d68cbd2f>] ip_local_out+0x1c/0x50 [<00000000995e2f37>] ip_send_skb+0x19/0x40 [<000000003d95f220>] udp_send_skb.isra.5+0x157/0x360 [<00000000ebc25968>] udp_sendmsg+0x9d8/0xc10 [<000000003bef56ec>] inet_sendmsg+0x3e/0xf0 [<000000008d23e405>] sock_sendmsg+0x1d/0x30 [<000000008c297097>] ___sys_sendmsg+0x108/0x2b0 [<00000000f15a806c>] __sys_sendmmsg+0xba/0x1c0 [<00000000e195d2cf>] __x64_sys_sendmmsg+0x24/0x30 In __nf_conntrack_confirm, object ct can be referenced to by the stack variable ct and the members of ct->tuplehash. kmemleak needs at least one of them to find the ct object during scan. When the ct object is moved from the unconfirmed hlist to the confirmed hlist. kmemleak cannot see ct object if things happen in the following order and thus give the above false positive report. 1) The ct object is removed from the unconfirmed hlist. 2) kmemleak scans data/bss sections(heap scan passes without heap reference). 3) The ct object is added to confirmed hlist and the variable ct is destroyed as the function returns. 4) kmemleak scans task stacks(stack scan passes without stack reference). This patch marks ct object as not a leak. Signed-off-by: He Zhe Cc: pablo@netfilter.org Cc: kadlec@blackhole.kfki.hu Cc: fw@strlen.de Cc: davem@davemloft.net Cc: catalin.marinas@arm.com --- So far this is only observed in v4.18, not in v4.19. But the case seems apply to both. net/netfilter/nf_conntrack_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index a676d5f..067365d 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -1282,6 +1283,8 @@ __nf_conntrack_alloc(struct net *net, if (ct == NULL) goto out; + kmemleak_not_leak(ct); + spin_lock_init(&ct->lock); ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple = *orig; ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode.pprev = NULL;