From: Greg KH <greg-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
To: dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Cc: mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org,
linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
toshi.kani-VXdhtT5mjnY@public.gmane.org,
matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org,
x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
James.Bottomley-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org,
horms-/R6kz+dDXgpPR4JQBCEnsQ@public.gmane.org,
bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org,
ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org,
hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org,
vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Subject: Re: [patch 9/9 v3] x86: export x86 boot_params to sysfs
Date: Thu, 21 Nov 2013 08:45:54 -0800 [thread overview]
Message-ID: <20131121164554.GB15083@kroah.com> (raw)
In-Reply-To: <20131121061757.030007746-je1gSBvt1TcFLmT5oZ11vB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
On Thu, Nov 21, 2013 at 02:17:13PM +0800, dyoung@redhat.com wrote:
> kexec-tools use boot_params for getting the 1st kernel hardware_subarch,
> the kexec kernel efi runtime support also need read the old efi_info from
> boot_params. Currently it exists in debugfs which is not a good place for
> such infomation. Per HPA, we should avoid of "sploit debugfs".
>
> In this patch /sys/kernel/boot_params are exported, also the setup_data
> is exported as a subdirectory. For original debugfs since it's already
> there for long time and kexec-tools is using it for hardware_subarch so
> let's do not remove them for now.
>
> Structure are like below:
>
> /sys/kernel/boot_params
> ├── data /* binary data for boot_params */
> ├── setup_data /* subdirectory for setup_data if there's any */
> │ ├── 0 /* the first setup_data node */
> │ │ ├── data /* binary data for setup_data node 0 */
> │ │ └── type /* setup_data type of setup_data node 0, hex string */
> | [snip] /* other setup_data nodes ... */
> └── version /* hex string for boot protocal version */
>
> Signed-off-by: Dave Young <dyoung@redhat.com>
> ---
> Documentation/ABI/testing/sysfs-kernel-boot_params | 40 ++
> arch/x86/kernel/Makefile | 2
> arch/x86/kernel/ksysfs.c | 326 +++++++++++++++++++++
> 3 files changed, 367 insertions(+), 1 deletion(-)
>
> --- /dev/null
> +++ efi/Documentation/ABI/testing/sysfs-kernel-boot_params
> @@ -0,0 +1,40 @@
> +What: /sys/kernel/boot_params
> +Date: November 2013
> +Contact: Dave Young <dyoung@redhat.com>
> +Description:
> + The /sys/kernel/boot_params directory contains two
> + files: "data" and "version" and one subdirectory "setup_data".
> + It is used to export the kernel boot parameters of x86
> + platform to user space for kexec and debugging purpose.
> +
> + If there's no setup_data in boot_params the subdirectory will
> + not be created.
> +
> + "data" file is the binary representation of struct boot_params.
> +
> + "version" file is the string representation of boot
> + protocol version.
> +
> + "setup_data" subdirectory contains the setup_data data
> + structure in boot_params. setup_data is maintained in kernel
> + as a link list. In "setup_data" subdirectory there's one
> + subdirectory for each link list node named with the number
> + of the list nodes. The list node subdirectory contains two
> + files "type" and "data". "type" file is the string
> + representation of setup_data type. "data" file is the binary
> + representation of setup_data payload.
> +
> + The whole boot_params directory structure is like below:
> + /sys/kernel/boot_params
> + ├── data
> + ├── setup_data
> + │ ├── 0
> + │ │ ├── data
> + │ │ └── type
> + │ └── 1
> + │ ├── data
> + │ └── type
> + └── version
> +
> +Users:
> + Kexec Mailing List <kexec@lists.infradead.org>
> --- efi.orig/arch/x86/kernel/Makefile
> +++ efi/arch/x86/kernel/Makefile
> @@ -35,7 +35,7 @@ obj-y += alternative.o i8253.o pci-nom
> obj-y += tsc.o io_delay.o rtc.o
> obj-y += pci-iommu_table.o
> obj-y += resource.o
> -
> +obj-$(CONFIG_SYSFS) += ksysfs.o
> obj-y += process.o
> obj-y += i387.o xsave.o
> obj-y += ptrace.o
> --- /dev/null
> +++ efi/arch/x86/kernel/ksysfs.c
> @@ -0,0 +1,326 @@
> +/*
> + * Architecture specific sysfs attributes in /sys/kernel
> + *
> + * Copyright (C) 2007, Intel Corp.
> + * Huang Ying <ying.huang@intel.com>
> + * Copyright (C) 2013, 2013 Red Hat, Inc.
> + * Dave Young <dyoung@redhat.com>
> + *
> + * This file is released under the GPLv2
> + */
> +
> +#include <linux/kobject.h>
> +#include <linux/string.h>
> +#include <linux/sysfs.h>
> +#include <linux/init.h>
> +#include <linux/stat.h>
> +#include <linux/slab.h>
> +#include <linux/mm.h>
> +
> +#include <asm/setup.h>
> +
> +static ssize_t boot_params_version_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + return sprintf(buf, "0x%04x\n", boot_params.hdr.version);
> +}
> +
> +static struct kobj_attribute boot_params_version_attr =
> + __ATTR(version, S_IRUGO, boot_params_version_show, NULL);
__ATTR_RO() please.
> +static struct kobj_attribute type_attr =
> + __ATTR(type, S_IRUGO, setup_data_type_show, NULL);
__ATTR_RO() here too.
> +static struct bin_attribute data_attr = {
> + .attr = {
> + .name = "data",
> + .mode = S_IRUGO,
> + },
> + .read = setup_data_data_read,
> +};
> +
> +static int __init create_setup_data_node(struct kobject *parent,
> + struct kobject **kobjp, int nr)
> +{
> + int ret = 0;
> + size_t size;
> + struct kobject *kobj;
> + char name[16]; /* should be enough for setup_data nodes numbers */
> + snprintf(name, 16, "%d", nr);
> +
> + kobj = kobject_create_and_add(name, parent);
> + if (!kobj)
> + return -ENOMEM;
> +
> + ret = sysfs_create_file(kobj, &type_attr.attr);
> + if (ret)
> + goto out_kobj;
> +
> + ret = get_setup_data_size(nr, &size);
> + if (ret)
> + goto out_kobj;
> +
> + data_attr.size = size;
> + ret = sysfs_create_bin_file(kobj, &data_attr);
> + if (ret)
> + goto out_file;
> + *kobjp = kobj;
You just raced with userspace (creating and announcing the kobject and
then, afterward, at some later point in time, created the sysfs files.
Please use the groups option to create the files properly before
announcing the kobject to userspace.
> +static int __init boot_params_ksysfs_init(void)
> +{
> + int ret;
> + struct kobject *boot_params_kobj;
> +
> + boot_params_kobj = kobject_create_and_add("boot_params",
> + kernel_kobj);
> + if (!boot_params_kobj) {
> + ret = -ENOMEM;
> + goto out;
> + }
> + ret = sysfs_create_file(boot_params_kobj,
> + &boot_params_version_attr.attr);
> + if (ret)
> + goto out_boot_params_kobj;
> + ret = sysfs_create_bin_file(boot_params_kobj,
> + &boot_params_data_attr);
> + if (ret)
> + goto out_create_file;
> +
> + ret = create_setup_data_nodes(boot_params_kobj);
> + if (ret)
> + goto out_create_bin;
> +
> + return 0;
Same race condition here as well. Use a groups structure please.
thanks,
greg k-h
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2013-11-21 16:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 6:17 [patch 0/9 v3] kexec kernel efi runtime support dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-11-21 6:17 ` [patch 1/9 v3] efi: remove unused variables in __map_region dyoung-H+wXaHxf7aLQT0dZR+AlfA
[not found] ` <20131121061752.715177297-je1gSBvt1TcFLmT5oZ11vB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2013-11-21 15:54 ` Borislav Petkov
2013-11-21 6:17 ` [patch 2/9 v3] efi: add a wrapper function efi_map_region_fixed dyoung-H+wXaHxf7aLQT0dZR+AlfA
[not found] ` <20131121061753.223578092-je1gSBvt1TcFLmT5oZ11vB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2013-11-21 16:39 ` Borislav Petkov
[not found] ` <20131121163947.GL26009-fF5Pk5pvG8Y@public.gmane.org>
2013-11-22 2:59 ` Dave Young
2013-11-21 6:17 ` [patch 3/9 v3] efi: reserve boot service fix dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-11-21 6:17 ` [patch 4/9 v3] efi: cleanup efi_enter_virtual_mode function dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-11-21 16:49 ` Borislav Petkov
[not found] ` <20131121164929.GM26009-fF5Pk5pvG8Y@public.gmane.org>
2013-11-22 2:54 ` Dave Young
2013-11-21 6:17 ` [patch 5/9 v3] efi: export more efi table variable to sysfs dyoung-H+wXaHxf7aLQT0dZR+AlfA
[not found] ` <20131121061754.887381332-je1gSBvt1TcFLmT5oZ11vB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2013-11-21 16:42 ` Greg KH
[not found] ` <20131121164224.GA15083-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2013-11-22 2:51 ` Dave Young
2013-11-21 16:57 ` Borislav Petkov
[not found] ` <20131121165742.GN26009-fF5Pk5pvG8Y@public.gmane.org>
2013-11-22 2:48 ` Dave Young
[not found] ` <20131122024850.GC3874-je1gSBvt1TcFLmT5oZ11vB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2013-11-23 13:15 ` Borislav Petkov
[not found] ` <20131123131518.GC24148-fF5Pk5pvG8Y@public.gmane.org>
2013-11-25 5:28 ` Dave Young
2013-11-21 6:17 ` [patch 6/9 v3] efi: export efi runtime memory mapping " dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-11-21 6:17 ` [patch 7/9 v3] efi: passing kexec necessary efi data via setup_data dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-11-21 6:17 ` [patch 8/9 v3] x86: add xloadflags bit for efi runtime support on kexec dyoung-H+wXaHxf7aLQT0dZR+AlfA
2013-11-21 6:17 ` [patch 9/9 v3] x86: export x86 boot_params to sysfs dyoung-H+wXaHxf7aLQT0dZR+AlfA
[not found] ` <20131121061757.030007746-je1gSBvt1TcFLmT5oZ11vB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2013-11-21 16:45 ` Greg KH [this message]
[not found] ` <20131121164554.GB15083-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2013-11-22 2:45 ` Dave Young
[not found] ` <20131121061704.363730447-je1gSBvt1TcFLmT5oZ11vB/sF2h8X+2i0E9HWUfgJXw@public.gmane.org>
2013-11-21 6:52 ` [patch 0/9 v3] kexec kernel efi runtime support Dave Young
2013-11-22 22:29 ` Toshi Kani
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=20131121164554.GB15083@kroah.com \
--to=greg-u8xffu+wg4eavxtiumwx3w@public.gmane.org \
--cc=James.Bottomley-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org \
--cc=bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org \
--cc=dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
--cc=horms-/R6kz+dDXgpPR4JQBCEnsQ@public.gmane.org \
--cc=hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org \
--cc=kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=matt-HNK1S37rvNbeXh+fF434Mdi2O/JbrIOy@public.gmane.org \
--cc=mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org \
--cc=toshi.kani-VXdhtT5mjnY@public.gmane.org \
--cc=vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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