lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <159306873839.62212.9311861115757727633@swboyd.mtv.corp.google.com>
Date:   Thu, 25 Jun 2020 00:05:38 -0700
From:   Stephen Boyd <swboyd@...omium.org>
To:     linux-kernel@...r.kernel.org, patrick.rudolph@...ements.com
Cc:     coreboot@...eboot.org,
        Patrick Rudolph <patrick.rudolph@...ements.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Alexios Zavras <alexios.zavras@...el.com>,
        Allison Randal <allison@...utok.net>,
        Julius Werner <jwerner@...omium.org>,
        Samuel Holland <samuel@...lland.org>
Subject: Re: [PATCH v4 1/2] firmware: google: Expose CBMEM over sysfs

Quoting patrick.rudolph@...ements.com (2020-04-07 01:29:06)
> From: Patrick Rudolph <patrick.rudolph@...ements.com>
> 
> Make all CBMEM buffers available to userland. This is useful for tools
> that are currently using /dev/mem.
> 
> Make the id, size and address available, as well as the raw table data.
> 
> Tools can easily scan the right CBMEM buffer by reading
> /sys/bus/coreboot/drivers/cbmem/coreboot*/cbmem_attributes/id
> or
> /sys/bus/coreboot/devices/coreboot*/cbmem_attributes/id
> 
> The binary table data can then be read from
> /sys/bus/coreboot/drivers/cbmem/coreboot*/cbmem_attributes/data
> or
> /sys/bus/coreboot/devices/coreboot*/cbmem_attributes/data
> 
> Signed-off-by: Patrick Rudolph <patrick.rudolph@...ements.com>
> ---

Sorry, this fell off my radar. Looks close though so please resend.

> diff --git a/Documentation/ABI/stable/sysfs-bus-coreboot b/Documentation/ABI/stable/sysfs-bus-coreboot
> new file mode 100644
> index 000000000000..6055906f41f2
> --- /dev/null
> +++ b/Documentation/ABI/stable/sysfs-bus-coreboot
> @@ -0,0 +1,44 @@
> +What:          /sys/bus/coreboot/devices/.../cbmem_attributes/id
> +Date:          Apr 2020
> +KernelVersion: 5.6
> +Contact:       Patrick Rudolph <patrick.rudolph@...ements.com>
> +Description:
> +               coreboot device directory can contain a file named
> +               cbmem_attributes/id if the device corresponds to a CBMEM
> +               buffer.
> +               The file holds an ASCII representation of the CBMEM ID in hex
> +               (e.g. 0xdeadbeef).
> +
> +What:          /sys/bus/coreboot/devices/.../cbmem_attributes/size
> +Date:          Apr 2020
> +KernelVersion: 5.6
> +Contact:       Patrick Rudolph <patrick.rudolph@...ements.com>
> +Description:
> +               coreboot device directory can contain a file named
> +               cbmem_attributes/size if the device corresponds to a CBMEM
> +               buffer.
> +               The file holds an representation as decimal number of the
> +               CBMEM buffer size (e.g. 64).
> +
> +What:          /sys/bus/coreboot/devices/.../cbmem_attributes/address
> +Date:          Apr 2020
> +KernelVersion: 5.6
> +Contact:       Patrick Rudolph <patrick.rudolph@...ements.com>
> +Description:
> +               coreboot device directory can contain a file named
> +               cbmem_attributes/address if the device corresponds to a CBMEM
> +               buffer.
> +               The file holds an ASCII representation of the physical address
> +               of the CBMEM buffer in hex (e.g. 0x000000008000d000) and should
> +               be used for debugging only.

If this is for debugging purposes only perhaps it should go into
debugfs. We try to not leak information about physical addresses to
userspace and this would let an attacker understand where memory may be.
That's not ideal and should be avoided.

> +
> +What:          /sys/bus/coreboot/devices/.../cbmem_attributes/data
> +Date:          Apr 2020
> +KernelVersion: 5.6
> +Contact:       Patrick Rudolph <patrick.rudolph@...ements.com>
> +Description:
> +               coreboot device directory can contain a file named
> +               cbmem_attributes/data if the device corresponds to a CBMEM
> +               buffer.
> +               The file holds a read-only binary representation of the CBMEM
> +               buffer.
> diff --git a/drivers/firmware/google/cbmem-coreboot.c b/drivers/firmware/google/cbmem-coreboot.c
> new file mode 100644
> index 000000000000..f76704a6eec7
> --- /dev/null
> +++ b/drivers/firmware/google/cbmem-coreboot.c
> @@ -0,0 +1,128 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * cbmem-coreboot.c
> + *
> + * Exports CBMEM as attributes in sysfs.
> + *
> + * Copyright 2012-2013 David Herrmann <dh.herrmann@...il.com>
> + * Copyright 2017 Google Inc.
> + * Copyright 2019 9elements Agency GmbH
> + */
> +
[..]
> +       &bin_attr_data,
> +       NULL
> +};
> +
> +static const struct attribute_group cb_mem_attr_group = {
> +       .name = "cbmem_attributes",
> +       .attrs = cb_mem_attrs,
> +       .bin_attrs = cb_mem_bin_attrs,
> +};
> +
> +static const struct attribute_group *attribute_groups[] = {
> +       &cb_mem_attr_group,
> +       NULL,

Nitpick: Drop the comma on sentinel so nothing can come after lest a
compile error happens.

> +};
> +
> +static int cbmem_probe(struct coreboot_device *cdev)
> +{
> +       struct device *dev = &cdev->dev;
> +       struct cb_priv *priv;
> +
> +       priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL);
> +       if (!priv)
> +               return -ENOMEM;
> +
> +       memcpy(&priv->entry, &cdev->cbmem_entry, sizeof(priv->entry));
> +
> +       dev_set_drvdata(dev, priv);

Agreed, avoid the memcpy().

> +
> +       return 0;
> +}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ