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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F3F3C433EF for ; Wed, 17 Nov 2021 22:26:01 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0240361B5F for ; Wed, 17 Nov 2021 22:26:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0240361B5F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BsgweLMfbevelBs8Ah94VMX16pbChVGB8jzMOwPFc8A=; b=A2Wp1HV//ugCHu dngEsvbw61fNh8PpJ7ZrGongtnPDjpjiCRg30FQ/1GrKjwFGEGj8vXUjbCIqrRFbEr6XCehOByH4/ AQR/XMGJAHBKS943I4SP6XAYMqRTDAj27QvJ3wku6hiqcZfEl82f9g8k95WwoCtKr0iX+1zB9Jz/1 WcokzfM+VlEUju6zNGOa8L/rQyRZhtgKSG6HJEz+L/RhmcNyidxZ4/CzQMxYZqRM+yIzO1mOCofJU +ISG5TSsVxk3j5quCrA7DYBtRIKMxrb00yS5BhWtVT1RtIWMhcHwJzgtbePdFZOOvXzdHxTbdy7RC V8A8/O1WfhGu6DPH0i/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnTKX-006R4c-Bx; Wed, 17 Nov 2021 22:23:03 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnT04-006NgC-UM for linux-arm-kernel@lists.infradead.org; Wed, 17 Nov 2021 22:01:54 +0000 Received: by mail-pg1-x529.google.com with SMTP id 200so3483051pga.1 for ; Wed, 17 Nov 2021 14:01:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NrftdzRJB+iZXhfybj3wXjLC5DBwV9iU14DUg7paL24=; b=eBLjeWMGVqkF82f+ZTunl/5cPTL6s9LC1GIM2m29eHFzvFNKcBpgZYcng81TfXgUyt 2Sk/PCTAChxnm4vANMcdfsEayCJ2EUOmPIIkJEwV2q67UPGWVq+c14pvSbyxVvy9LbPV FdxyxiAIRDJF4rof3OAUXlmdML5i9wTxnKiSw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NrftdzRJB+iZXhfybj3wXjLC5DBwV9iU14DUg7paL24=; b=d19NFWfHjMEkOE/Oy/5+nlLvdbx7sLAVr9HZiEuDE1ry/B9LKQssSnEraUlKmL8+pH KZERU4YjJ8Igh1yjHt8BN82SMaieJUUqvSSN8R99I/kJAb93rc8zc2zfWUQ6GPDV6QcF XH5xlGmPhmDlRzFWSIt/DFWDxHf0v55pcpnKOexnexB5rbyiO+JbQgPiq3fKowisl0C+ aXxQXrsgKx5/zjf5sfGttB3dhq8beHA1dKc4vLiE1QNLv7yCXgB4XHTn3JBNJO78kxQ1 WxXvl+ZUjoNoJHkekHrSY74cEoe49kAsN+ohyeCWjQ+HbykO3Z5G7Rrqa9YHkW+M7wpd 9xHA== X-Gm-Message-State: AOAM533mNrLbHevKBPuXZBu0/h00dXLT+/hUNG5UayHTHrO9EYg+cu3b Fs2w6nI+qRPffS9QyQVNO81bdw== X-Google-Smtp-Source: ABdhPJytb4QuGhE0Dp5hS2yGoJ5gdfGFvXD2UKBYYQ+FwETV1QxzSJKBdU6XMk2BDAY7E94T1Ku81w== X-Received: by 2002:a63:1125:: with SMTP id g37mr7864577pgl.118.1637186511589; Wed, 17 Nov 2021 14:01:51 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q18sm605060pfj.46.2021.11.17.14.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 14:01:51 -0800 (PST) Date: Wed, 17 Nov 2021 14:01:50 -0800 From: Kees Cook To: Takashi Iwai Cc: Dinh Nguyen , "Ivan T . Ivanov" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE Message-ID: <202111171400.618456DCE9@keescook> References: <20211117193244.31162-1-tiwai@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211117193244.31162-1-tiwai@suse.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211117_140153_050528_968FAFD0 X-CRM114-Status: GOOD ( 26.33 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Nov 17, 2021 at 08:32:44PM +0100, Takashi Iwai wrote: > When CONFIG_FORTIFY_SOURCE is set, memcpy() checks the potential > buffer overflow and panics. The code in sofcpga bootstrapping > contains the memcpy() calls are mistakenly translated as the shorter > size, hence it triggers a panic as if it were overflowing. > > This patch adds the __NO_FORTIFY define for avoiding the > false-positive crash. > > Buglink: https://bugzilla.suse.com/show_bug.cgi?id=1192473 > Signed-off-by: Takashi Iwai > --- > > I took an easier path for now, as the attempt with a foced cast > failed. If there is a better way to handle, let me know, I'd happily > resubmit. Thanks! > The way these have been fixed in the past is to declare these as char arrays (see include/asm-generic/sections.h). I'd prefer something like this (totally untested): diff --git a/arch/arm/mach-socfpga/core.h b/arch/arm/mach-socfpga/core.h index fc2608b18a0d..18f01190dcfd 100644 --- a/arch/arm/mach-socfpga/core.h +++ b/arch/arm/mach-socfpga/core.h @@ -33,7 +33,7 @@ extern void __iomem *sdr_ctl_base_addr; u32 socfpga_sdram_self_refresh(u32 sdr_base); extern unsigned int socfpga_sdram_self_refresh_sz; -extern char secondary_trampoline, secondary_trampoline_end; +extern char secondary_trampoline[], secondary_trampoline_end[]; extern unsigned long socfpga_cpu1start_addr; diff --git a/arch/arm/mach-socfpga/platsmp.c b/arch/arm/mach-socfpga/platsmp.c index fbb80b883e5d..201191cf68f3 100644 --- a/arch/arm/mach-socfpga/platsmp.c +++ b/arch/arm/mach-socfpga/platsmp.c @@ -20,14 +20,14 @@ static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle) { - int trampoline_size = &secondary_trampoline_end - &secondary_trampoline; + int trampoline_size = secondary_trampoline_end - secondary_trampoline; if (socfpga_cpu1start_addr) { /* This will put CPU #1 into reset. */ writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST); - memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size); + memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size); writel(__pa_symbol(secondary_startup), sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff)); @@ -45,12 +45,12 @@ static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle) static int socfpga_a10_boot_secondary(unsigned int cpu, struct task_struct *idle) { - int trampoline_size = &secondary_trampoline_end - &secondary_trampoline; + int trampoline_size = secondary_trampoline_end - secondary_trampoline; if (socfpga_cpu1start_addr) { writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr + SOCFPGA_A10_RSTMGR_MODMPURST); - memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size); + memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size); writel(__pa_symbol(secondary_startup), sys_manager_base_addr + (socfpga_cpu1start_addr & 0x00000fff)); > arch/arm/mach-socfpga/platsmp.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/arch/arm/mach-socfpga/platsmp.c b/arch/arm/mach-socfpga/platsmp.c > index fbb80b883e5d..d46b1af96a8a 100644 > --- a/arch/arm/mach-socfpga/platsmp.c > +++ b/arch/arm/mach-socfpga/platsmp.c > @@ -5,6 +5,9 @@ > * Based on platsmp.c, Copyright (C) 2002 ARM Ltd. > * Copyright (C) 2012 Altera Corporation > */ > + > +#define __NO_FORTIFY /* need to avoid the crash with memcpy() calls */ > + > #include > #include > #include > -- > 2.26.2 > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel