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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DCA6C43603 for ; Tue, 17 Dec 2019 10:28:58 +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 DC54220716 for ; Tue, 17 Dec 2019 10:28:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cLoMq0Gy"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="Mpu/CQwP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC54220716 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject: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=vKX1kp6X+eqFdXCb4ZlWc+iRdWDKzRBJDs/jPW6MJoA=; b=cLoMq0Gy7iXg27 14sjuhKHAysnLAwRhDyPjxl8Vkwy+vV3QyOJe28NuaG+1MfH8/fpWiyB/hhttX31EDffRPQgAmJy4 MmfWkHPwWsG5mr8f4P0zZOb++tDGqhqnNHJdKYq1SWRQOYqQU+s9EiczluCcC/Ie1OF8eJtx939vz pfVUa0EvT15GAOYD6knpeDOWyEfJ14dHI+Uqz+ma1LmKaGaMnwkw3cEtVw7sWLl88BWOqgXl6g3lU IZtxrrvKh1fS7WTntcJDIjNqqOfnVlC+ppWfMR4IdVEv87ZH0KenPA0iZbWRANoy2tysrNFnm0waN 8lthdKc6BmOKPlZxrTLg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ihA62-00017L-Sm; Tue, 17 Dec 2019 10:28:54 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ihA5y-00015y-Cf for linux-arm-kernel@lists.infradead.org; Tue, 17 Dec 2019 10:28:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xIsVCSCddGcBczzhrJmpWdldvcvD8/SOoTohcqfDdpc=; b=Mpu/CQwP505C8biFNOIztuq5H RtEPYQbkrn288Xfq4TohizM2O4bz7zIrNfn3c8ST3u+aEsIkzbBO1wXLiCanTbMxTeihL7x4uRdzQ 2d9Kz0AvwC1Qrihh/ZBP1c1FMweIV/RGnSDW/GSgfW/ooLn2T+plH8ltRcjO/62630LsxyJXhBpjG PXipzJ9uizk93dUJzqUmdhyNdlGkfyiwivC6qf8/i7mv03DCiVr2CrHvNctKEXbeRpv07ZOruJhdJ 193cpkjwBS8sxOvmph3UfpU7J++zH9R9NH4IkEiTTm7L+vzn6x/MDq4SV6pDDqm2SGuotgBhSiHW7 gnMQEQL9w==; Received: from shell.armlinux.org.uk ([2002:4e20:1eda:1:5054:ff:fe00:4ec]:50030) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ihA5j-0005M5-7h; Tue, 17 Dec 2019 10:28:35 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1ihA5f-0003KB-Ca; Tue, 17 Dec 2019 10:28:31 +0000 Date: Tue, 17 Dec 2019 10:28:31 +0000 From: Russell King - ARM Linux admin To: Vincent Whitchurch Subject: Re: [PATCH] asm/sections: Check for overflow in memory_contains() Message-ID: <20191217102831.GP25745@shell.armlinux.org.uk> References: <20191217102238.14792-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20191217102238.14792-1-vincent.whitchurch@axis.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191217_022851_571003_964C13A1 X-CRM114-Status: GOOD ( 18.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Whitchurch , arnd@arndb.de, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, treding@nvidia.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Dec 17, 2019 at 11:22:38AM +0100, Vincent Whitchurch wrote: > ARM uses memory_contains() from its stacktrace code via this function: > > static inline bool in_entry_text(unsigned long addr) > { > return memory_contains(__entry_text_start, __entry_text_end, > (void *)addr, 1); > } > > addr is taken from the stack and can be a completely invalid. If addr > is 0xffffffff, there is an overflow in the pointer arithmetic in > memory_contains() and in_entry_text() incorrectly returns true. > > Fix this by adding an overflow check. The check is done on unsigned > longs to avoid undefined behaviour. > > Signed-off-by: Vincent Whitchurch > --- > include/asm-generic/sections.h | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h > index d1779d442aa5..e6e1b381c5df 100644 > --- a/include/asm-generic/sections.h > +++ b/include/asm-generic/sections.h > @@ -105,7 +105,15 @@ static inline int arch_is_kernel_initmem_freed(unsigned long addr) > static inline bool memory_contains(void *begin, void *end, void *virt, > size_t size) > { > - return virt >= begin && virt + size <= end; > + unsigned long membegin = (unsigned long)begin; > + unsigned long memend = (unsigned long)end; > + unsigned long objbegin = (unsigned long)virt; > + unsigned long objend = objbegin + size; > + > + if (objend < objbegin) > + return false; > + > + return objbegin >= membegin && objend <= memend; Would merely changing to: return virt >= begin && virt <= end - size; be sufficient ? Is end - size possible to underflow? > } > > /** > -- > 2.20.0 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel