Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5190132ybi; Tue, 28 May 2019 08:58:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxOMxz2IEQkE++Ef2X37n6vKvvDbPUGrIqPfDaYfEL19AJ5IdoURO8D1uAHYiUmZUDLvq9 X-Received: by 2002:a17:90a:248:: with SMTP id t8mr6816944pje.119.1559059119533; Tue, 28 May 2019 08:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559059119; cv=none; d=google.com; s=arc-20160816; b=yGAhGcX+72vAAN6/sDYN2UDGm7TOv71Q8xi2pfgP8bNZuDxYUNMiqpQjQXXJ16MBnI X+j/2ql8rGw2+7hHUGsNGNtbfGMXYQvcR8scueJWhVj0qz+40wa/uqUbSzuDXLSYcpPI M6madnZp911/fAt3MUEOEDsc2dniG7CNEQHSxPcRTxRmsW16mP6a4rZmu3skI7LpXHBi blJ8PZJ3q2F6wmLWd21HUcY4zI1orY4mw07zTD+1rGqQ8/mEJf8tgq3Qe8iPn7tav+AW FWnrQHyLA11YiXGzi0V6BnbMewSAc8guZ2/ofzxiO3hJrHESd15W1Xo6e3vVw5b0d5lF IxsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=4sx6zuiPNmk1/+rypL+mdhl/tHJkw6ok3vlutZvaqlg=; b=xO5HYXYtlLHvoVmIdwuXNlP3SxisaReUexz53RMKouG1jNhZgpGKB2hL2gtJnW1OuO U5Bdcm2Th80tZajjJ140Is9NI6VnPwD2SzTZNaYmilM7PRTcnAn+HkYu3PEkJonJbtkV 3vMfmGVsFSUSoRdmWx09uBMre/SCHRqrleufjtatr9F4iV2G9gaqiDE/59c548+PEt/X QHxzpzBUNsk/tgE/nSyqPc1yrNsksewfmtUAoZc2PSuTOBWHPOf51l1zLwgztQWHylUe Lk413RqRsSg+ncrvzlkZ7Q9iGKMxx9GHnRis02IJy0O6AIaPWwvIlVq5DyWhY1D8uxRY RtRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BAruqRTN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si23593604pfb.7.2019.05.28.08.58.24; Tue, 28 May 2019 08:58:39 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BAruqRTN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbfE1PzX (ORCPT + 99 others); Tue, 28 May 2019 11:55:23 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:36278 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbfE1PzW (ORCPT ); Tue, 28 May 2019 11:55:22 -0400 Received: by mail-lj1-f196.google.com with SMTP id w16so593019ljd.3 for ; Tue, 28 May 2019 08:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4sx6zuiPNmk1/+rypL+mdhl/tHJkw6ok3vlutZvaqlg=; b=BAruqRTNAuHmdADbYtzdc1NnjwOLpFamR1xmF5wKpLBENZTkD/0oxBAS7jyujLZbm7 +QcU9GgX9XR9EbGCvyHpNv6cWM+in+2ruw6J3gkyKDwbsArABfIG/y4VmVnO+C16fFIh ugptwjzGuo9+eCuEI0KXyQwmcSWkLIYcjK9aON+GXxIe8E17LWOquf5IiHAaWfNitGHF Aqdv7ZjeJuz+l+lxYCpS/S+/D7uIxoqKhh52aJfwVdwrxjP/V4gMj1GVvFYiyw3LZl4S cdiDLu/e/LN0SEb5PH+B+Em6gnwYs13wEzxkqu446ssr8MOqCFGjGeQ/5qxCeVl2LiEm hyag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=4sx6zuiPNmk1/+rypL+mdhl/tHJkw6ok3vlutZvaqlg=; b=PbPf61rFIjAL0JDJ4mdEOpgj6C4yJV9KorH5dyYTd4cavTeMCwIIRAJT390KCswm6n NU+sztkkPxrC3R0FkLIozy1wOQNwlhg0ZxGxCAYEA6hxuecYrMtlQrhhYu0W9hs9RcYt 2iQeUfaQCrHH4nbU1kLl6E3vLGdTbNBSWxzI/Caw6EOIYpg6mzYRd3fMi61f8wL4O/nT 0xcA2OxJOxIosv4Lj2ELIXvFdn1gDbzeKO885iDGTnvY1vfeuqbqnvQDmJij29mna8Vu LeodbtKiDrq4Q0zI/rhiXunFxk8DSg9kCLgUbweP/DZIlFW6n5YZBJgK47595MkTXBHr gabg== X-Gm-Message-State: APjAAAVeykGlVTXmfbg3TnEQ1O9qnAKCXLYFCGXYfVaPBw9DhHR76KNk qh1lky35+u28Z6GA1W4ppo0= X-Received: by 2002:a2e:7d02:: with SMTP id y2mr38817535ljc.62.1559058919834; Tue, 28 May 2019 08:55:19 -0700 (PDT) Received: from [192.168.1.15] (2-111-15-75-dynamic.dk.customer.tdc.net. [2.111.15.75]) by smtp.gmail.com with ESMTPSA id m21sm405603lfh.20.2019.05.28.08.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 May 2019 08:55:19 -0700 (PDT) Subject: Re: [PATCH] trace: Avoid memory leak in predicate_parse() To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, mingo@redhat.com References: <20190528104400.388e4c3f@gandalf.local.home> <20190528154338.29976-1-tomasbortoli@gmail.com> <20190528114821.2302dabd@gandalf.local.home> From: Tomas Bortoli Openpgp: preference=signencrypt Autocrypt: addr=tomasbortoli@gmail.com; prefer-encrypt=mutual; keydata= mQINBFpCTZMBEADNZ1+Ibh0Z4pgGRcd1aOUMbe/YfHktmajjcoTnKmZZunjoUVAl8waeLITd BC2c8i1wHzHcnthrmb1izs5XlG6PZnl8n5tjysSNbwggzS1NcEK1qgn5VjNlHQ5aRMUwCC51 kicBiNmlQk2UuzzWwdheRGnaf+O1MNhC0GBeEDKQAL5obOU92pzflv6wWNACr+lHxdnpyies mOnRMjH16NjuTkrGbEmJe+MKp0qbjvR3R/dmFC1wczniRMQmV5w3MZ/N9wRappE+Atc1fOM+ wP7AWNuPvrKg4bN5uqKZLDFH7OFpxvjgVdWM40n0cQfqElWY9as+228Sltdd1XyHtUWRF2VW O1l5L0kX0+7+B5k/fpLhXqD3Z7DK7wRXpXmY59pofk7aFdcN97ZK+r6R7mqrwX4W9IpsPhkT kUyg3/Dx/khBZlJKFoUP325/hoH684bSiPEBroel9alB7gTq2ueoFwy6R3q5CMUw3D+CZWHA 3xllu46TRQ/Vt2g0cIHQNPoye2OWYFJ6kSEvaLpymjNDJ9ph2EuHegonDfOaYSq34ic2BcdB JkCgXRLP5K7KtRNJqqR+DM8xByeGmQv9yp6S97el+SiM9R53RhHawJZGz0EPl+2Q6+5mgh3u wXOlkmGrrSrlB8lc567l34ECl6NFtUPIL7H5vppIXAFl7JZUdQARAQABtB50b21hcyA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Z0ginUUY993Gb8k/CxjABEMUGVHhQPZ0OzjHIKS6cTzN6ue8bB+CGOLCaQp1 C0NRT5Tn9zpLxtf5nBExFd/zVENY5vAV2ZbKQdemO54O7j6B9DSgVRrm83GCZxbL4d+qTYBF 3tSCWw/6SG1F3q9gR9QrSC2YRjCmhijUVEh6FhZwB58TNZ1sEEttrps8TDa5tUd9 Message-ID: <2100b570-889d-a3d3-9e7e-19b74da9243c@gmail.com> Date: Tue, 28 May 2019 17:55:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190528114821.2302dabd@gandalf.local.home> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/28/19 5:48 PM, Steven Rostedt wrote: > On Tue, 28 May 2019 17:43:38 +0200 > Tomas Bortoli wrote: > >> In case of errors, predicate_parse() goes to the out_free label >> to free memory and to return an error code. >> >> However, predicate_parse() does not free the predicates of the >> temporary prog_stack array, thence leaking them. > > Thanks, I applied this and I'm running it through my tests. But just an > FYI, when sending updated patches please add a "v2" to the subject: > > [PATCH v2] tracing: Avoid memory leak in predicate_parse() > > That way struggling maintainers like myself don't get confused about > which patch to apply ;-) > > Thanks! > Yeah, sorry about that, will make sure it doesn't happen again! Thank you, Tomas > >> >> Signed-off-by: Tomas Bortoli >> Reported-by: syzbot+6b8e0fb820e570c59e19@syzkaller.appspotmail.com >> --- >> kernel/trace/trace_events_filter.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c >> index 05a66493a164..ecfa6f0f1c7e 100644 >> --- a/kernel/trace/trace_events_filter.c >> +++ b/kernel/trace/trace_events_filter.c >> @@ -427,7 +427,7 @@ predicate_parse(const char *str, int nr_parens, int nr_preds, >> op_stack = kmalloc_array(nr_parens, sizeof(*op_stack), GFP_KERNEL); >> if (!op_stack) >> return ERR_PTR(-ENOMEM); >> - prog_stack = kmalloc_array(nr_preds, sizeof(*prog_stack), GFP_KERNEL); >> + prog_stack = kcalloc(nr_preds, sizeof(*prog_stack), GFP_KERNEL); >> if (!prog_stack) { >> parse_error(pe, -ENOMEM, 0); >> goto out_free; >> @@ -578,6 +578,8 @@ predicate_parse(const char *str, int nr_parens, int nr_preds, >> out_free: >> kfree(op_stack); >> kfree(inverts); >> + for (i = 0; prog_stack[i].pred; i++) >> + kfree(prog_stack[i].pred); >> kfree(prog_stack); >> return ERR_PTR(ret); >> } >