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=-12.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 F28F1C2B9F7 for ; Tue, 25 May 2021 00:54:29 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B683E61415 for ; Tue, 25 May 2021 00:54:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B683E61415 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F227882EA6; Tue, 25 May 2021 02:54:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="fLpGTkkT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C964982ED1; Tue, 25 May 2021 02:54:23 +0200 (CEST) Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0ECF082D13 for ; Tue, 25 May 2021 02:54:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-qk1-x72f.google.com with SMTP id i5so21638033qkf.12 for ; Mon, 24 May 2021 17:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nYvUPAK8mNOm4eMSnfVsgQSIJQCOtQVxbTMsIHWOVas=; b=fLpGTkkT8q4GfJYKtYt3QEMMd4hI3Rsp8rx4Za8pIeBgHGM0EdfEbnlHbik9NU9l3u mkkpvJE9nVUmqhQ9b0M55d5oACo1Kn/EogvpXhW+4kskSwTCGbsMUnOGNtxrmLr3tbta 88JcvrSYCp0SVIq7Vd2xx9rA0GXeSrWpJwN9Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=nYvUPAK8mNOm4eMSnfVsgQSIJQCOtQVxbTMsIHWOVas=; b=nWAOW+XMytJLqdfpwraOxU0SM708IVdVRXHdT9HYFx37J8Bkc6+NaVxn8Utzs+baJl jgqn7ieC+9cbgxP2ORNMrLvqrAG60HwwGceUqPyaIkPmqutMeaOn+QVzkiIOC4vqSzw/ fRH++1ozOPobqOe2y16hp16MG9KTwP1hbsMvst9JZojyZt1WslWPm5aoGY1xvshhj/RT 37a9+wIjJFUDIC3Bs6jIembj/wWyenXtQZgT0fq3LFP4Xj1hrb6pyT0Uxe2qJV7HhBqL hYjbjGqT6xlW4gCzlPa6Hj8wJ74hC9dbXaEd2zWoh2MfWhpMwxMIskTXHxFQLgurYu9t 62ig== X-Gm-Message-State: AOAM5321mF3v8ePYQ0WuPSCQnanwfa2sSW3r92RuZIeVbQI5anDdjoc8 uER244Yz2sNbB3dkkKjvSGirKw== X-Google-Smtp-Source: ABdhPJxYCU4okqyhXT36BjK7D/HK4xLvzyX4RvkxqdfxlApcGQh5vuyXS/W/zN6yFsz2BTVA7ram8g== X-Received: by 2002:ae9:c019:: with SMTP id u25mr9527612qkk.467.1621904055752; Mon, 24 May 2021 17:54:15 -0700 (PDT) Received: from bill-the-cat (2603-6081-7b01-cbda-5ce8-9acb-4a3a-47a0.res6.spectrum.com. [2603:6081:7b01:cbda:5ce8:9acb:4a3a:47a0]) by smtp.gmail.com with ESMTPSA id r3sm11916075qtu.50.2021.05.24.17.54.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 May 2021 17:54:14 -0700 (PDT) Date: Mon, 24 May 2021 20:54:12 -0400 From: Tom Rini To: Marek =?iso-8859-1?Q?Beh=FAn?= Cc: u-boot@lists.denx.de, Simon Glass , Heiko Schocher , Patrick Delaunay , Patrice CHOTARD , Miquel Raynal , Pali =?iso-8859-1?Q?Roh=E1r?= , Stefan Roese , Heinrich Schuchardt , Alexander Graf , Marek Vasut , Neil Armstrong , Ryder Lee , Adam Ford , Bin Meng , Harald Seiler , Tim Harvey , Pratyush Yadav Subject: Re: [PATCH u-boot v4 01/36] regmap: fix a serious pointer casting bug Message-ID: <20210525005412.GG17669@bill-the-cat> References: <20210520112425.25166-1-marek.behun@nic.cz> <20210520112425.25166-2-marek.behun@nic.cz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="xHtCxi0H7oMfDiXP" Content-Disposition: inline In-Reply-To: <20210520112425.25166-2-marek.behun@nic.cz> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean --xHtCxi0H7oMfDiXP Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, May 20, 2021 at 01:23:50PM +0200, Marek Beh=FAn wrote: > There is a serious bug in regmap_read() and regmap_write() functions > where an uint pointer is cast to (void *) which is then cast to (u8 *), > (u16 *), (u32 *) or (u64 *), depending on register width of the map. >=20 > For example given a regmap with 16-bit register width the code > int val =3D 0x12340000; > regmap_read(map, 0, &val); > only changes the lower 16 bits of val on little-endian machines. > The upper 16 bits will remain 0x1234. >=20 > Nobody noticed this probably because this bug can be triggered with > regmap_write() only on big-endian architectures (which are not used by > many people anymore), and on little endian this bug has consequences > only if register width is 8 or 16 bits and also the memory place to > which regmap_read() should store it's result has non-zero upper bits, > which it seems doesn't happen anywhere in U-Boot normally. CI managed to > trigger this bug in unit test of dm_test_devm_regmap_field when compiled > for sandbox_defconfig using LTO. >=20 > Fix this by utilizing an union { u8; u16; u32; u64; } and reading data > into this union / writing data from this union. >=20 > Signed-off-by: Marek Beh=FAn > Cc: Simon Glass > Cc: Heiko Schocher > Cc: Bin Meng > Cc: Pratyush Yadav Applied to u-boot/master, thanks! --=20 Tom --xHtCxi0H7oMfDiXP Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmCsSrQACgkQFHw5/5Y0 tyy4dQwAutj3WQlKKeFhU1jed81f7p1esPGnRoLPdV42BfRH9qigwmZPKDfUYTBZ wCEefpiyhPdH6jTyOp7ivDBhUN0qSq3RXhd8fneJjD6EPx8g2lI71lwl2wmQJBWS SKm1b0xODyejHM4SJHyz4Lv8QJ09l3eg2c2R88kPpoFnhJTw/Pw5XOsttKNFE1cQ EF+UwaUT+s9KkvnMGafnarK5X81XRObBPVbwqu1ZC7z/44s8XtBCCYFVqy7b6van jXdipBIxpdFPXmSY7T0NNfEr5+O48QWqjC8/5wvZqGdJImJBxln/M0S1vDKIo6pQ I3by+m5Ykehg2UYT4Znoefx5D0x+wfVJEnJXD18QMq+DhICEcxdb93KxvGp5N8/3 JTMwFVNJwt/1rfz0nVLCT8APT6yjFeKhKlu0VLe7Nu5GsmjBqa5p1LCoZAIYZfVs zwoB+QRo2ZQqnR5sZLrL1iWZBZ/3A4yMovj8zuOrWs6IJjjR3focO04XHI3XeceY Y3Y4EcdI =4555 -----END PGP SIGNATURE----- --xHtCxi0H7oMfDiXP--