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 A66CF24BD02; Tue, 29 Apr 2025 17:48:57 +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=1745948937; cv=none; b=Di86/Ppa86r82OzhPWi0MLrn5khiWdQG8FqpmkC04Bk23UAiNsXXnDvr14QHwlZ5hhVrdqTBLUpWl3rJdDuTJt3E5wyobD8GXt/FxILPFuzpGSgm8Cj7988pvbFJv9YyIScT9qXxVyIsYnQnNhKyucbzbNBoQyXndigR4g+ZAKU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745948937; c=relaxed/simple; bh=CxGXRYQxmv5PHnzpPtrRQMQBGTBszLsg8mS4CaeCPYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uYbveNQUT7PO2Y+f2cKSef2tVodWJCDtEaTNa6swFNIi9fp1MzkrtkLS21eBD2Z59eA6wVIB3SuIJjgcmA3ZQqYT8qFN1+KA/h092tw9zdV+iT5C9sRZ1ffVjvEpKvl4FT0GwGHfnOUrQvhIGQEJyHHOvCajUijMGPP7M2yc3fM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DYq2A2b+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DYq2A2b+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93CF8C4CEE3; Tue, 29 Apr 2025 17:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745948937; bh=CxGXRYQxmv5PHnzpPtrRQMQBGTBszLsg8mS4CaeCPYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DYq2A2b+S2wTvdeYaz4kXEzs4C7S/2VsceuSbrV9q5wDDi2lYB1HfKlP9xL9yCxCv uZMLZJ5A3Ysg07ogClNtB9ehlRfei/lbUMegRkqJ1DPiew1gBEsC06LwIKHQ+m4ucS dc1D6n1eysABea8nqkZyX+IFfnfgpp+C7VWD2a4M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nathan Chancellor , "Dmitry V. Levin" , Palmer Dabbelt Subject: [PATCH 5.15 170/373] riscv: Avoid fortify warning in syscall_get_arguments() Date: Tue, 29 Apr 2025 18:40:47 +0200 Message-ID: <20250429161130.167374919@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161123.119104857@linuxfoundation.org> References: <20250429161123.119104857@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nathan Chancellor commit adf53771a3123df99ca26e38818760fbcf5c05d0 upstream. 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: Dmitry V. Levin Fixes: e2c0cdfba7f6 ("RISC-V: User-facing API") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250409-riscv-avoid-fortify-warning-syscall_get_arguments-v1-1-7853436d4755@kernel.org Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman --- arch/riscv/include/asm/syscall.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -60,8 +60,11 @@ static inline void syscall_get_arguments 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,