public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Hans-Gert Dahmen <hans-gert.dahmen@immu.ne>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	philipp.deppenwiese@immu.ne, mauro.lima@eclypsium.com,
	hughsient@gmail.com, platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH] firmware: export x86_64 platform flash bios region via sysfs
Date: Tue, 9 Nov 2021 11:28:08 +0100	[thread overview]
Message-ID: <YYpNOMtp7Kwf0fho@kroah.com> (raw)
In-Reply-To: <42cea157-55a2-bd12-335b-6348f0ff6525@immu.ne>

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?

> > > +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.

> > Also, you just bound this driver to ANY platform that it was loaded on,
> > with no actual detection of the hardware present, which feels like it
> > could cause big problems on all platforms.  Please, if you really want
> > to do this, restrict it to hardware that actually has the hardware you
> > are wanting to access, not all machines in the world.
> 
> I ave already proven that it works on all x64 Intel platforms here [1]. It
> nearly impossible to prove for AMD b/c of the lack of documentation, but we
> tested it on several old Bulldozer system and so far the memory was always
> mapped. I feel that adding more hardware detection just adds complexity.
> Anyway, what do you suggest? Use CPUID to check if the vendor is AMD or
> Intel?

Again, without some sort of "we only bind to the hardware on these types
of devices", a driver like this is not going to be allowed, because you
are not checking the hardware at all!

Also, drivers are loaded based on the hardware being found on the system
and having the driver loaded automatically.  That isn't happening here
at all, so that's another reason why this isn't going to be acceptable.

You HAVE to have hardware detection, otherwise the code is broken,
sorry.

thanks,

greg k-h

  parent reply	other threads:[~2021-11-09 10:28 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-09  0:01 [PATCH] firmware: export x86_64 platform flash bios region via sysfs Hans-Gert Dahmen
2021-11-09  6:16 ` Greg KH
2021-11-09  8:52   ` Hans-Gert Dahmen
2021-11-09  8:56     ` Hans-Gert Dahmen
2021-11-09 10:28     ` Greg KH [this message]
2021-11-09 12:32       ` Hans-Gert Dahmen
2021-11-09 12:42         ` Greg KH
2021-11-09 14:09           ` Mauro Lima
2021-11-09 14:11             ` Mauro Lima
2021-11-09 14:10           ` Hans-Gert Dahmen
     [not found]             ` <CAHp75VfbYsyC=7Ncnex1f_jiwrZhExDF7iy4oSGZgS1cHmsN0Q@mail.gmail.com>
2021-11-10  8:37               ` Hans-Gert Dahmen
2021-11-10  9:04                 ` Andy Shevchenko
2021-11-10  9:17                   ` Hans-Gert Dahmen
2021-11-10  9:25                     ` Andy Shevchenko
2021-11-10 10:00                       ` Hans-Gert Dahmen
2021-11-10 13:13                         ` Mauro Lima
2021-11-10 16:31                           ` Andy Shevchenko
2021-11-10 17:37                             ` Mauro Lima
2021-11-11  6:42                               ` Mika Westerberg
2021-11-11  8:59                                 ` Hans-Gert Dahmen
2021-11-11 10:32                                   ` Mika Westerberg
2021-11-11 10:55                                     ` Hans-Gert Dahmen
2021-11-11 11:43                                       ` Greg KH
2021-11-11 11:46                                     ` Richard Hughes
2021-11-11 12:46                                       ` Andy Shevchenko
2021-11-11 12:56                                         ` Hans-Gert Dahmen
2021-11-11 13:54                                           ` Andy Shevchenko
2021-11-11 14:33                                             ` Hans-Gert Dahmen
2021-11-11 15:30                                               ` Andy Shevchenko
2021-11-11 15:43                                                 ` Ard Biesheuvel
2021-11-11 15:49                                                   ` Andy Shevchenko
2021-11-11 16:05                                                     ` Hans-Gert Dahmen
2021-11-11 21:07                                                     ` Richard Hughes
2021-11-12  6:52                                                       ` Greg KH
2021-11-12 10:09                                                         ` Richard Hughes
2021-11-12 10:43                                                           ` Greg KH
2021-11-12 12:25                                                             ` Hans-Gert Dahmen
2021-11-11 16:07                                                 ` Hans-Gert Dahmen
2021-11-11 16:44                                                   ` Andy Shevchenko
2021-11-11 16:55                                                     ` Hans-Gert Dahmen
2021-11-11 17:48                                                       ` Andy Shevchenko
2021-11-11 18:14                                                         ` Hans-Gert Dahmen
2021-11-11 19:14                                                           ` Ard Biesheuvel
2021-11-11 20:50                                                             ` Hans-Gert Dahmen
2021-11-11 13:00                                       ` Mika Westerberg
2021-11-11 13:22                                         ` Richard Hughes
2021-11-11 13:34                                           ` Mika Westerberg
2021-11-11 13:36                                             ` Hans-Gert Dahmen
2021-11-11 14:42                                             ` Mauro Lima
2021-11-11 15:06                                               ` Mika Westerberg
2021-11-11 15:16                                                 ` Hans-Gert Dahmen
2021-11-12  6:59                                                   ` Mika Westerberg
2021-11-11 15:31                                                 ` Mauro Lima
2021-11-11 11:50                                 ` Mauro Lima
2021-11-10 17:41                             ` Hans-Gert Dahmen
     [not found]   ` <E1CBFD23-AC3B-43BF-BF0A-158844486BA9@getmailspring.com>
2021-11-09 10:24     ` Greg KH
2021-11-09 10:30       ` Philipp Deppenwiese
2021-11-09 11:25         ` Greg KH
2021-11-09 13:55   ` Mauro Lima
2021-11-09 16:12     ` Greg KH
2021-11-09 17:23       ` Mauro Lima
  -- strict thread matches above, loose matches on Subject: below --
2021-06-22 14:23 Hans-Gert Dahmen
2021-06-22 20:02 ` Greg KH
2021-06-25 13:54   ` Hans-Gert Dahmen
2021-06-22 22:18 ` David Laight
2021-06-23 12:17   ` Hans-Gert Dahmen
2021-06-23 12:40     ` gregkh
2021-06-24 11:20       ` Hans-Gert Dahmen
2021-06-24 11:42         ` gregkh
2021-06-23 13:22     ` David Laight
2021-06-18 16:47 Hans-Gert Dahmen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YYpNOMtp7Kwf0fho@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=hans-gert.dahmen@immu.ne \
    --cc=hughsient@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mauro.lima@eclypsium.com \
    --cc=philipp.deppenwiese@immu.ne \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox