Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp644834pxa; Tue, 4 Aug 2020 14:28:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaaQzOGvBSU0ak60gr2l9IGIS/2IvxMwxJDwP3MTQAYadmhvlBWqFF0CZpSRPN+bLJycyN X-Received: by 2002:a05:6402:1c10:: with SMTP id ck16mr21968562edb.151.1596576483633; Tue, 04 Aug 2020 14:28:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596576483; cv=none; d=google.com; s=arc-20160816; b=VDsdXNV9Ni1XAePs43wTnv1dCGysbIe5jiZv2CUvFzhogC61IErDlE6WrKCkNTfzCz vr1Y/ngzheyTIN4ENzAWdNzPmh0SZg67sQQvzwhSJUGGsofieAz0uc2rLkApwGqyX3+a y8ZpipObRSA8P84ThcPzekCX4ASKnl0jG8XiA5DRDLex0dvvPnxavNsry50v/QXhaCl3 H33MBCeGcK0X9lqU1pZHmGGZlOstkNLOqWqmDlf4QTWBu+gZR+9ZsOouawf8bpaqmq0m +NfhYHZdYxb5iBuLTOMfIVTzSG5zx5v1WKlQHj9PA85FO/SmYfLKUmpU/EJTr/i0mBl0 Czxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=EIijXqczA+fJ6ljet3cDCIUDRtSrnljLBcPwrEPIX1I=; b=HUYDoBTnDZsUdWI28FbFh6b1PLnVuRxv5fmJyQXkCrK5/IB40Iu5U6uo9wURaz2OOO GJiLPBGcLP/pi7zQnuLQr6VFAFggu0bSltKUpjMsbSVnxy9g8ikqKzJg9IpTTHq9NXUL OJ/HwXhUfIQClv4DLd2Sn/9OmkChC1zDE2ynxp1ajJ0eg/h3jCyeDvPJJP2Mxjf5lvAo sk4Bc9KxOoufmXknuSR7OBLQ+bS0OzOE9A0Oca9tewtfbjezO3bJIzVYNXH8FU+5otTK diaQjB1AkdEzDU84xWgfGq1FU2hjTTIWxsA1ImPgrCjYjANNQjk4zSUvbufH21X09G7Q I1Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=NnLic8Mv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz6si2908175edb.254.2020.08.04.14.27.41; Tue, 04 Aug 2020 14:28:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=NnLic8Mv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727861AbgHDV02 (ORCPT + 99 others); Tue, 4 Aug 2020 17:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbgHDV02 (ORCPT ); Tue, 4 Aug 2020 17:26:28 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2564C06174A for ; Tue, 4 Aug 2020 14:26:27 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id w2so7702034qvh.12 for ; Tue, 04 Aug 2020 14:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclypsium.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EIijXqczA+fJ6ljet3cDCIUDRtSrnljLBcPwrEPIX1I=; b=NnLic8Mve8V7Vn5BnI+2aE5Qj9cAudq14M8IldzGj4HmlvW/KE+/PvgoPdjFUIzzVA ovpOrHj6UrwT/KFYHpe2OF2gPnl434X7L9XP5gyfwBlzPGhvBU4IHO/Ia+ZTNUMzLmtB Gu78Ru+PyTpkN8YLdM5zvj7fj0EmcMiRT8Fn1nIQNTq7O/C/k29VTasIfZvhsES96FsW 16jj98++LlFxieMbt8m2oLc2i9Llz6HrmTPt5lYYfZp1d78kXWx+HMnyvoX8axmRU+bw NtFKluqhjAqZaoRrq6T39LyCkITvmN25fmY2VrUmdVyHx3kYHW5+A66gQaX0SwYDSiDf 7lIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EIijXqczA+fJ6ljet3cDCIUDRtSrnljLBcPwrEPIX1I=; b=Aqo40jhF4qDzosKBfbs2CP7OcK0TFDJjLfbMGm9CZgTzy2VrSVmHXQCr/H8Uybh/Ba 3c3osVfJYoV2vAlF3WJSwPvVAUDGGVotmY3Ippnk9IcfxM50fLhK9/iK8rnm5CHSnxiH TLNo11z1/b0cLcJHxd2nJ/5jHtOZDt42PLCtteXYKXREadh9y0tgcgUSKIE+C576JWNz yphdCxpSjKeLPp8o+WNmN58gcqvAP9RGfYVLgLWhT6cJ8OMzBhOkBf/ELw7BoVfY86Xy CPrUoUjcD1PEZT2//WG7yKGTRrEUHQnmN+IexVYATMHhsaJvbUlJwo8G86jEGUFSGUCJ /aRA== X-Gm-Message-State: AOAM532CBseg4uRdVX9d6xXOPXDM9653Lc2FnsIGlyVfnqVheHSUnD8O CIAgCo7jk7e+/0vHPR8h/j6dB3x3lUdFjxo99+C5BA== X-Received: by 2002:ad4:5502:: with SMTP id az2mr377046qvb.148.1596576386950; Tue, 04 Aug 2020 14:26:26 -0700 (PDT) MIME-Version: 1.0 References: <20200804135817.5495-1-daniel.gutson@eclypsium.com> In-Reply-To: From: Daniel Gutson Date: Tue, 4 Aug 2020 18:26:15 -0300 Message-ID: Subject: Re: [PATCH] mtd: spi-nor: intel-spi: Do not try to make the SPI flash chip writable To: Arnd Bergmann Cc: Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Boris Brezillon , linux-mtd , "linux-kernel@vger.kernel.org" , Alex Bazhaniuk , Richard Hughes , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 4, 2020 at 5:46 PM Arnd Bergmann wrote: > > On Tue, Aug 4, 2020 at 9:57 PM Daniel Gutson wrote: > > On Tue, Aug 4, 2020 at 4:06 PM Arnd Bergmann wrote: > > > On Tue, Aug 4, 2020 at 5:49 PM Daniel Gutson wrote: > > > > On Tue, Aug 4, 2020 at 12:21 PM Arnd Bergmann wrote: > > > >> On Tue, Aug 4, 2020 at 3:58 PM Daniel Gutson > > > >> wrote: > > > > > > > > What about just saying > > > > > > > > "This patch removes the attempt by the intel-spi-pci driver to > > > > make the chip always writable." > > > > > > Yes, that is much better, though it still sounds like it would at the > > > moment allow writing to the device from software without also > > > setting the module parameter. I would say something like > > > > > > "Disallow overriding the write protection in the PCI driver > > > with a module parameter and instead honor the current > > > state of the write protection as set by the firmware." > > > > But wait, Mika, the author of the file, asked earlier not to remove > > the module parameter of intel-spi, and just remove the unconditional > > attempt to turn the chip writable in intle-spi-pci. > > Yes, and I think that is fine (aside from the inconsistency with bay trail > that you have not commented on), There are two inconsistencies before any of my patches: 1) in intel-spi.c: uses the module parameter only for bay trail. 2) intel-spi.c uses a module parameter whereas intel-spi-pci doesn't My initial patch addressed #2 by also adding a module parameter to intel-spi-pci, but then some of you discouraged me to use module parameters. Mika showed up and suggested to leave intel-spi.c as is (with its module parameter), and remove the code in intel-spi-pci that tried to turn the SPI chip writable if the BIOS was unlocked. > but that only touches the hardware > write-protection, which doesn't really have any effect unless user > space also configures the driver module to allow writing to the > mtd device. > > > So I'm not touching intel-pci, just removing that code from > > intel-spi-pci without adding a new module parameter. > > > > Are you aligned on this? > > One of us is still very confused about what the driver does. > You seem to have gone back to saying that without the > change a user could just write to the device even without > passing the module parameter to intel-spi.ko? What I'm trying to say is that, if the BIOS is unlocked (no driver involvement here), the intel-spi-pci turns the chip writable even without changing the module parameter of intel-spi. This is because the attempt to turn the chip writable occurs in the probing of intel-spi-pci, that is, earlier than the intel-spi initialization. > > Maybe you should start by explaining what scenario you > actually want to prevent here. Is it Was it clear from above? Before commenting below, it's important to note again that the driver will succeed in turning the chip writable only if the BIOS is unlocked by its build time specification. The WPD field (Write Protect Disable) bit only has effect if the BIOS is not locked. This WPD bit is the one that the intel-spi-pci driver tries to set unconditionally. If the BIOS is locked, it will cause no effect. But if the BIOS is not locked, the chip will end up in Write Protect Disabled state. My latest patch simply leaves alone the WPD bit in intel-spi-pci, not trying to set it to 1. I'm not sure the options below are now fully compatible with my explanation above. > > a) the hardware write-protect bit getting changed, which > introduces the possibility of corrupting the flash even > if nothing tries to write to it, > > b) root users setting the device writable with the intention > of writing to it even though firmware has politely asked > for this not to be done (by setting the write-protect bit > but not preventing it from being disabled again), or > > c) a writeable mtd device showing up even without > the module parameter being set at all? > > I thought the initial patch was about c) which turned out > to be a non-issue, and then the later patch being about b). > > Arnd -- Daniel Gutson Argentina Site Director Enginieering Director Eclypsium Below The Surface: Get the latest threat research and insights on firmware and supply chain threats from the research team at Eclypsium. https://eclypsium.com/research/#threatreport