Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2644051rwb; Mon, 3 Oct 2022 03:52:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7PzqMlEhUX1TVqWLt2aL80Ou1XVw1rpr5Q5hhnNdhR1Y0wDZU3H2sStxoshdYF1DSqVDwo X-Received: by 2002:a63:f010:0:b0:446:13df:7018 with SMTP id k16-20020a63f010000000b0044613df7018mr9135145pgh.546.1664794370286; Mon, 03 Oct 2022 03:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664794370; cv=none; d=google.com; s=arc-20160816; b=MMz69krbZNhQvwDG16GxLuVmfxeyauQf1XSuQE+izfz1PAQxS2Dmog/BXKkadkyFD1 RnxPapYtRF68M27H6MxzSimeidWCFDvz4YtRqthJ7Z9epS800Hi5cbcvva7AxcPu1hz2 MvwXLZlMVH3O7ep2Lbs6N5argDQbAA2YCTm45cfcx3lMz3SSpyeBVJpiRa74VnxEGqm+ L22okinwKPGHZ11l7qq/bCzZ9G8pbbsB/NWEE7r5X9UgMgdyl6QY6IeAQ0J1niwALold Y8C+eI/5Q1x001JktHG5DFQNoXACGvr0ZhBhvo/S90Uzviis5DeJjbyPQUR9tpaviR7a x5XQ== 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=ijUwNBDUvN5Bj1TGHMab76x2Lxd6joNo/8Q10h4J8zw=; b=p5msCU5+rothNZAeAlO3HuI1T0KJz2qDaEja99E2DSpEZ8ZrmdFp0qTorOovQjPiGa kVqc00U55u+5F8NTtokFYgGclMKpKKN3AqSmmrTdQi+ISQm24vC9OG7SHTj8qQEb0umA Cvq39PeVe+SbnsMDbebDQUghjkPzxccKTWUtBLTuh8QAFuTeRnA7TUtwp7NkUvzTMkys kD6AXNRg28cDT9AWQ7QxdDH2cpxxTSkla7dTgE0o5jldePNE+at0cPdAG5GKLDnNpJz6 XZsrLyKg3aMc5XQANdUM8IXYLaw7v5LLo50eJxiG7nYelGJnZ+wAVne+XIKcZthMEBJL qcWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fMuZyrKB; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk17-20020a17090b4a1100b0020169c73d8bsi10146665pjb.2.2022.10.03.03.52.38; Mon, 03 Oct 2022 03:52:50 -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=@kernel.org header.s=k20201202 header.b=fMuZyrKB; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229764AbiJCKjD (ORCPT + 99 others); Mon, 3 Oct 2022 06:39:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbiJCKi5 (ORCPT ); Mon, 3 Oct 2022 06:38:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5341356EE for ; Mon, 3 Oct 2022 03:38:56 -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 ams.source.kernel.org (Postfix) with ESMTPS id 71E33B81049 for ; Mon, 3 Oct 2022 10:38:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8D63C43141; Mon, 3 Oct 2022 10:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664793534; bh=C4Vx5tvsjc4GTe+ODm+teOUMFaKT91CBKzQiLXfj2dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fMuZyrKBqrNiFoQFi+CtalwIR9BMcH8RYBA2q9Ikh+r1G+fCMFL0fy59iTweNgB+O 40MadJensyCmFJYgg2V7DGmIi0R1OdmX4SvpR2YrnHigZ5p/x1TVhl0pn+CELNambv RboGUr52C7Xp71TWbVhtIbce7ooMVP31jx57oF1CZ3wVbLPn/8c31Lr3B/r+ohOjcm e8PqHQdiRpXAoxF3W0j5fEzPto1ef7AYwcIPJ2FwXDFAdQR47430QWmq+cGEGMCS4L IGuA0A7K7BDRW6KpxrfV3WQQPVwyDNFfPOpmYbIPMS6wUuySlmfn8QRzR05K83j8WV 5M0QYkDgfjb0Q== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] riscv: process: fix kernel info leakage Date: Mon, 3 Oct 2022 18:29:18 +0800 Message-Id: <20221003102921.3973-2-jszhang@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221003102921.3973-1-jszhang@kernel.org> References: <20221003102921.3973-1-jszhang@kernel.org> MIME-Version: 1.0 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 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 thread_struct's s[12] may contain random kernel memory content, which may be finally leaked to userspace. This is a security hole. Fix it by clearing the s[12] array in thread_struct when fork. As for kthread case, it's better to clear the s[12] array as well. Fixes: 7db91e57a0ac ("RISC-V: Task implementation") Signed-off-by: Jisheng Zhang --- arch/riscv/kernel/process.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index ceb9ebab6558..52002d54b163 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -164,6 +164,8 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) unsigned long tls = args->tls; struct pt_regs *childregs = task_pt_regs(p); + memset(&p->thread.s, 0, sizeof(p->thread.s)); + /* p->thread holds context to be restored by __switch_to() */ if (unlikely(args->fn)) { /* Kernel thread */ -- 2.37.2