Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1794338rdh; Tue, 26 Sep 2023 04:00:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKUSul1iD52o3z3D6HCo3s7B/ArXl0eNDR4DG58UYn8reZ5cQq6ld0k6prEYccgHikYEib X-Received: by 2002:a05:6358:999b:b0:134:c8cb:6a00 with SMTP id j27-20020a056358999b00b00134c8cb6a00mr9610920rwb.12.1695726020161; Tue, 26 Sep 2023 04:00:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695726020; cv=none; d=google.com; s=arc-20160816; b=pSP7CZ3B0jbYh5JWHauvf3m75iXzRCwlPvXmb3CGWXiRYF467OgyuicZYwcLuSh1gC szEXp15C1TvgD0zdsWkrlzq0WZja7We+7gxSc4IDTtUlVL6OtBMbWQy9UTtpO+KhRQKZ ejrtuPOQnpHhiPIlPcL3P/jOSLDUJCKelVR2OXGIb2TdbgmimuRge1Nr91ATBFmv3XLU +3zgBhNzom6ElkR8Rwnpo7iv7Ua7stMy9zjU1ECy3voQiV4lKRoQ6NOr9eq6Vh777KcA kzK00K5oqMJBaOkIC9RGg1TKVWbFaOUQO+jk047deAb5BABiHr3NnCUlXSrbxP2x8llT S/GA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AC9zbFzLXKPuYOJNpw2kNkoiGNa6WmVnEzplbAtdNls=; fh=XUQCavePdd0QwkeIN0hRaQp1gkkEgf/2VNbqW1H2m1E=; b=EhIHoxglPPllzsuWNiD4Vfhj5SxjNsL3Jqz3gKUf8Tt84eaH1dvK3AnLDBPuAzgMP/ ub/Zzqirw6q69rm7RWdIvK+LX3uuUlwkDFtWgGnOxI+IeP04BTbYaZuHfxQ3lr51EZVZ eKPsSIM0YdLnyZO9qdvyQQUQN2OiQGDE0l0djzjYXFtDhptsXYC3ELxnQz+DpqmLMaCx j6X3t6wM0YQW7c+43ahs0nyyAAnxaF5q06lb+hJ+oworFvWMSOPMaYO/3FIPzz6SGQE2 LcceeLeYJvEAmMYPiSDWc3z9Y/03tQdJ1XFQvumB8313msZgoOibjNHetgRjEO6tKS5R M7VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BE6R+SjF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id i67-20020a636d46000000b005708fb8f0bbsi12575187pgc.571.2023.09.26.04.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:00:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BE6R+SjF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id A84E880E9E99; Tue, 26 Sep 2023 04:00:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234495AbjIZLAI (ORCPT + 99 others); Tue, 26 Sep 2023 07:00:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbjIZLAG (ORCPT ); Tue, 26 Sep 2023 07:00:06 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4846EE5; Tue, 26 Sep 2023 03:59:58 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6910ea9cca1so6358647b3a.1; Tue, 26 Sep 2023 03:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695725998; x=1696330798; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AC9zbFzLXKPuYOJNpw2kNkoiGNa6WmVnEzplbAtdNls=; b=BE6R+SjFYT3gY/GURiK/jTTE1acczdwE9k10jVpMUnyDLEx3CS5SH325OKuW9WNVlD WNhxkJVF7ya4Hwzx48dkF2RFU9YRty21QQAxokg+NTPC54b7uz9F1Iw4bY5HS2igr+Xw XBjos2G8soQoEJF/WYQINTYOIBSonhBOVLc/w81SK6mmn1pM9V8DWOYzZgjL4xs1GNHf VhywI4wjZYhAdxlalH/kRoLA8IvO+G8yuhGScW3qDZzv4YLIVfzV26el2ejoLEHypQUL LyzZ7KtkiVVbXaQKs+xj3jxoDzmBih0qopfhVx3xPbqpgXX4kjbhM+obYW2AQPjck/Oi n9DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695725998; x=1696330798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AC9zbFzLXKPuYOJNpw2kNkoiGNa6WmVnEzplbAtdNls=; b=fhxEwtPuNxSaet2fhCUBwe0017Lj9eMDhoqpxRluPTpG7/LsiC7+WAaROm/8blj9SP WhayVYOK30pQxJU0bLV13iBVJltFLlP8bxwUpOvSbGQv7qj9hL5twK+FNOkg314SqwMw EJ+Gbfimi/CWdgX80EHcMOKTaWfciq62Q3XlN5jcg9d06nhOfZppAomQN7jwzbE4xvvz H4Ab3mrY8vMZO/l/LCDfMFgjuFW/t7eT0oQAirMCmD+mRj9BV/R8vds6yccHQ6cO3Bbw 8PYsvYgmEQmbidILfi+Tli/GXTt/lUvQj1k2Y8Y0fJQbt9Q6ffmv/o8sZ93SMpRDcbes kj6w== X-Gm-Message-State: AOJu0YyKXFVEpdyhJatOiavrS996q2OtJWKOXd3E9oPzOwOcK3mGgawT wIIVNMuDDprUe7sk5WJ4eYM= X-Received: by 2002:a05:6a00:4683:b0:692:cede:c902 with SMTP id de3-20020a056a00468300b00692cedec902mr4844980pfb.9.1695725997687; Tue, 26 Sep 2023 03:59:57 -0700 (PDT) Received: from pek-lxu-l1.wrs.com ([111.198.228.56]) by smtp.gmail.com with ESMTPSA id f9-20020a639c09000000b005781e026905sm9176996pge.56.2023.09.26.03.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 03:59:57 -0700 (PDT) From: Edward AD To: syzbot+8d2757d62d403b2d9275@syzkaller.appspotmail.com Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: [PATCH] riscv: fix out of bounds in walk_stackframe Date: Tue, 26 Sep 2023 18:59:50 +0800 Message-ID: <20230926105949.1025995-2-twuufnxlz@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <0000000000000170df0605ccf91a@google.com> References: <0000000000000170df0605ccf91a@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 26 Sep 2023 04:00:07 -0700 (PDT) Increase the check on the frame after assigning its value. This is to prevent frame access from crossing boundaries. Reported-and-tested-by: syzbot+8d2757d62d403b2d9275@syzkaller.appspotmail.com 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; -- 2.25.1