From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F4A8C369AB for ; Tue, 22 Apr 2025 02:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kqxW7W7g0GMxiK4VTGtAR0yJCw7tFAENT/l4+8R8py4=; b=D+4EicJNSRUwlT qymBf3939rDvDxZfpuftoLiwM1kHMqa1MvPg5ThLeMVkyxpvvxFTqHY5L80ESwF/M6i112d7ETA7F F71uB/O9V67y1SYoGiX19BM4RTUrS+sHx4ZdnJ58YC7V9Ct55OgZUeEQ82nWYV5/SDofY+TfqmYNI TgE06qPQd7TTkMcQS2sn8a43XDRR7s3auc2cIWLtseR7Zx0URVJNOZE+ovok2+svy7VHvXCAScsTD JhjanDq6lh8+AaWlfvuAVps6gb1kCcv7hz4ENAlzEM819PVoErt9KSRA9H2A2BME7RWmfoKHmmiMW v6BR/eiaGFpGBNhTQWHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u73bc-00000005fkF-1Vtb; Tue, 22 Apr 2025 02:43:28 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u73Dh-00000005ZoR-3hVS for linux-riscv@lists.infradead.org; Tue, 22 Apr 2025 02:18:49 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 51A115C5A92; Tue, 22 Apr 2025 02:16:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0040C4CEE4; Tue, 22 Apr 2025 02:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745288325; bh=zUWHg3M5/7e6/OE5DILVPOKMNGSQopFKWdCPK6kJ/KY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pAIXyfHENv7TwoC16YbjkPMa3byko9nGINIVU9CaqcU1zH3+X97N+rs5CKny1E4W1 lb/0fPmqobTgwgM2CI3gm7jxtTC+fQuOcffxYaVV+PltMRT2yordUVfCuU2rYWacd/ xljs5c4wA+JODjatoWUlnkMibVY0tN3S8dGxxF//YuXSaYHQqdvE74X59puKJ/s3B0 VoloaKn+BppzPLL2J0tftgD6QrXp5ybe9L/1AbISjInqJ/q99S0Kw15wK9QjJivFgO d3uy3rKNSXo9Muoz08iMiRGmElfnxZprfiR/OzNfVp7/YyE7B3DFYAYzcsxKqjXp2q ob11qhKfvGrww== 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 6.1 11/12] riscv: Avoid fortify warning in syscall_get_arguments() Date: Mon, 21 Apr 2025 22:18:25 -0400 Message-Id: <20250422021826.1941778-11-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250422021826.1941778-1-sashal@kernel.org> References: <20250422021826.1941778-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.134 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250421_191846_011258_BAFEF636 X-CRM114-Status: GOOD ( 13.30 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 384a63b86420b..8426c4510d31e 100644 --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -61,8 +61,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 int syscall_get_arch(struct task_struct *task) -- 2.39.5 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 26AD126B95A; Tue, 22 Apr 2025 02:18:45 +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=1745288325; cv=none; b=Q0Tg+uOUgUkj9RGrB75bZ15aUis5NPu+A0t+5bm8m+pDUQVHpPwB+WMppgQC3i5e6OMmdFRU4W1SW4JubXLIRDWe8IKBgNkN5s1JuFDvgKxiCkBXqWx0kLVIQQyueFZ7tWepW+1ELF8DLix1dtcuUuhGvgvFoAgQ1Y8o0O+qlr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745288325; c=relaxed/simple; bh=zUWHg3M5/7e6/OE5DILVPOKMNGSQopFKWdCPK6kJ/KY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UwwO04SlHdOtMvotpa+P5X724S5HNEUlHoGDOiqrCwrDvO5siFS9JHsWUe0DpoEv25fuBNpYDWJsPKQdFNiYbYKiRAOUpoIRBzyLxhvRsCYOVdHjSMklsDD6jxeNcsWH5zwCf21s7GRukmHOmv7HqSFByiFw4p6QynpFWsjY3R4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pAIXyfHE; 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="pAIXyfHE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0040C4CEE4; Tue, 22 Apr 2025 02:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745288325; bh=zUWHg3M5/7e6/OE5DILVPOKMNGSQopFKWdCPK6kJ/KY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pAIXyfHENv7TwoC16YbjkPMa3byko9nGINIVU9CaqcU1zH3+X97N+rs5CKny1E4W1 lb/0fPmqobTgwgM2CI3gm7jxtTC+fQuOcffxYaVV+PltMRT2yordUVfCuU2rYWacd/ xljs5c4wA+JODjatoWUlnkMibVY0tN3S8dGxxF//YuXSaYHQqdvE74X59puKJ/s3B0 VoloaKn+BppzPLL2J0tftgD6QrXp5ybe9L/1AbISjInqJ/q99S0Kw15wK9QjJivFgO d3uy3rKNSXo9Muoz08iMiRGmElfnxZprfiR/OzNfVp7/YyE7B3DFYAYzcsxKqjXp2q ob11qhKfvGrww== 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 6.1 11/12] riscv: Avoid fortify warning in syscall_get_arguments() Date: Mon, 21 Apr 2025 22:18:25 -0400 Message-Id: <20250422021826.1941778-11-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250422021826.1941778-1-sashal@kernel.org> References: <20250422021826.1941778-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.134 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 384a63b86420b..8426c4510d31e 100644 --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -61,8 +61,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 int syscall_get_arch(struct task_struct *task) -- 2.39.5