Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp718050pxk; Wed, 23 Sep 2020 14:20:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlTEW10YXzO+1CWeYrA0bR/FYNe8hJIDML0wH56ufXN4bvfF9TFfCPOlqRkl77sCqmHMRL X-Received: by 2002:aa7:de82:: with SMTP id j2mr1383328edv.3.1600896026449; Wed, 23 Sep 2020 14:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600896026; cv=none; d=google.com; s=arc-20160816; b=ZRlhhQfu7zJ2jKdreXE1Fsu8cd76JRaZfR1+EZ4uQn1nPGY17bLlwjvUWkIKH/Vk0l mUROQlwDK8t7+TTBG2fFli6wNv5cd8in7URXPDue5PYlQsVCySGukYQgUaCAirFoZfTL a9Lds9IWsM5mGhZuEKEPd7uNRrk8juI+ZzyARvfan/h/Xlg+YtDbt5CYHeWkk1oG7+Dd EOLXU+uI3AiLNkWFEWkaJ02D2yUj5HNxfBG5TJSvRkfnhUJ+GUkUOx93vuXyWON0mCE0 CjD7949c4443VUjUCLwJewOxOqPXHaS9II1MdhkJggh7+j8bZS4sVEkzyQHzm4XF6JvN 8FoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:autocrypt:from :references:to:subject:reply-to:dkim-signature; bh=gT0OzoKFfMNOUHhQ2p/0QEs9umxUstEKkl3b8YIoH9I=; b=ZvXu+6Vb+2WaZGgkmMmbV+5CgYCmEjXZM5K3rNcwuOtM+o+ab1TFBUtU5HW1mQvI74 syihH1ei6jbPenxMuwAHVVZucTK48szhpMbptGFmfS4mOMmg7GIUq+GIr+1yyBvuYfll j1oe/wHvbAHZMwBlos0pOlO1MlcqLLroClTESDcU6QOrboHVtpwZAvKjnoAxFDPnFXb7 JO+zSVqkXfpRZbrI3qCd+s7iA0s/l6OGNZYyYaz8Nqk1sSxw12gSZU4Wq71lZtUAXX28 +BwjKX4zZ2oA7Rz28jSF6QfeVStkjxop8YfmD56sq7BbRXRUTGI1sqI44gmNVOLM7FBr e16g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P7LJNpq3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si677436edy.595.2020.09.23.14.20.01; Wed, 23 Sep 2020 14:20:26 -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; dkim=pass header.i=@kernel.org header.s=default header.b=P7LJNpq3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726419AbgIWVR6 (ORCPT + 99 others); Wed, 23 Sep 2020 17:17:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:52244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726199AbgIWVR6 (ORCPT ); Wed, 23 Sep 2020 17:17:58 -0400 Received: from [192.168.0.20] (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2C79521D43; Wed, 23 Sep 2020 21:17:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600895877; bh=Fv8vjLo6iV8lbW6twrAEQbbeDfVmj2mS7ucahi9brMI=; h=Reply-To:Subject:To:References:From:Date:In-Reply-To:From; b=P7LJNpq33eIqcl75C25zSbP9kRjDF/yfAVqXWLZVnDNz/R3W4wP8ehlr5tTYWYuze dlowemphyzxA3j7ZhyeIQJiqB+PxFs/xm2ujk3PgrQa86x9ZzrpwlcqHX0dDbZA/Gz St0Hqy0P1ynT3HA+ovll5OY9Gp1O05PH539DHMY4= Reply-To: kbingham@kernel.org Subject: Re: [PATCH] scripts/gdb: fix list_for_each To: George Prekas , Jan Kiszka , linux-kernel@vger.kernel.org References: <3b382958-9f1d-a3d2-a239-09ba084227e6@amazon.com> <2516a051-306f-670b-1f9e-d46fc577c7f8@siemens.com> <109fe98d-4143-cfd3-b145-8d5fee189f63@amazon.com> <25111834-a414-e380-1e61-c1b1c0e766cb@kernel.org> From: Kieran Bingham Autocrypt: addr=kbingham@kernel.org; keydata= mQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat V/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC rRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C potzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ cSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf Kr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8 RXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko lPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuett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rj48jsbEYX0YQnzaj+jO6kJto ZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8pQk3kgDu7kb/7PRYrZvB sr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXcMW8zs8avFNuA9VpXt0Yu pJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPUAfYnB4JBDLmLzBFavQfv onSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4WZw01QYHU/GUV/zHJSFk Message-ID: <0a687830-a334-60ba-7a65-f25342139e08@kernel.org> Date: Wed, 23 Sep 2020 22:17:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/09/2020 14:13, George Prekas wrote: > Hi Kieran, > > On 9/22/2020 2:11 PM, Kieran Bingham wrote: >> Hi George, >> >> On 22/09/2020 18:17, Prekas, George wrote: >>> >>> On 9/22/2020 9:32 AM, Jan Kiszka wrote: >>>> >>>> On 22.09.20 16:28, George Prekas wrote: >>>>> If the next pointer is NULL, list_for_each gets stuck in an infinite >>>>> loop. >>>>> >>>>> Signed-off-by: George Prekas >>>>> --- >>>>>    scripts/gdb/linux/lists.py | 2 ++ >>>>>    1 file changed, 2 insertions(+) >>>>> >>>>> diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py >>>>> index c487ddf09d38..424a91c1aa8b 100644 >>>>> --- a/scripts/gdb/linux/lists.py >>>>> +++ b/scripts/gdb/linux/lists.py >>>>> @@ -27,6 +27,8 @@ def list_for_each(head): >>>>>            raise TypeError("Must be struct list_head not {}" >>>>>                               .format(head.type)) >>>>> >>>>> +    if head['next'] == 0: >>>>> +        return >>>>>        node = head['next'].dereference() >>>>>        while node.address != head.address: >>>>>            yield node.address >>>> >>>> Obviously, infinite loops are bad and should be avoided. But NULL is >>>> bug, isn't it? Shouldn't we report such a corruption? >>>> >>> >>> Hi Jan, >>> >>> Is it a bug? Or does it mean that the list is empty? >> >> A correctly initialised (empty) list_head has the next, and prev >> pointers pointing to itself >> > > You are right, actually. > >> >>> Let me give some background. If you do the following: >>> >>> $ qemu-system-x86_64 -nographic -m 1024 -kernel >>> build/arch/x86/boot/bzImage -s -S < /dev/null > /dev/null & >>> $ gdb -q build/vmlinux -ex 'target remote localhost:1234' -iex 'set >>> auto-load safe-path /' -ex 'lx-symbols' >> >> I suspect this is trying to load modules before the kernel is actually >> fully loaded and running, so nothing is yet initialised. >> >> >>> You will see: >>> >>> loading vmlinux >>> scanning for modules in /home/ubuntu/linux-5.8.10 >>> no module object found for '' >>> >>> And the last line repeats forever. This happens because modules.next == >>> NULL. This is the Python stack trace: >>> >>>[...] >>> >>> This patch tries to fix the above problem. >> >> Does it fix it for you ? >> >> I expect it allows the boot process to continue, but the lx-symbols >> command will not have completed successfully (or rather I expect it will >> not have found anything to load). >> >> I suspect adding defensive checks in here might be helpful but I think >> the reality is the code is being called at the wrong time. >> >> The fact that it 'can' be called at the wrong time is where we might >> need to be more defensive. >> > > At that point in time, the kernel has not even started so it does not > have any loaded modules. In fact, as you said, the modules linked list > is uninitialized. So with this patch, lx-symbols does not get stuck in > an infinite loop and loads only the vmlinux symbols. > > Maybe, I should rephrase the commit message to say that list_for_each > gets stuck in an infinite loop on uninitialized linked lists. > > Do you think that list_for_each should handle uninitialized lists? If > yes, how do you propose to handle them? > > 1. Treat them as empty lists (this patch). > 2. Print a warning and treat them as empty lists. > 3. Raise exception and treat them as empty lists. > > I would go with option 1. For traversal purposes an uninitialized list > is the same as an empty list; it has no elements. I am happy, though, to > change the patch to another option if you believe it would be better. I would choose 2 personally. While debugging, if anyone hits an uninitialised linked-list - that's a problem they want to know about, not ignore. -- Kieran > -- > George >