Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1081349rda; Mon, 23 Oct 2023 01:38:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/YI82f2LgJq+bImQ8R2so/HwLWn1PKMBFDufbYW1+4GTAmHJotfWU/yGHC3Z191l16BNi X-Received: by 2002:a17:903:124e:b0:1c6:1ab1:93eb with SMTP id u14-20020a170903124e00b001c61ab193ebmr7012907plh.17.1698050284910; Mon, 23 Oct 2023 01:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698050284; cv=none; d=google.com; s=arc-20160816; b=UKNiviN7bDbOn9xEWgO64RWU5a07U26utbdFz3psP9El9sJ+/9SrQkuPJTRQ2k1BwZ SYm6ETIfg0pW8viML7xmHws7Y1ctdHFVBrIXgl3T/4aYVW3gAhADBbgMpYdDe5DA443a sDNoUjwRH2GUiO2RVV+LRDz49L+zGxmr4QIAskysANuHmckWInjLP32fwP6DMMaHD+9p 3Npk4JbQYNYyRcYt1Qwmi9MgovB3LEOIyaFfCzsmuHiH9XtyUQ3Sw1/DYSD0QFj0QuVT rG9TA/JFUnpGzk9Kv9gpV9ZGesAI4nucvJrYBWh83AF/MDd4rETVkIFVxdIOUK00uTZv 7/sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=v2qWqEWwWxgzTB5vBK4eUVGzwwb4KGMgVk1+rMugYSY=; fh=JSP1GHxRj5t21yLzZaMwQcBwIJ2DL/BdTf4boKw7sac=; b=c2daYVjPlQdoec8dxVN5wtOwZdJfQ5A1c3h+m/HgPL+EC/tCM1eM4EXbRWp7+cK88A rcqC28Z4c8ePihkW/s1NbETaL1m/PQYrqW9l8ctL1GQLkgxEZIvScuU44OpLvWcIZIhg Tyn1gBumiOCwSEDh5olGge2tB3SLZ5YS91p0jaQBbDLpx4Y8jN8ewAE9E2zHcNhtsI2T +Tif03W0zCBA05EBeyyx0xszvaYqI8ib2sGR0xtes6tSZi1PjrIJ9qYOwcnDZ2U3D7pU dKRSBicmSiJ+UrAdX+6Yiro4Q9y32t2aAZdEGmvQamE0sZQirE48ONxnml6/MU3hxk4H xEUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=I+qXGtKj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id e7-20020a170902b78700b001c9b129a658si5842668pls.122.2023.10.23.01.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 01:38:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=I+qXGtKj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 19362806A97C; Mon, 23 Oct 2023 01:38:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbjJWIhw (ORCPT + 99 others); Mon, 23 Oct 2023 04:37:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjJWIhv (ORCPT ); Mon, 23 Oct 2023 04:37:51 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63B97FC; Mon, 23 Oct 2023 01:37:48 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 09C1CC0004; Mon, 23 Oct 2023 08:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1698050266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v2qWqEWwWxgzTB5vBK4eUVGzwwb4KGMgVk1+rMugYSY=; b=I+qXGtKjWACc+95J3bxM740AW7ZhuwMsitmdSpakULn3nkAShIyZmAK/lJnq1wlUd7qNKp ToHV1Zz1KfIOmy74YTi2yd0Dm5UQ7Y7NApLfo2z48EbNSxuJKEA0Sh7wT5FBvI1DIByCaz IUgnve6EG+gsLFmHDpsuHgWC2YSFPnRBvBejHvqykWy0XjriEmjVqoZiYoIdR3ePVH0MF1 shAKlro8Chqv6dCsMXzdTXJTIpqDc7Z+Vt0M3HLIN5tDbXJm8j3s45WdvqyN9eJzwk+94m H8cKtVya75rHIMRlfJU2ZKdKLm3yUiPq1aHPGSTh+5FIF0SocS1LqmCQOlmkLA== Date: Mon, 23 Oct 2023 10:37:44 +0200 From: Miquel Raynal To: Linus Walleij Cc: Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Nicolas Pitre Subject: Re: [PATCH v4] mtd: cfi_cmdset_0001: Byte swap OTP info Message-ID: <20231023103745.054bc2d3@xps-13> In-Reply-To: References: <20231020-mtd-otp-byteswap-v4-1-0d132c06aa9d@linaro.org> <20231023102552.4b053b17@xps-13> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 23 Oct 2023 01:38:02 -0700 (PDT) Hi Linus, linus.walleij@linaro.org wrote on Mon, 23 Oct 2023 10:35:24 +0200: > On Mon, Oct 23, 2023 at 10:25=E2=80=AFAM Miquel Raynal > wrote: >=20 > > linus.walleij@linaro.org wrote on Fri, 20 Oct 2023 22:30:29 +0200: > > =20 > > > Currently the offset into the device when looking for OTP > > > bits can go outside of the address of the MTD NOR devices, > > > and if that memory isn't readable, bad things happen > > > on the IXP4xx (added prints that illustrate the problem before > > > the crash): > > > > > > cfi_intelext_otp_walk walk OTP on chip 0 start at reg_prot_offset 0x0= 0000100 > > > ixp4xx_copy_from copy from 0x00000100 to 0xc880dd78 > > > cfi_intelext_otp_walk walk OTP on chip 0 start at reg_prot_offset 0x1= 2000000 > > > ixp4xx_copy_from copy from 0x12000000 to 0xc880dd78 > > > 8<--- cut here --- > > > Unable to handle kernel paging request at virtual address db000000 > > > [db000000] *pgd=3D00000000 > > > (...) > > > > > > This happens in this case because the IXP4xx is big endian and > > > the 32- and 16-bit fields in the struct cfi_intelext_otpinfo are not > > > properly byteswapped. Compare to how the code in read_pri_intelext() > > > byteswaps the fields in struct cfi_pri_intelext. > > > > > > Adding a small byte swapping loop for the OTP in read_pri_intelext() > > > and the crash goes away. > > > > > > The problem went unnoticed for many years until I enabled > > > CONFIG_MTD_OTP on the IXP4xx as well, triggering the bug. > > > > > > Cc: stable@vger.kernel.org =20 > > > > Would you like to add a Fixes tag as well? Or is this skipped on > > purpose? =20 >=20 > Yes the actual commit predates existing git history... :/ >=20 > Git blame looks like that: >=20 > ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 423) > ^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 424) > /* Protection Register info */ > b359ed5184aeb (Jean-Philippe Brucker 2020-04-17 16:23:26 +0200 425) > if (extp->NumProtectionFields) > b359ed5184aeb (Jean-Philippe Brucker 2020-04-17 16:23:26 +0200 426) > extra_size +=3D (extp->NumProtectionFields - 1) * > b359ed5184aeb (Jean-Philippe Brucker 2020-04-17 16:23:26 +0200 427) > sizeof(struct cfi_intelext_otpinfo); >=20 > Jean-Philippe's patch is not the root cause AFAICT, but something > predating it, and predating git history. >=20 > The fix easily applies to all maintained stable kernels. Ack. > > > Reviewed-by: Nicolas Pitre > > > Signed-off-by: Linus Walleij > > > --- > > > ChangeLog v3->v4: > > > - Collected Nico's ACK. > > > - Stalled since june! Has this been missed? =20 > > > > Our current organization relies on Vignesh to pick-up (or tell me to > > pick-up) cfi patches. But he is slightly less active these days, so if I > > don't get any feedback from him soon I will take it for the next merge > > window. > > > > Sorry for the delay anyway. =20 >=20 > No worries it's not like the patch is urgent. Haha, well, yes :) Thanks, Miqu=C3=A8l