Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp46516pxf; Tue, 6 Apr 2021 14:35:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsYmcLm7LeL9oDoxCNVvS3OPkr6kKSKqshCQNiGiAes6gpHjAhqSQsEE3H0eNAi0WxWmhf X-Received: by 2002:a05:6402:3592:: with SMTP id y18mr453091edc.360.1617744910623; Tue, 06 Apr 2021 14:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617744910; cv=none; d=google.com; s=arc-20160816; b=mlFgoNInyFWWO6U4H0s0B2VOywDiyPWUvXyy46T2Wq09gP1aAhte0PUo7oBkxOzPV3 btETyWk+M5hXEBBSg1+3WW34brMQJcfX8/N5UZiuhxVMSRlvLurv/FmR1hMwAEUsa3wi qgnynOFV3uB+CfujM0uPaX35yYP5m3Bz6LW7ouYhcBLCH6H9RfHu32lb/js0J/AOWeIB O5JP71pxmDtqSFIqsNV5mTEw+2xeLkGp35WEJAFv1hRnhoQAHZ0+GnPCPWrfBa8A0Ykt qC4CTwrX34LMdPaM8DV9G/kWTTR4cSH3DT+dJhf40GywDmz88ELDvHGB1YGK3BejzS5g K6CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=DBzwzR4kFf2+lB+4t5orhs/i7MNX+pi7Gwnrrl3afXM=; b=IGAnlIKrcNlQ6kG6HVRAsIRhq3qgD/3mcOgAlLH756nDNaDVOf51V6pqtgp3+BezRL pozFRBvvKGdpnVetQuikB4RqrZkOddLqU39tJoBCQcSLK+hGrjy2tOPpz0Ce51BLFzC3 10acqB1i88XI+MmF9gEgimPc4vxm040bj8vu+RNYTpYkRRwx4HnQ/YW9aDMQ4qrA7J31 bt9+Sb4+FVBb/nAAdex27zEMiGsz4KYWffszsGKC/vgOMKtc1HKMo7NDND1LcbvWL2gH 4971Rz9y8S80g34A3pbueyXQ5pL7o416HcMg50GPaKjtQ9mB+3Gj8x7dfgiDVGTexmR8 1I0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si16860399edc.65.2021.04.06.14.33.37; Tue, 06 Apr 2021 14:35:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242010AbhDFM1h (ORCPT + 99 others); Tue, 6 Apr 2021 08:27:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:43494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241745AbhDFM1g (ORCPT ); Tue, 6 Apr 2021 08:27:36 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 55BB76121E; Tue, 6 Apr 2021 12:27:28 +0000 (UTC) Date: Tue, 6 Apr 2021 08:27:26 -0400 From: Steven Rostedt To: Jiapeng Chong Cc: mingo@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ftrace: Check if pages were allocated before calling free_pages() Message-ID: <20210406082726.3b25a2f6@gandalf.local.home> In-Reply-To: <1617691905-8016-1-git-send-email-jiapeng.chong@linux.alibaba.com> References: <1617691905-8016-1-git-send-email-jiapeng.chong@linux.alibaba.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 6 Apr 2021 14:51:45 +0800 Jiapeng Chong wrote: > It is possible that on error pg->size can be zero when getting its > order,which would return a -1 value. It is dangerous to pass in an > order of -1 to free_pages(). Check if order is greater than or equal > to zero before calling free_pages(). > > Reported-by: Abaci Robot > Signed-off-by: Jiapeng Chong > --- > kernel/trace/ftrace.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index b7e29db..74efc33 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -6811,7 +6811,8 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr) > if (!pg->index) { > *last_pg = pg->next; > order = get_count_order(pg->size / ENTRIES_PER_PAGE); > - free_pages((unsigned long)pg->records, order); > + if (order >= 0) > + free_pages((unsigned long)pg->records, order); This has already been fixed upstream. -- Steve > ftrace_number_of_pages -= 1 << order; > ftrace_number_of_groups--; > kfree(pg);