From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 20ADB27700D; Tue, 22 Apr 2025 02:19:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745288343; cv=none; b=i05S+FmvQixRvrJy9RfFIuDWQeEH80YJvk6bBOGVGu5gqfnh1pFd9wYb6TEHBA19En2sLAdJdpEsj+eRxlC9q9dQKfN0S4e/XL1pNGGhL1wHW0e01W/saZkBTbB+yJm9ZhGHDysKOoYG7ItTu6sBOw/6fCN+XBa7vIK78mtsjmk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745288343; c=relaxed/simple; bh=E2UZawLOB60I+5y5go5f2JrYmVaLg3aKhdQdhvtcUbk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eVPepdrUw70ggdRuNU9ulq1BWVfb7RhB8OB9XNFyjdsnZRS2yeI76krTKNjGqz+gPAsXxsf8LQIPoz7DEB36kA/zYrkNiVoV/TyxJ75edyFvcxJuk7NFCvvwxzDl5xhUDlZO7F/yiTVI07mBNClwdoQaLGliCH5SZnsvMFAailg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qhEOifXx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qhEOifXx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80522C4CEEC; Tue, 22 Apr 2025 02:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745288342; bh=E2UZawLOB60I+5y5go5f2JrYmVaLg3aKhdQdhvtcUbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qhEOifXx76BUUHN2PxJAwDbXaBuerk3jMJ0O6UjN8fZy6wOfEdQogEbTIZxrj/mGG 55SBLruHZXmAqas+un12v9TVxcZStZbZv0CuGiqgjWh1I/LUDQLGx0/Z4Io/4drPWU JbqVRa1QrRRbQCyVoQnuhMgGydgTvNmC2Dssa5GFc5lLxDNCkDcVsd/cMy1D/9LrWm urz7ipf8kGNqYnUyYDXvnFFK22qEfYixEMDa68qMQqF1ufbuIEAaNsrZ5EWnb3JhDg o4JsHfgAUBm71kFPwiopqzZg3ralMugAPdIrhaSUGd/SWcKxsWlxUxCtXLcd5f1Ld3 EPZ720ZyBroMQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nathan Chancellor , Alexandre Ghiti , "Dmitry V . Levin" , Sasha Levin , paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org Subject: [PATCH AUTOSEL 5.10 3/3] riscv: Avoid fortify warning in syscall_get_arguments() Date: Mon, 21 Apr 2025 22:18:56 -0400 Message-Id: <20250422021856.1942063-3-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250422021856.1942063-1-sashal@kernel.org> References: <20250422021856.1942063-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.236 Content-Transfer-Encoding: 8bit From: Nathan Chancellor [ Upstream commit 1413708f990cb7d025affd706ba9c23e2bfc1a27 ] When building with CONFIG_FORTIFY_SOURCE=y and W=1, there is a warning because of the memcpy() in syscall_get_arguments(): In file included from include/linux/string.h:392, from include/linux/bitmap.h:13, from include/linux/cpumask.h:12, from arch/riscv/include/asm/processor.h:55, from include/linux/sched.h:13, from kernel/ptrace.c:13: In function 'fortify_memcpy_chk', inlined from 'syscall_get_arguments.isra' at arch/riscv/include/asm/syscall.h:66:2: include/linux/fortify-string.h:580:25: error: call to '__read_overflow2_field' declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Werror=attribute-warning] 580 | __read_overflow2_field(q_size_field, size); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors The fortified memcpy() routine enforces that the source is not overread and the destination is not overwritten if the size of either field and the size of the copy are known at compile time. The memcpy() in syscall_get_arguments() intentionally overreads from a1 to a5 in 'struct pt_regs' but this is bigger than the size of a1. Normally, this could be solved by wrapping a1 through a5 with struct_group() but there was already a struct_group() applied to these members in commit bba547810c66 ("riscv: tracing: Fix __write_overflow_field in ftrace_partial_regs()"). Just avoid memcpy() altogether and write the copying of args from regs manually, which clears up the warning at the expense of three extra lines of code. Signed-off-by: Nathan Chancellor Reviewed-by: Alexandre Ghiti Reviewed-by: Dmitry V. Levin Link: https://lore.kernel.org/r/20250409-riscv-avoid-fortify-warning-syscall_get_arguments-v1-1-7853436d4755@kernel.org Signed-off-by: Alexandre Ghiti Signed-off-by: Sasha Levin --- arch/riscv/include/asm/syscall.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h index 49350c8bd7b09..9fa0729bc6696 100644 --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -60,8 +60,11 @@ static inline void syscall_get_arguments(struct task_struct *task, unsigned long *args) { args[0] = regs->orig_a0; - args++; - memcpy(args, ®s->a1, 5 * sizeof(args[0])); + args[1] = regs->a1; + args[2] = regs->a2; + args[3] = regs->a3; + args[4] = regs->a4; + args[5] = regs->a5; } static inline void syscall_set_arguments(struct task_struct *task, -- 2.39.5