Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4153157pxf; Tue, 6 Apr 2021 09:07:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb+EFuL+GYNeuJOT2B9oPgtNf/nKfn2OgziN0HXUHaBQ2HRX84FOVOsJjXoRlCsJaU0Yee X-Received: by 2002:a50:e702:: with SMTP id a2mr39434173edn.3.1617725252516; Tue, 06 Apr 2021 09:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617725252; cv=none; d=google.com; s=arc-20160816; b=xJVcSaxSotsl5zqZj8P3lsw/cQvfy9rCPa9Tvj2KT0TiAVdvkFs2VIwygtcJVYqfnP l/YJpVv7q6jsUYXwqS+WcnoIi+vk1V2Az2VCnWXS4Nwu/mc5Tn8dZJGkj3YFQuoUwrgj s02J5iKThRxUHswY900A2vYl56XF5U8gSX23KY9pPzn5D1TRILKtcNjb+LBaPk+Bar9N srquCQUFi31ZF3PqE5CNZZtl5b1eA9p/r7LZ5nas779hug2mf2u605bUZl31FxwdGboo dB5fDYGy9dN85L1xip/p6tLt5IMq6Bgv3+Zkq2v6P6it0fV1wGeiB7jMAkVIximmNVLu f29A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=IXbdvbF/yKrx9AILKweXJvUdhKgePxSMGOGgYVI6ftI=; b=WjM+lOlSXSqM0utsOS/OeTMv4YW8JuA25avyZqCZwL/nc9bKv2qXFnec1MdIdOo3NK hTPmWBZeyin0tq8OT/B7PfR/BmpjlZglE5DbBY8OCb/GQ2PTzD43T/0SWDI8nztll5jH 8zj5/yOItvd0tmHktpxvutaei7jiTbYw9vu76XBJXA0UFkIL3UtwobKJMJW05htzNDdy xJm8/QGWKbmWHwXlr/dT39oHqbFzuiZhr8ZhP884yMrjosW2oivVVLXEs1yebrfvzMkb LQBr8Y5nWTkIZFvWkZwe5ZkHPQwsqQXpOPQaZV8hnH9bnXCZpSqRmkwFezuyIcZj7Y64 GUvg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dx18si8427599ejb.674.2021.04.06.09.07.07; Tue, 06 Apr 2021 09:07:32 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244089AbhDFGwV (ORCPT + 99 others); Tue, 6 Apr 2021 02:52:21 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:57012 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbhDFGwU (ORCPT ); Tue, 6 Apr 2021 02:52:20 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=jiapeng.chong@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0UUfZeID_1617691907; Received: from j63c13417.sqa.eu95.tbsite.net(mailfrom:jiapeng.chong@linux.alibaba.com fp:SMTPD_---0UUfZeID_1617691907) by smtp.aliyun-inc.com(127.0.0.1); Tue, 06 Apr 2021 14:52:11 +0800 From: Jiapeng Chong To: rostedt@goodmis.org Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, Jiapeng Chong Subject: [PATCH] ftrace: Check if pages were allocated before calling free_pages() Date: Tue, 6 Apr 2021 14:51:45 +0800 Message-Id: <1617691905-8016-1-git-send-email-jiapeng.chong@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); ftrace_number_of_pages -= 1 << order; ftrace_number_of_groups--; kfree(pg); -- 1.8.3.1