From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC7D73769F6 for ; Tue, 16 Jun 2026 03:05:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781579115; cv=none; b=ieISSV9THU1O7cjoWajO5WjIHSDRwzmSDoHppN7i69ddJWID0DFDOlC1PBScXNXY+tq6tt+NPy3gJMhAMykiNqd7L0jWn4wuIC4R5EoKnU4zxdvGNqJHP+O/O62Vkwq+CpAulFxAmOp269QDAWchXeRhhPHG9OWKBaoig0YZH5I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781579115; c=relaxed/simple; bh=7QMHTyvpE/+C/oZNtfh61calEjeb6Fbl4mK1bOZVSms=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LOs5vAzp2UYwAaBltOieW05LzPziggtRX9RZOw6xNYZP9HDtxcHZcwQ5/lumHaeaih9/yieW774wyTeYqAI6HzsLMjfTa/oT2FJJmCvi7KmsIiv0BiAY+X+AvOotoEWebLA24gAxDILIa7ojuTWJp7OZSu+gQkBV14eEkqRbw4Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UE6gvTCy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UE6gvTCy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6231B1F000E9; Tue, 16 Jun 2026 03:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781579114; bh=lcN1Rfl7aDSj0DZ5HyYtJgZFzJ29ICvABy26jIqS94M=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=UE6gvTCyfVo/gJA86Vkg5VetDrNwz24PcbzvCouVlWuiWZ1NX8UGiHJlqma9E2V6k KyH5j1ONpSLfsbrdHZCqmPaCtF/Z/HxkCNs4TvUUe4jsaUNMmD4G7dOw8adGc0WpmM +J10ZZx/R4sElYXo/KTDjGwZd4kV4tVxhK4YKHuVgompm/YS6eEV7x0AhXWKprv9ns yFpFEf9Q+VsHevakDjI2YS4T/xWgfHvJEE0vGHEFLX9PM2NhPhOfuuSXgol6NvlXa/ mE9ctPV/EoQlahFPkqJWEvhNkYkwLwxAHFAWVsron2w7pImq5VCrWRjTcNaWWGHpSq m57PIGpSPcOgQ== Message-ID: <77749c92-ac8a-4074-bb59-59dbbd3d84f2@kernel.org> Date: Tue, 16 Jun 2026 13:05:09 +1000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] riscv: hwprobe: Avoid uninitialized read in hwprobe_get_cpus() To: Mark Harris , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20260612045502.70850-1-mark.hsj@gmail.com> Content-Language: en-US From: Michael Ellerman In-Reply-To: <20260612045502.70850-1-mark.hsj@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/6/26 2:55 pm, Mark Harris wrote: > When cpusetsize < cpumask_size(), hwprobe_get_cpus() did not fully > initialize its copy of the cpu mask, which could cause non-deterministic > results from the riscv_hwprobe syscall on a system with more than 8 CPUs > when the supplied cpu mask is empty. Address this by fully initializing > the cpu mask. > > Signed-off-by: Mark Harris > --- > arch/riscv/kernel/sys_hwprobe.c | 1 + > 1 file changed, 1 insertion(+) This should have a fixes tag, I think it's: Fixes: e178bf146e4b ("RISC-V: hwprobe: Introduce which-cpus flag") > diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c > index 1659d31fd288..caf6762427c8 100644 > --- a/arch/riscv/kernel/sys_hwprobe.c > +++ b/arch/riscv/kernel/sys_hwprobe.c > @@ -450,6 +450,7 @@ static int hwprobe_get_cpus(struct riscv_hwprobe __user *pairs, > if (cpusetsize > cpumask_size()) > cpusetsize = cpumask_size(); > > + cpumask_clear(&cpus); > ret = copy_from_user(&cpus, cpus_user, cpusetsize); > if (ret) > return -EFAULT; cpus is on the stack, and is copied back out at the end of the function, so this looks like it could be a stack info leak. But the copy back is also bounded by cpusetsize, so in fact there is not any leak of uninitialised stack out to userspace: ret = copy_to_user(cpus_user, &cpus, cpusetsize); if (ret) return -EFAULT; Reviewed-by: Michael Ellerman cheers