Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3406321rwa; Tue, 23 Aug 2022 04:22:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4N3ADhDOxXmNXQ8go8BkX7zKjbN2eT0yIerh36uU3rb+v/FHl1fWpUTQ1K1sqK4UV2MVZ/ X-Received: by 2002:a17:902:c949:b0:172:d2cd:a9b2 with SMTP id i9-20020a170902c94900b00172d2cda9b2mr14721036pla.38.1661253721409; Tue, 23 Aug 2022 04:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253721; cv=none; d=google.com; s=arc-20160816; b=Iu2PfG22MTH/Yzn9hMzjkAzS7QNFriTtmuslfqd9fE1zRTjjauhjg44/382FSBtriC x8KPpzQ3uyIviuh6k2Grm61Ea6GvZD8ErbP5bH79CekShFSVteamrQQFJAYCKYRZKwRu uCS+5cwfwk6NxoMOuPgm07H61j8wcrK4lg0XzXM2U4N7Vh0ulIC8E8mSptI1YVNbqlGv hLwk6N+INeyfJIAIa7wZZ2SJU4S303B01+NQ4uv5ncSRHK8BKn3CgXcStIZ9WCit/fzn aQ0EZXdAARldw7+Jl9e/KOLwxdhWb7Rfhpc1aw1aBt4oNAXV2PBBeOxTS5kLYX+hTJ01 YP9w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5QqrPDZ2swW2fFQko+Nx+Y2ntHZIhF6DxqOWbcyNDTw=; b=ML3jzdDs9YxCEdAf6Hvo46MiAaT+6vcFOOJsOd7Vj4pzbVZ2MMeDlaQK/LO2se3LwP HawSDFiwDWpArVxyZEW6lZEgWHF2ZodVsd+ybHRQJfn+m7E2sZpoTa78ZkRoEPfZMnSi mtJKiFpVbsIaZb45VV+ZxPAV4tN5kS75tRi5P9I3wSVh5FoKlBNWH6mk2qYcTc8rtq0A /Np0QMpnEunrS0d9FdOeD8xPkBngp2L67mHNejAlb2twfxTqc8Gl7YCgpGuiZnscTPv8 Xilh3SeujiDUutoUtZUgfhlc42PsXXamIu5YxKtDOAbFX5fzjfyQxkOaaTTHrLpKsfky Fltg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="aPuvZJC/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a637146000000b0041bc27b1bd5si15376602pgn.462.2022.08.23.04.21.50; Tue, 23 Aug 2022 04:22:01 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="aPuvZJC/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354635AbiHWK0B (ORCPT + 99 others); Tue, 23 Aug 2022 06:26:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353644AbiHWKLr (ORCPT ); Tue, 23 Aug 2022 06:11:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF3F14F1BD; Tue, 23 Aug 2022 01:57:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C78F6123D; Tue, 23 Aug 2022 08:57:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46741C433C1; Tue, 23 Aug 2022 08:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245074; bh=5QEhkpbOIt5ZQhJj4twQe+roC+RNayxcEOZD8bg916A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aPuvZJC/NO7OHNpcFfLLLDQ3XvSZsAlJm/Pqw7fxfPeTUECx4rekPvgyuQZUdK8eo 4A5+aC9WO7JctGIlxHyilf3q8+rqmjR9ojeHIKmuUoV8QdeE3ZH4dfFdbf0xUw2kj4 vJklpbP3FfEt3B0k+JkI5tsP0OZ/GCTNVldsrRys= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Steven Rostedt , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 206/244] lib/list_debug.c: Detect uninitialized lists Date: Tue, 23 Aug 2022 10:26:05 +0200 Message-Id: <20220823080106.380597402@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Guenter Roeck [ Upstream commit 0cc011c576aaa4de505046f7a6c90933d7c749a9 ] In some circumstances, attempts are made to add entries to or to remove entries from an uninitialized list. A prime example is amdgpu_bo_vm_destroy(): It is indirectly called from ttm_bo_init_reserved() if that function fails, and tries to remove an entry from a list. However, that list is only initialized in amdgpu_bo_create_vm() after the call to ttm_bo_init_reserved() returned success. This results in crashes such as BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 1 PID: 1479 Comm: chrome Not tainted 5.10.110-15768-g29a72e65dae5 Hardware name: Google Grunt/Grunt, BIOS Google_Grunt.11031.149.0 07/15/2020 RIP: 0010:__list_del_entry_valid+0x26/0x7d ... Call Trace: amdgpu_bo_vm_destroy+0x48/0x8b ttm_bo_init_reserved+0x1d7/0x1e0 amdgpu_bo_create+0x212/0x476 ? amdgpu_bo_user_destroy+0x23/0x23 ? kmem_cache_alloc+0x60/0x271 amdgpu_bo_create_vm+0x40/0x7d amdgpu_vm_pt_create+0xe8/0x24b ... Check if the list's prev and next pointers are NULL to catch such problems. Link: https://lkml.kernel.org/r/20220531222951.92073-1-linux@roeck-us.net Signed-off-by: Guenter Roeck Cc: Steven Rostedt Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- lib/list_debug.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/list_debug.c b/lib/list_debug.c index 5d5424b51b74..413daa72a3d8 100644 --- a/lib/list_debug.c +++ b/lib/list_debug.c @@ -20,7 +20,11 @@ bool __list_add_valid(struct list_head *new, struct list_head *prev, struct list_head *next) { - if (CHECK_DATA_CORRUPTION(next->prev != prev, + if (CHECK_DATA_CORRUPTION(prev == NULL, + "list_add corruption. prev is NULL.\n") || + CHECK_DATA_CORRUPTION(next == NULL, + "list_add corruption. next is NULL.\n") || + CHECK_DATA_CORRUPTION(next->prev != prev, "list_add corruption. next->prev should be prev (%px), but was %px. (next=%px).\n", prev, next->prev, next) || CHECK_DATA_CORRUPTION(prev->next != next, @@ -42,7 +46,11 @@ bool __list_del_entry_valid(struct list_head *entry) prev = entry->prev; next = entry->next; - if (CHECK_DATA_CORRUPTION(next == LIST_POISON1, + if (CHECK_DATA_CORRUPTION(next == NULL, + "list_del corruption, %px->next is NULL\n", entry) || + CHECK_DATA_CORRUPTION(prev == NULL, + "list_del corruption, %px->prev is NULL\n", entry) || + CHECK_DATA_CORRUPTION(next == LIST_POISON1, "list_del corruption, %px->next is LIST_POISON1 (%px)\n", entry, LIST_POISON1) || CHECK_DATA_CORRUPTION(prev == LIST_POISON2, -- 2.35.1