Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3091483rdh; Thu, 28 Sep 2023 02:13:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvlUy5+cwok0f5FW6nVhXZo26zYOat3TrA32UsLfP67la5OHmzn6XtVlXy8ykaScXKIixz X-Received: by 2002:a17:902:d510:b0:1bb:fcb9:f85 with SMTP id b16-20020a170902d51000b001bbfcb90f85mr1055757plg.32.1695892397600; Thu, 28 Sep 2023 02:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695892397; cv=none; d=google.com; s=arc-20160816; b=B+WNWl5nBLXzonsGpVHBHhE0KNggAD7oCbrF+qvlrFrM20p0AohEcXWJh5/suQUL6e UuEmeNmUqzeADQCbS9i6OgDHzwaL3fNNvEfkiMI8B+2XZhwHRRdWa6ppvzjhGiSdFBhp csnmmcaCHPOs0oZnCXWm+fiX7V4ygyWht7kd4EEtOEYnR0n5ri8u1guWovTic7+1uF84 bidTCiP4e9Ed7BEhN+RDEop50IjcmF7UjJJh7g4LPv5nggA2qdwhsULiHvFES2CY0gZK wjckuy6ypxutzRXvA4NAQWWsMaw/q5LApi1JYeFFqP0tX4tT+OewiURfeBujR+Ti4kcz G7zA== 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:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=7qZQScJJtxa5hTXilw9NIxVqW15vtTg5XhDxinj5nyk=; fh=JbAFyQRvs9JJtcLFHOKivx1telCurvVD39uk7f4/Qu8=; b=rzkPIvvos+L8U/kRVngbP8QIpvgpfQSuaWDzMR6yHOPL9kzAmRSBSHVA9RcfaSCuFh EI+iA8ikssIBKY4pAS6R7bxYk7o+JzPBirmdwxMjycorDRmhXaNKRsa6nGBWECUiGrHs 0xkKfUatjQ+ZwN9byUBzDiG9g7QVH/8RQSBNMIFoSdFTM9fJw0WwtevhCD8Hhrsp05KA pi1rqOS+dIen0HB9xB2DxEBPhlKTECD68FqsLE/MaR1ngx3P8HO0OIE655ZctUOyH8tH hWquV53exrwr471+kRuz8ETO06BSpZdHWCynxkm2Zw9t6pmGjtlakAt8UkLhyLUvUqGD 3PZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id i7-20020a170902c94700b001b9ea0f0e25si5945372pla.607.2023.09.28.02.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:13:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id AC7578024FF9; Thu, 28 Sep 2023 01:02:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231137AbjI1ICe (ORCPT + 99 others); Thu, 28 Sep 2023 04:02:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjI1ICc (ORCPT ); Thu, 28 Sep 2023 04:02:32 -0400 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 886B2BE; Thu, 28 Sep 2023 01:02:30 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 47DE240004; Thu, 28 Sep 2023 08:02:23 +0000 (UTC) Message-ID: Date: Thu, 28 Sep 2023 10:02:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] riscv: fix out of bounds in walk_stackframe To: Edward AD , conor@kernel.org Cc: syzbot+8d2757d62d403b2d9275@syzkaller.appspotmail.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, syzkaller-bugs@googlegroups.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, guoren@kernel.org, alexghiti@rivosinc.com, liushixin2@huawei.com, linux-riscv@lists.infradead.org References: <0000000000000170df0605ccf91a@google.com> <20230926114343.1061739-2-twuufnxlz@gmail.com> Content-Language: en-US From: Alexandre Ghiti In-Reply-To: <20230926114343.1061739-2-twuufnxlz@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-Sasl: alex@ghiti.fr X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 01:02:43 -0700 (PDT) Hi Edward, On 26/09/2023 13:43, Edward AD wrote: > Increase the check on the frame after assigning its value. This is to prevent > frame access from crossing boundaries. > > Closes: https://lore.kernel.org/all/20230926105949.1025995-2-twuufnxlz@gmail.com/ > Fixes: 5d8544e2d007 ("RISC-V: Generic library routines and assembly") > Reported-and-tested-by: syzbot+8d2757d62d403b2d9275@syzkaller.appspotmail.com > Link: https://lore.kernel.org/all/0000000000000170df0605ccf91a@google.com/T/ > Signed-off-by: Edward AD > --- > arch/riscv/kernel/stacktrace.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c > index 64a9c093aef9..53bd18672329 100644 > --- a/arch/riscv/kernel/stacktrace.c > +++ b/arch/riscv/kernel/stacktrace.c > @@ -54,6 +54,8 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, > break; > /* Unwind stack frame */ > frame = (struct stackframe *)fp - 1; > + if (!virt_addr_valid(frame)) > + break; > sp = fp; > if (regs && (regs->epc == pc) && (frame->fp & 0x7)) { > fp = frame->ra; virt_addr_valid() works on kernel linear addresses, not on vmalloc addresses, which is the case hereĀ  (0xff20000006d37c38 belongs to the vmalloc region: see https://elixir.bootlin.com/linux/latest/source/Documentation/riscv/vm-layout.rst#L125). So this fix can't work. I'm a bit surprised though of this out-of-bounds access since CONFIG_FRAME_POINTER is enabled, so there may be a real issue here (the console output is horrible, lots of backtraces, which is weird), so it may be worth digging into that. Thanks, Alex