Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp595543pxh; Tue, 9 Nov 2021 15:54:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxY3+Kgu2vQac/T6HZyfRMeCu2qvt6mMZS8D1yAPd9I06GPp0GtVGFYowzgHHfsU/Y47g7G X-Received: by 2002:a92:c5cc:: with SMTP id s12mr8566595ilt.239.1636502039934; Tue, 09 Nov 2021 15:53:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636502039; cv=none; d=google.com; s=arc-20160816; b=uzdrmCRk6Z+hBuYqh8vwaSZlZsXOV2th7T2nSCSXET5LQI0WYwq67fyXIEDR6jHzQ9 AtIkFjim2HkGKOWyGmu2FMM/o3nIXJKIvW8BkXUxYns8UoI+z0G/iZZuHApeyfI3GxFK G5mJa2W8FX4pB4U8UKjd4f6T93lCxe6KK6LFnpcjbKA3OzP8mepHOdSwzOuEbyOaRDXp WnZYM9oBm+qWWg7hcje83tdSUDvuc7g5bnfH5UCrIqQGi9+KIZe4mDotEdE6hxFjdOY8 dD9P0f0+aozOb5XMITmu8tR0yOOIjtXllE7OJOx8YXhDqOIxwirPBDgnyVRtGXs5W7qs 0/0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/J4gthd3qA7NoGBc7YDjUAL5EF4s746/NmksKEqqClY=; b=qw+gMOEVuTJSQ2S7qLL31IrGotYTxpS3uMcGzm3TVBweQefO6K6yHTRq4Co5ad7/9L 6NI7RgT7AB/GNciPXw1uk80oCRBzCCrzy5NDRZesk/jHuhzuXpBI8iWRSQMeXnvJjq8v z+uYsuCPvnFmhu3aOY8zcfyGS5yG+rkh8ZbeYhKTHN71KEceTrlqaQ71Xc+TzlkzfVIJ +K9wqeb1zChSOwXkBqR2W+C4nS6N4S3IB34YG7Y2+9tyqHMXg8T0PQ7uiQ+0jukZSMie DoOXSt/infMG2PcovsBFfthEoDxy99swHeKooFFIuZhHu74Vf2NDleJXi2H0BZjSTZ5V HypA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=E+Y3y8rD; 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 g7si43815017ila.114.2021.11.09.15.53.45; Tue, 09 Nov 2021 15:53:59 -0800 (PST) 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=E+Y3y8rD; 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 S231839AbhKIOMt (ORCPT + 97 others); Tue, 9 Nov 2021 09:12:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234190AbhKIOMr (ORCPT ); Tue, 9 Nov 2021 09:12:47 -0500 Received: from mail-vk1-xa32.google.com (mail-vk1-xa32.google.com [IPv6:2607:f8b0:4864:20::a32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0464C061766 for ; Tue, 9 Nov 2021 06:10:01 -0800 (PST) Received: by mail-vk1-xa32.google.com with SMTP id e64so10104139vke.4 for ; Tue, 09 Nov 2021 06:10:01 -0800 (PST) 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=/J4gthd3qA7NoGBc7YDjUAL5EF4s746/NmksKEqqClY=; b=E+Y3y8rDnFkA6I6Aq+x2QVjkohJVEoe+lUX53ZwKnjmYLDyLyb2413yUTxBao5qxlY DdzUx3EdJzIaOJxyeYEykGzV44BHzI9pTMWuHqKggENG5uVtKYBXYyc//Voc0mVOVoKt 6WTymGVW2t7g5k+mpgCWeBH0g0JvY5rioa56h/BY/kNFk7P1OIxWp7vtcCeL85MfxbFG zUviE5k0/J9V1PDIgoodIpVdsuexCsZSI/2moTLYsyqUxOmyfey+NnWLxhHWsn+bUSU3 CxG5+3WCGYJFrKcc2MfXK23uIaRhbCTqCPpHvN2yx/Vtt6mGNAzTvIyMvbN9krZ/CuQ8 y+4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/J4gthd3qA7NoGBc7YDjUAL5EF4s746/NmksKEqqClY=; b=3AgJExCrSIdWt+h7CFE5QBpfsW2bBjmQNHIobEjlXC69ZyI9V6V9lU9ZwYWjSMGZay GmaizB88E/nCYcqx8DZYsUsCvdnEVgOXqA227/1iq+NZ9+0LzpsWs6+ouFHhOVg6Y9zi IlJsRSL0EEGsNAHyXKXncyU6JFb+ctNDAuZ+xkyMII/gpehuq7aroZVLGDbbcqbOVad8 6Wl3jkvKY0EbH78UlOo1PXzomaXF/delhuhTyNGXNqFeHWmn4Iihkakergo1ORLncgAQ dw/Nuzd2wsA17KsCkv/aoscgivF9wPEVzBuGseJWLJ+pEIzHZa5tp86GdDWxYEaiRAgh pLkw== X-Gm-Message-State: AOAM531M6yPrSnkIVISuIrh+SUNBFG9NArfSHn+lbObcU0DPzPoNSbEn Wq4d5AshmNApHxp9yKsvU6KIDtEY1Hk2Qk7iNTDfCQ== X-Received: by 2002:a05:6122:1803:: with SMTP id ay3mr11940761vkb.24.1636467000684; Tue, 09 Nov 2021 06:10:00 -0800 (PST) MIME-Version: 1.0 References: <20211109000130.42361-1-hans-gert.dahmen@immu.ne> <42cea157-55a2-bd12-335b-6348f0ff6525@immu.ne> In-Reply-To: From: Mauro Lima Date: Tue, 9 Nov 2021 11:09:49 -0300 Message-ID: Subject: Re: [PATCH] firmware: export x86_64 platform flash bios region via sysfs To: Greg KH Cc: Hans-Gert Dahmen , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Philipp Deppenwiese , Richard Hughes , platform-driver-x86@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 9, 2021 at 9:42 AM Greg KH wrote: > > On Tue, Nov 09, 2021 at 01:32:48PM +0100, Hans-Gert Dahmen wrote: > > On Tue, 9 Nov 2021, 11:28 Greg KH, wrote: > > > > > > On Tue, Nov 09, 2021 at 09:52:53AM +0100, Hans-Gert Dahmen wrote: > > > > On 09.11.21 07:16, Greg KH wrote: > > > > > On Tue, Nov 09, 2021 at 01:01:30AM +0100, Hans-Gert Dahmen wrote: > > > > > > Make the 16MiB long memory-mapped BIOS region of the platform SPI flash > > > > > > on X86_64 system available via /sys/kernel/firmware/flash_mmap/bios_region > > > > > > for pen-testing, security analysis and malware detection on kernels > > > > > > which restrict module loading and/or access to /dev/mem. > > > > > > > > > > That feels like a big security hole we would be opening up for no good > > > > > reason. > > > > > > > > > > > It will be used by the open source Converged Security Suite. > > > > > > https://github.com/9elements/converged-security-suite > > > > > > > > > > What is the reason for this, and what use is this new interface? > > > > Because it is very hard to access the SPI flash to read the BIOS contents > > > > for (security) analysis and this works without the more complex and > > > > unfinished SPI drivers and it does so on a system where we may not access > > > > the full /dev/mem. > > > > > > Why not fix the spi drivers to do this properly? What is preventing you > > > from doing that instead of adding a new user/kernel api that you will > > > have to support for the next 20+ years? > > > > > > > Because this interface we want to use is inherently tied to the > > workings of x86_64 CPUs. It is very stable and easy to use. The SPI > > drivers in contrast have a history of being complex, buggy and in > > general not reliable. > > Do you have a pointer to these complex and buggy drivers anywhere? Right now the intel spi driver has a _(DANGEROUS)_ tag [1], this is preventing the kernel engineers from compiling the driver into different distros. A couple of months ago I tried to modify the driver and make it RO [2] but the drivers author told me that they don't want to remove the tag, even if the driver is compiled without any write/erase functionality as I proposed. The driver is fixed as the author claims but, as I said, they want to preserve the tag. This patch is close to what we need if we can't use the intel spi mechanism. > > > This module will require very little maintenance > > and will probably work in the future without needing modification for > > newer platforms. It generally is meant as a fallback to the real SPI > > flash drivers so that userspace programs are able to provide essential > > functionality. > > If it is a "fallback", how is it going to interact on a system where the > SPI driver is loaded? > > > > > > > +static int __init flash_mmap_init(void) > > > > > > +{ > > > > > > + int ret; > > > > > > + > > > > > > + pdev = platform_device_register_simple("flash_mmap", -1, NULL, 0); > > > > > > + if (IS_ERR(pdev)) > > > > > > + return PTR_ERR(pdev); > > > > > > + > > > > > > + ret = sysfs_create_group(&pdev->dev.kobj, &flash_mmap_group); > > > > > > > > > > You just raced with userspace and lost > > > > > > Please set the attribute to the platform driver before you create the > > > > > device. > > > > > > > > > > > > > Sorry, but I went through tons of code and could not find a single instance > > > > where I can use a default group for creation without using a probe function > > > > that does the magic for me. Please help me find the correct way of doing > > > > this without manually creating and adding kobjects. > > > > > > The problem here is that you are abusing the platform driver code and > > > making a "fake" device that is not attached to anything real, and > > > without a driver. That should not be done, as you do not know what > > > hardware this driver is going to be run on. > > > > > > Bind to the real hardware resource please. > > > > In a previous mail in June you suggested this is some sort of platform > > device, that is why I rewrote it as such. > > That's fine, but bind to the real platform device that describes this > hardware! You are not doing anything like this at all here, you are > just creating a random device in the sysfs tree and instantly allowing > userspace access to raw memory. You are not actually controlling the > platform device at all. > > > The hardware resource here > > is the south bridge for x86_64 CPUs and the module dependencies will > > compile it only for these platforms. > > What "module dependencies"? You do realize that distro kernels enable > all modules to be built. We have an "autoload only the modules that this > hardware needs" infrastructure that you need to tie into here, you are > totally ignoring it (despite it being present for almost 20 years > now...) > > > The situation is like, if you > > have that CPU, you have the hardware, so it is implicitly bound or it > > just will not execute on a machine code level. > > What do you mean "implicitly bound"? How does this tie into the driver > model such that it will only be autoloaded, and have the driver bind to > the hardware, that it knows it can control? > > That is what needs to be fixed here, you are just claiming that it can > talk to the hardware without having any check at all for this. > > > I feel like your > > requirement is somewhat impossible to satisfy and I really don't know > > what to do. Please, can anyone help me by pointing out a proper > > example elsewhere in the kernel? > > What resource in the system describes the hardware you wish to bind to? > Write a driver for _that_ resource, and have it be properly autoloaded > when that resource is present in the system. > > You have hundreds of examples running on your system today, but as I do > not know where this hardware is described specifically, it's hard to be > able to point you to an example that works like that. > > So again, what hardware signature describes the resource you wish to > bind to? > > thanks, > > greg k-h Thanks, Mauro.