Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5658520imm; Mon, 23 Jul 2018 03:53:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdQqPRyFb7smPkaJxKyaKxoSF9kUvNa3OHZnls4RDSVWmVdr5IKk1Z7iKDqdoDOmhHhqvkq X-Received: by 2002:a17:902:bf44:: with SMTP id u4-v6mr12576880pls.84.1532343196804; Mon, 23 Jul 2018 03:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532343196; cv=none; d=google.com; s=arc-20160816; b=ogRmrKd97xBP7wZLEE0GCXWCMnhNz8kTw+zXMx3HeBut7YKDPXOSyJRkVBCtmnwkv7 qE44arcD6429wUOTeOs7KMlPV4UiZg2SPPR0iXikA1ev8ZrPe2MjJsdcqkmAqd0FHg9d SdrDCrX3pCDhbIMBBALpeBuMF+65n4bPpKj2nXWt3OYq1GZ7zP0AUf1e/WbHwZN9aHmE I6N2LVykkLVuFPJVxWruNO2ycJ0Ea7zGvtDEDYy+gugR1QjVLFe8QUL5mpx1rD56UnbJ rCO9LGluHJzXYj3FcbWSmiEiJ+aTYh32f7wM8mtHWgJFX/JqBYCBQw+FlosWbfWJaf7W e2eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=5zLN0v5RwC56JFPjylUMYqFF9u+HlhetOOGN6jLLh/k=; b=H41rms1gtc+yI4woFkqxNjgpbiyR5KUjF3+DhT4g8yUHjePWOoCNKomlCZZpHBZGlG B9D9nihwJ9GOisZ4MVR1kVrYYkYqOiVfqijdSPUd7nHxhS01vrxTq2ku70gonmZCv8Q0 elL9fBRmiVX2B97/N/xw9bDtqvt1UD6x3/99A24W0KRpJJ2PbdnilpQ2hNxeeZpe1PeW bbtWl0FfvPlW6TexMr6qfR/IBsxMCbwKhu2FkQcfymP5nrWuE+kgJV3054O/tcY2jxGD kQno0RUqIjt5Ppnv9yPIT6fimosS1ST8Wos9zVQWT6IRnDQEmU5ClCjTAdIA8PRfMWit Vy2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11-v6si3244317pll.234.2018.07.23.03.53.01; Mon, 23 Jul 2018 03:53:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387936AbeGWLwp (ORCPT + 99 others); Mon, 23 Jul 2018 07:52:45 -0400 Received: from Chamillionaire.breakpoint.cc ([146.0.238.67]:35468 "EHLO Chamillionaire.breakpoint.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387815AbeGWLwp (ORCPT ); Mon, 23 Jul 2018 07:52:45 -0400 Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.89) (envelope-from ) id 1fhYRb-0008Ja-Tm; Mon, 23 Jul 2018 12:52:00 +0200 Date: Mon, 23 Jul 2018 12:51:59 +0200 From: Florian Westphal To: Pablo Neira Ayuso Cc: Florian Westphal , David Miller , cscnull@gmail.com, kadlec@blackhole.kfki.hu, johannes.berg@intel.com, Jason@zx2c4.com, ktkhai@virtuozzo.com, lucien.xin@gmail.com, xiyou.wangcong@gmail.com, dsahern@gmail.com, netfilter-devel@vger.kernel.org, tom@quantonium.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] netlink: fix memory leak of dump Message-ID: <20180723105159.vpknxgam3fqeicvv@breakpoint.cc> References: <20180722143354.23722-1-cscnull@gmail.com> <20180722163925.gdfkndldatsoae6x@breakpoint.cc> <20180722.100755.19840167505550163.davem@davemloft.net> <20180722180910.wcwhantwpm2nfxet@breakpoint.cc> <20180723091551.mwhltw4ujm4bylvj@salvia> <20180723092818.ztsfsnqzxgzrauim@breakpoint.cc> <20180723093855.c4ncixsnkee6r34v@salvia> <20180723094228.mejwuvoyitolqktv@breakpoint.cc> <20180723094742.gg6e73l6aknghal7@salvia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180723094742.gg6e73l6aknghal7@salvia> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pablo Neira Ayuso wrote: > On Mon, Jul 23, 2018 at 11:42:28AM +0200, Florian Westphal wrote: > We can also add another scratchpad area, similar to the ->cb[x] area > that can be initialized before netlink_dump_start()? So we don't need > the data pointer. > > By passing the array of attributes, we'll need to do attribute parsing > over and over again from each netlink_dump() call. Its still done once, parsing is only delayed/moved to ->start(). Now: nla_parse control->data = kmalloc() + init netlink_dump_start() ->start() /* if it returns 0, done() will be called eventually netlink_dump() ->done() free(cb->data); Proposed fix: control->data = &on_stack; netlink_dump_start() ->start() nla_parse cb->data = kmalloc() + init netlink_dump() ->done() free(cb->data); I've submitted a patch for nf_tables, let me know if you have a better idea or see a problem with it.