mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: "Michael J. Coss" <michael.coss@alcatel-lucent.com>
Cc: gregkh@linuxfoundation.org, davem@davemloft.net,
	linux-kernel@vger.kernel.org,
	containers@lists.linuxcontainers.org, serge.hallyn@ubuntu.com,
	stgraber@ubuntu.com
Subject: Re: [PATCH 3/3] net/udevns: Netlink module to forward uevent to containers
Date: Thu, 10 Sep 2015 20:05:00 -0500	[thread overview]
Message-ID: <87si6lvk8z.fsf@x220.int.ebiederm.org> (raw)
In-Reply-To: <dba3687ebebd6744710cd9a1d6f39b1fa01dfd87.1441762578.git.michael.coss@alcatel-lucent.com> (Michael J. Coss's message of "Tue, 8 Sep 2015 22:10:30 -0400")

"Michael J. Coss" <michael.coss@alcatel-lucent.com> writes:

> New generic netlink module to provide an interface with the new
> forwarding interface for uevent.  The driver allows a user to
> direct a uevent as read from the kernel to a specific network
> namespace by providing the uevent message, and a target process id.
> The uapi header file provides the message format.

If we can't just pass the message thourgh I don't expect genetlink is a
particularly good interface for this.

It would be nice if we could open some appropriate thing and the act of
getting a file descriptor ould suppress all of the uevent broadcast
messages in that network namespace.

Further GENL_ADMIN_PERM is an unfortunate choice for a permission check.
I don't see it as exploitable but I am not certain CAP_SYS_ADMIN is the
best capability to check.    Beyond that we probably want to arrange
things so that we can use ns_capable so we can allow containers to hand
off their devices to child containers.

Implementations that do not allow for containers to nest bother me.

> Signed-off-by: Michael J. Coss <michael.coss@alcatel-lucent.com>
> ---
>  include/uapi/linux/Kbuild   |   1 +
>  include/uapi/linux/udevns.h |  19 ++++++++
>  net/Kconfig                 |   1 +
>  net/Makefile                |   1 +
>  net/udevns/Kconfig          |   9 ++++
>  net/udevns/Makefile         |   5 ++
>  net/udevns/udevns.c         | 112 ++++++++++++++++++++++++++++++++++++++++++++
>  net/udevns/udevns.h         |  19 ++++++++
>  8 files changed, 167 insertions(+)
>  create mode 100644 include/uapi/linux/udevns.h
>  create mode 100644 net/udevns/Kconfig
>  create mode 100644 net/udevns/Makefile
>  create mode 100644 net/udevns/udevns.c
>  create mode 100644 net/udevns/udevns.h
>
> diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
> index 1ff9942..9fb9c59 100644
> --- a/include/uapi/linux/Kbuild
> +++ b/include/uapi/linux/Kbuild
> @@ -404,6 +404,7 @@ header-y += toshiba.h
>  header-y += tty_flags.h
>  header-y += tty.h
>  header-y += types.h
> +header-y += udevns.h
>  header-y += udf_fs_i.h
>  header-y += udp.h
>  header-y += uhid.h
> diff --git a/include/uapi/linux/udevns.h b/include/uapi/linux/udevns.h
> new file mode 100644
> index 0000000..f5702f5
> --- /dev/null
> +++ b/include/uapi/linux/udevns.h
> @@ -0,0 +1,19 @@
> +#ifndef _UDEVNS_H_
> +#define _UDEVNS_H_
> +
> +enum udevns_msg_types {
> +	UDEVNS_FORWARD_MSG = 0x1,
> +	UDEVNS_CMD_MAX,
> +};
> +
> +enum udevns_attr {
> +	UDEVNS_UNSPEC,
> +	UDEVNS_PID,
> +	UDEVNS_MSG,
> +	__UDEVNS_ATTR_MAX,
> +};
> +
> +#define UDEVNS_ATTR_MAX (__UDEVNS_ATTR_MAX - 1)
> +#define UDEVNS_VERSION 0x1
> +
> +#endif
> diff --git a/net/Kconfig b/net/Kconfig
> index 57a7c5a..465e288 100644
> --- a/net/Kconfig
> +++ b/net/Kconfig
> @@ -54,6 +54,7 @@ source "net/packet/Kconfig"
>  source "net/unix/Kconfig"
>  source "net/xfrm/Kconfig"
>  source "net/iucv/Kconfig"
> +source "net/udevns/Kconfig"
>  
>  config INET
>  	bool "TCP/IP networking"
> diff --git a/net/Makefile b/net/Makefile
> index 3995613..bde7775 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -74,3 +74,4 @@ obj-$(CONFIG_HSR)		+= hsr/
>  ifneq ($(CONFIG_NET_SWITCHDEV),)
>  obj-y				+= switchdev/
>  endif
> +obj-$(CONFIG_UDEVNS)	+= udevns/
> diff --git a/net/udevns/Kconfig b/net/udevns/Kconfig
> new file mode 100644
> index 0000000..367e650
> --- /dev/null
> +++ b/net/udevns/Kconfig
> @@ -0,0 +1,9 @@
> +config UDEVNS
> +	tristate "UDEV namespace bridge"
> +	depends on SYSFS
> +	default n
> +	help
> +		This option enables support for explicit forwarding of UDEV events to
> +		other network namespaces
> +
> +		If unsure, say N.
> diff --git a/net/udevns/Makefile b/net/udevns/Makefile
> new file mode 100644
> index 0000000..44c6b12
> --- /dev/null
> +++ b/net/udevns/Makefile
> @@ -0,0 +1,5 @@
> +#
> +# Makefile for the uevent namespace aware forwarder
> +#
> +#
> +obj-$(CONFIG_UDEVNS) += udevns.o
> diff --git a/net/udevns/udevns.c b/net/udevns/udevns.c
> new file mode 100644
> index 0000000..8b23751
> --- /dev/null
> +++ b/net/udevns/udevns.c
> @@ -0,0 +1,112 @@
> +#include <linux/module.h>
> +#include <linux/moduleparam.h>
> +#include <net/sock.h>
> +#include <net/genetlink.h>
> +#include <linux/netlink.h>
> +#include <linux/skbuff.h>
> +#include <linux/fs.h>
> +#include <linux/list.h>
> +#include <linux/slab.h>
> +#include <linux/uaccess.h>
> +#include <linux/kobject.h>
> +#include <linux/sysfs.h>
> +
> +#include "udevns.h"
> +
> +#define DRIVER_AUTHOR "Michael J Coss <michael.coss@alcatel-lucent.com>"
> +#define DRIVER_DESC   "new udev namespace bridge"
> +#define DEVICE_NAME   "udevns"
> +
> +#ifdef MODULE
> +#define UDEVNS_NAME (THIS_MODULE->name)
> +#else
> +#define UDEVNS_NAME "udevns"
> +#endif
> +
> +#define UDEVNS_INFO(fmt, args...)                                       \
> +	pr_info("[%s] " fmt, UDEVNS_NAME, ## args)
> +
> +#define UDEVNS_ERROR(fmt, args...)                                      \
> +	pr_err("[ERROR:%s:%s] " fmt, UDEVNS_NAME, __func__, ## args)
> +
> +#define UDEVNS_WARNING(fmt, args...)                                    \
> +	pr_warn("[WARNING:%s:%s] " fmt, UDEVNS_NAME, __func__, ## args)
> +
> +static struct genl_family udevns_genl_family = {
> +	.id      = GENL_ID_GENERATE,
> +	.name    = DEVICE_NAME,
> +	.hdrsize = 0,
> +	.version = UDEVNS_VERSION,
> +	.maxattr = UDEVNS_ATTR_MAX,
> +};
> +
> +static const struct nla_policy udevns_fmsgpolicy[UDEVNS_ATTR_MAX + 1] = {
> +	[UDEVNS_PID] = { .type = NLA_U32 },
> +	[UDEVNS_MSG] = { .type = NLA_STRING, .len =  UEVENT_BUFFER_SIZE},
> +};
> +
> +static int udevns_forwardmsg(struct sk_buff *skb, struct genl_info *info)
> +{
> +	pid_t pid;
> +	char *msg;
> +	int msglen;
> +	int err;
> +
> +	if (!info->attrs[UDEVNS_PID]) {
> +		UDEVNS_WARNING("missing PID from UDEVNS_FORWARD_MSG.\n");
> +		return -EINVAL;
> +	}
> +
> +	if (!info->attrs[UDEVNS_MSG]) {
> +		UDEVNS_WARNING("missing uevent from UDEVNS_FORWARD_MSG.\n");
> +		return -EINVAL;
> +	}
> +
> +	pid = nla_get_u32(info->attrs[UDEVNS_PID]);
> +	msg = nla_data(info->attrs[UDEVNS_MSG]);
> +	msglen = nla_len(info->attrs[UDEVNS_MSG]);
> +
> +	if (msglen < 0) {
> +		UDEVNS_ERROR("Malformed uevent from UDEVNS_FORWARD_MSG.\n");
> +		return -EINVAL;
> +	}
> +
> +	err = kobject_uevent_forward(msg, msglen, pid);
> +	return err;
> +}
> +
> +static struct genl_ops udevns_genl_ops[] = {
> +	{
> +		.cmd    = UDEVNS_FORWARD_MSG,
> +		.flags  = GENL_ADMIN_PERM,
> +		.doit   = udevns_forwardmsg,
> +		.policy = udevns_fmsgpolicy,
> +	},
> +};
> +
> +static int __init udevns_init(void)
> +{
> +	int rc;
> +
> +	UDEVNS_INFO("Starting udevns module\n");
> +	rc = genl_register_family_with_ops(&udevns_genl_family,
> +					   udevns_genl_ops);
> +	if (rc) {
> +		UDEVNS_ERROR("Failed to register netlink interface\n");
> +		return rc;
> +	}
> +	return 0;
> +}
> +
> +static void __exit udevns_exit(void)
> +{
> +	UDEVNS_INFO("Exiting udevns module\n");
> +	genl_unregister_family(&udevns_genl_family);
> +}
> +
> +module_init(udevns_init);
> +module_exit(udevns_exit);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION(DRIVER_DESC);
> +MODULE_AUTHOR(DRIVER_AUTHOR);
> diff --git a/net/udevns/udevns.h b/net/udevns/udevns.h
> new file mode 100644
> index 0000000..f5702f5
> --- /dev/null
> +++ b/net/udevns/udevns.h
> @@ -0,0 +1,19 @@
> +#ifndef _UDEVNS_H_
> +#define _UDEVNS_H_
> +
> +enum udevns_msg_types {
> +	UDEVNS_FORWARD_MSG = 0x1,
> +	UDEVNS_CMD_MAX,
> +};
> +
> +enum udevns_attr {
> +	UDEVNS_UNSPEC,
> +	UDEVNS_PID,
> +	UDEVNS_MSG,
> +	__UDEVNS_ATTR_MAX,
> +};
> +
> +#define UDEVNS_ATTR_MAX (__UDEVNS_ATTR_MAX - 1)
> +#define UDEVNS_VERSION 0x1
> +
> +#endif

  reply	other threads:[~2015-09-11  1:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-09  2:10 [PATCH 0/3] kobject: support namespace aware udev Michael J. Coss
2015-09-09  2:10 ` [PATCH 1/3] lib/kobject_uevent.c: disable broadcast of uevents to other namespaces Michael J. Coss
2015-09-11  0:36   ` Eric W. Biederman
2015-09-11 18:21     ` Michael J Coss
2015-09-09  2:10 ` [PATCH 2/3] lib/kobject_uevent.c: add uevent forwarding function Michael J. Coss
2015-09-09  3:55   ` Greg KH
2015-09-09 19:24     ` Michael J Coss
2015-09-09 20:11       ` Greg KH
2015-09-10  5:43         ` Amir Goldstein
2015-09-10  5:58           ` Greg KH
2015-09-11  0:54   ` Eric W. Biederman
2015-09-11 18:43     ` [COMMERCIAL] " Michael J Coss
2015-09-09  2:10 ` [PATCH 3/3] net/udevns: Netlink module to forward uevent to containers Michael J. Coss
2015-09-11  1:05   ` Eric W. Biederman [this message]
2015-09-11 19:01     ` Michael J Coss
2015-09-09  3:54 ` [PATCH 0/3] kobject: support namespace aware udev Greg KH
2015-09-09 19:05   ` Michael J Coss
2015-09-09 20:09     ` Greg KH
2015-09-09 20:16       ` Michael J Coss
2015-09-09 20:28         ` Greg KH
2015-09-09 20:55           ` [COMMERCIAL] " Michael J Coss
2015-09-10  5:21             ` Greg KH

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=87si6lvk8z.fsf@x220.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=containers@lists.linuxcontainers.org \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.coss@alcatel-lucent.com \
    --cc=serge.hallyn@ubuntu.com \
    --cc=stgraber@ubuntu.com \
    /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

all inboxes | Powered by JetHome®