From patchwork Fri Apr 14 07:17:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Yejian X-Patchwork-Id: 83258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp191686vqo; Fri, 14 Apr 2023 00:20:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZsRyta7j8pe4gL/9N9pjbj0YtUwbDFVH44T84+LkkLoLDnzQXLbqmeG5AoVzOJyFOJAHO0 X-Received: by 2002:a17:902:f691:b0:1a1:a146:f6d7 with SMTP id l17-20020a170902f69100b001a1a146f6d7mr2388614plg.4.1681456825791; Fri, 14 Apr 2023 00:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681456825; cv=none; d=google.com; s=arc-20160816; b=TBkyzvO/Ob6F3N7rWzjnFd53zQsFWRz5Hj1F4AvK5JRAzBIRIlo40Q7Gj27OOP3W6S yvRcngPq9/J/+RSZ+yBYzdlAJyf3ULzRlyfD++PVLWavn9GpXRugJvImx2NaHxqj+1BY E8/GFHQT7H9Tao7AZSNrMhxScGmlUlv10clVDWv4QHRX2YRXrFv+Hz4ihu/sv0WM3bYN xRk9xjRR6gPUJn1z07i1gN4utcJnvF1zp04B1DKbuqIfJlh51/1NpcDlWke0C85QZEHQ sFYMIeYMghrbSy7Jrl0WhEJTIMXVVZwCkVVkFk8AndJOfge93NjCjW/T9spsrHQscblk VmbQ== 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 :message-id:date:subject:cc:to:from; bh=PdwL/hBGM8K9FPZO9UcpGNSnYV2CvrgYgAwEbvZDU3E=; b=Ou1m9MR5+r7hgEEK281bAvtCw4P5KNecCVDJAxfIl5A+oLoW00kyUT+LDNEbHCucQy lU6l9lzhOwz2/tQaL+RmjS+CJVpleIMfokHbT4+7E8PqJw6u5BCU5Ghd9mCFbCuKyxmy ATGhSHEhc2vohzc7S77wc/s6qedyBSAqCrNQurAgyCxzJDiBn2R8HF+ge8QrbsIZGMfl fXwSm1zfOcoZsI1kSNv3tWm2hHNUrSMK2ewvKv9fsI2gyhuBNa+6tHGWbre6JIzQv4Xq OfxIf0QRRod7XhHSF9Ofda8YJKw7FTJOP/3Ff9MCKTRzjqLF9uTuSPzIldEWZuSy1HwI 98FQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w62-20020a638241000000b0051b513cda72si3364968pgd.333.2023.04.14.00.20.10; Fri, 14 Apr 2023 00:20:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229668AbjDNHOL (ORCPT + 99 others); Fri, 14 Apr 2023 03:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjDNHOK (ORCPT ); Fri, 14 Apr 2023 03:14:10 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E053C3C07; Fri, 14 Apr 2023 00:14:08 -0700 (PDT) Received: from dggpeml100012.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PySMD1ctQzrbgs; Fri, 14 Apr 2023 15:12:40 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml100012.china.huawei.com (7.185.36.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Fri, 14 Apr 2023 15:14:05 +0800 From: Zheng Yejian To: , , CC: , Subject: [PATCH] ring-buffer: Clearly check null ptr returned by rb_set_head_page() Date: Fri, 14 Apr 2023 15:17:29 +0800 Message-ID: <20230414071729.57312-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml100012.china.huawei.com (7.185.36.121) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763135272324947273?= X-GMAIL-MSGID: =?utf-8?q?1763135272324947273?= In error case, 'buffer_page' returned by rb_set_head_page() is NULL, currently check '&buffer_page->list' is equivalent to check 'buffer_page' due to 'list' is the first member of 'buffer_page', but suppose it is not some time, 'head_page' would be wild memory while check would be bypassed. Signed-off-by: Zheng Yejian --- kernel/trace/ring_buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 76a2d91eecad..025324df1f96 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -2060,10 +2060,11 @@ rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer) struct list_head *head_page, *prev_page, *r; struct list_head *last_page, *first_page; struct list_head *head_page_with_bit; + struct buffer_page *hpage = rb_set_head_page(cpu_buffer); - head_page = &rb_set_head_page(cpu_buffer)->list; - if (!head_page) + if (!hpage) break; + head_page = &hpage->list; prev_page = head_page->prev; first_page = pages->next;