Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp163297rwe; Fri, 14 Apr 2023 00:21:41 -0700 (PDT) X-Google-Smtp-Source: AKy350Zk42D8fD0jNiVsQP3O4pLiOLm5l3ubeywuaFcEYDDamfHsD+SQkLRZm48RwVQnsXL7qE8q X-Received: by 2002:a17:90a:718b:b0:23d:39d5:f81e with SMTP id i11-20020a17090a718b00b0023d39d5f81emr4571855pjk.11.1681456900947; Fri, 14 Apr 2023 00:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681456900; cv=none; d=google.com; s=arc-20160816; b=BkLIW0Ab2i785NTDSWogcClLb0Wm7JWB6mb6oVYyLXvJjqn3SLEzGZir065VfdJFMH Z9WCcPTsqM30Ev6SbjeM/rUnlR/59kFLesQhl8s7WcglxpgCcrBhioygxCfZQwuO6By5 vzJ2UQRCyE7G3FzKw0IrTXeZwxHE2ivXakaBYjDZcYXxCldOoC9zkYuItUj5UliHr4qt MSrW6/AUyUSoQJnh7kJpmGvtUZATLNEaDLdaTZWltjylIv+yco4NsgaeYAuKry9pUp7S XZUW9VRKBmfmy95ZgCP2NjRgjALjqddNbKPLoEkB+jRTCfbJaKid3yhsY9O6GxlEcbK6 h7FQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a170902d50500b0019aaf311eaesi4193788plg.267.2023.04.14.00.21.26; Fri, 14 Apr 2023 00:21:40 -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 S229650AbjDNHOL (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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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; -- 2.25.1