Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp315673rdb; Fri, 6 Oct 2023 04:38:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOxGdzdMQyhHBAm3UWdpfjO9gSGMHF0bzJsIfoPPQjFr5rvko4P9i3ZJsjCo5It2Dux7SY X-Received: by 2002:a17:903:22d0:b0:1c3:62c4:7f12 with SMTP id y16-20020a17090322d000b001c362c47f12mr9355283plg.5.1696592310550; Fri, 06 Oct 2023 04:38:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696592310; cv=none; d=google.com; s=arc-20160816; b=JlLLB2b6jwedIYMI4vBAhiLg0ATWhcuFqCyjo4sstdUB1pWRDMZvb3qyfJ4xPFq/SN zPvnveaqCvHP6bUVzcb9sVSIeN0UWenHOyqgOTMjKjn3cXm6+glKwsj6hTBRY7wjR7lF L0kMfM0L95x6PJcnWeNBaivvdnlXzV1k3HbFT+ifBYBErxGAtUkDQnk1+w9HQNklOCq7 R9/op6TC+rNpXYEjkjLs9NSjBo18yJ2s8EaTb6uM98BFsc9tCb8gHlDmrtJq2yfe24bC M6Uj37njgezSImnt32n/UUGT4hP0fUspqmI7TF+ZRvr6dHPGRTuCmVuMRmwOG6opueOU iqWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id; bh=9q2QBsXuqStEi4QFqE+AYeDbRHr+zL2kg+vGfF3tYrM=; fh=46eNr5dHdLqJA96YXnblCGsZIMvXvuRqsVJ9RO1OJaw=; b=UIFa9y1G8D7Mk8ZM4BblVVBaeJjH2IAVmi2u9Cb5xJGOOfB3c1H9wjMUJisTldgs/O VDOwuOnpXLuO8MvXVtZBQ7RUFCtjmMWRI2DpSMI88xXnUyVfZ+3qcLduPdlDyX+13A7n fovYvLfEMq2NLfQT5LwHT8zpIEfOzuAkfGtemKrO+1VemZqchW74/PxYLUmk0MbTznu8 uOhIkZYnI6OSFz0KQ4BrAJxFNotwMdNljewvxQq9FNmJuMyv5VCiCrxPCke/vcut89lB K1VID8kVdrHHN6mmk223uvTeZ9Ron7yYpeFHI/3GKd3f/Ann0pJj67iu1dwY6L8r7MDw WpPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l20-20020a170902e2d400b001b9eb5d1ea2si3379892plc.198.2023.10.06.04.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 04:38:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DCD3D802891A; Fri, 6 Oct 2023 04:38:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232078AbjJFLiS (ORCPT + 99 others); Fri, 6 Oct 2023 07:38:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbjJFLiR (ORCPT ); Fri, 6 Oct 2023 07:38:17 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C38283; Fri, 6 Oct 2023 04:38:15 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1E7A3E0010; Fri, 6 Oct 2023 11:38:05 +0000 (UTC) Message-ID: Date: Fri, 6 Oct 2023 13:38:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Alexandre Ghiti Subject: Re: [PATCH] Test for riscv fixes To: Mark Rutland , Alexandre Ghiti Cc: Edward AD , aou@eecs.berkeley.edu, conor@kernel.org, gregkh@linuxfoundation.org, guoren@kernel.org, jirislaby@kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, liushixin2@huawei.com, palmer@dabbelt.com, paul.walmsley@sifive.com, syzbot+8d2757d62d403b2d9275@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com References: <20230929230549.45206-2-twuufnxlz@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-Sasl: alex@ghiti.fr X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 06 Oct 2023 04:38:28 -0700 (PDT) X-Spam-Level: ** Hi Mark, On 02/10/2023 15:41, Mark Rutland wrote: > On Mon, Oct 02, 2023 at 09:13:52AM +0200, Alexandre Ghiti wrote: >> Hi Edward, >> >> On Sat, Sep 30, 2023 at 1:06 AM Edward AD wrote: >>> Hi Alexandre, >>> >>> On Fri, 29 Sep 2023 10:25:59 +0200 Alexandre Ghiti wrote: >>>> I'm still not convinced this will fix the kasan out-of-bounds >>>> accesses, the page can be valid but the read can happen at an offset >>>> not initialized and trigger such errors right? I still think there is >>>> something weird about the stack frame, as to me this should not happen >>>> (but admittedly I don't know much about that). >>> The added check can confirm that the physical page is invalid (whether it is a >>> vmalloc allocated page or a slab allocated page), and exit the for loop when it is invalid. >> Yes, but to me this is not what happens in the bug report you link: >> >> | BUG: KASAN: out-of-bounds in walk_stackframe+0x130/0x2f2 >> arch/riscv/kernel/stacktrace.c:59 >> | Read of size 8 at addr ff20000006d37c38 by task swapper/1/0 >> >> So the read at address ff20000006d37c38 is not "normal" according to >> KASAN (you can see there is no trap, meaning the physical mapping >> exists). >> >> | The buggy address belongs to the virtual mapping at >> | [ff20000006d30000, ff20000006d39000) created by: >> | kernel_clone+0x118/0x896 kernel/fork.c:2909 >> >> The virtual address is legitimate since the vma exists ^ >> >> | The buggy address belongs to the physical page: >> | page:ff1c00000250dbc0 refcount:1 mapcount:0 mapping:0000000000000000 >> index:0x0 pfn:0x9436f >> >> And the physical page also exists ^ >> >> So I insist, checking that a physical mapping exists to exit the loop >> is not enough, to me, the error here is that the backtrace goes "too >> far" at an address where nothing was written before and then KASAN >> complains about that, again, we don't take any page fault here so it's >> not a problem of existing physical mapping. > Yep! > > I believe what's happening here is one task unwinding another (starting from > whatever gets saved in switch_to()), and there's nothing that prevents that > other task from running concurrently and modifying/poisoning its stack. In > general trying to unwind a remote stack is racy and broken, but we're stuck > with a few bits of the kernel tryingto do that occasionally and so the arch > code needs to handle that without blowing up. Thanks for that, I had already fixed the "imprecise" unwinder (when we don't have a frame pointer) using READ_ONCE_NOCHECK() but I had not this use case in mind, so I'll fix that too. > For KASAN specifically you'll need to access the stack with unchecked accesses > (e.g. using READ_ONCE_NOCHECK() to read the struct stackframe), and you'll > probably want to add some explicit checks that pointers are within stack bounds > since concurrent modification (or corruption) could result in entirely bogus > pointers. > > I *think* that we do the right thing on arm64, so you might want to take a look > at arm64's unwinder in arch/arm64/kernel/stacktrace.c, > arch/arm64/include/asm/stacktrace.h, and > arch/arm64/include/asm/stacktrace/common.h. And I'll check that for the stack bounds check. Thanks again, Alex > > Mark.