From patchwork Sun Oct 23 19:57:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 13016425 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 58456ECAAA1 for ; Sun, 23 Oct 2022 19:58:37 +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: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:In-Reply-To:References: List-Owner; bh=OV7c91BMk6PWw2RRVzIY5KNFNunqiAneEd9KzrzldAs=; b=OKRp6YEFVt9kHU PzQ+KoPLP30CvqQ92+DmGAj5s4kZ4JSWdwenXw31uaJ25t/nAJWQUuTpplMaFkGxj5ZPp+VBVs+ZN FsrOthmKL0MU006q4uQIGUFR4KqiNFxcHjyakx9zma3Uos9B+aBWQe/TZ7En82Bu/cT/W8ElUEuC/ +Ctx1g32CQnmDJPhHTOJE/Ol4IgH7cpDZo5G8+ZhmwwNBc4PFEVO2SyP/q3XvzqGna3K0zYJX2pr2 7QYAA4AXfI3gjApwyIWdzSPF99p/F63WCgaZiORqxmXw1yXPon5xIEqp01ysQLWeie9dHCdnfcpNR W4Z3+rpYtAYRHbpaizkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1omh6D-00G8Rz-Sl; Sun, 23 Oct 2022 19:57:33 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1omh6B-00G8Qm-0H for linux-arm-kernel@lists.infradead.org; Sun, 23 Oct 2022 19:57:32 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 5CA55CE0F0F; Sun, 23 Oct 2022 19:57:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E233C433C1; Sun, 23 Oct 2022 19:57:19 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="RHl2LtIT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1666555036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cWtExo86QbcGU83TlxLOo9FcuH1N6ldwUMYQv/obgzc=; b=RHl2LtITdsVw3pwWJLkHF4seczWczbn1OqZH2KgVX8rAsHgRpazXCOrq6DWxZF8v07JdEL rYfXZt/bxcshHqqZ6gQx67hKQKvnEWINrE3f3cv8EeyMJbIFVA3slI1XMvvHA7FlUMfAmu DCnr6Qj7X+mef3h86QrEUvBcyodfgog= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 31711279 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 23 Oct 2022 19:57:16 +0000 (UTC) From: "Jason A. Donenfeld" To: linus.walleij@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" , stable@vger.kernel.org, kernel test robot Subject: [PATCH] soc: ux500: do not directly dereference __iomem Date: Sun, 23 Oct 2022 21:57:11 +0200 Message-Id: <20221023195711.52515-1-Jason@zx2c4.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221023_125731_257933_15D6DB9D X-CRM114-Status: GOOD ( 13.42 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Sparse reports that calling add_device_randomness() on `uid` is a violation of address spaces. And indeed the next usage uses readl() properly, but that was left out when passing it toadd_device_ randomness(). So instead copy the whole thing to the stack first. Fixes: 4040d10a3d44 ("ARM: ux500: add DB serial number to entropy pool") Cc: Linus Walleij Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/202210230819.loF90KDh-lkp@intel.com/ Reported-by: kernel test robot Signed-off-by: Jason A. Donenfeld --- Untested, but hopefully correct. drivers/soc/ux500/ux500-soc-id.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/soc/ux500/ux500-soc-id.c b/drivers/soc/ux500/ux500-soc-id.c index a9472e0e5d61..27d6e25a0115 100644 --- a/drivers/soc/ux500/ux500-soc-id.c +++ b/drivers/soc/ux500/ux500-soc-id.c @@ -167,20 +167,18 @@ ATTRIBUTE_GROUPS(ux500_soc); static const char *db8500_read_soc_id(struct device_node *backupram) { void __iomem *base; - void __iomem *uid; const char *retstr; + u32 uid[5]; base = of_iomap(backupram, 0); if (!base) return NULL; - uid = base + 0x1fc0; + memcpy_fromio(uid, base + 0x1fc0, sizeof(uid)); /* Throw these device-specific numbers into the entropy pool */ - add_device_randomness(uid, 0x14); + add_device_randomness(uid, sizeof(uid)); retstr = kasprintf(GFP_KERNEL, "%08x%08x%08x%08x%08x", - readl((u32 *)uid+0), - readl((u32 *)uid+1), readl((u32 *)uid+2), - readl((u32 *)uid+3), readl((u32 *)uid+4)); + uid[0], uid[1], uid[2], uid[3], uid[4]); iounmap(base); return retstr; }