Received: by 10.213.65.68 with SMTP id h4csp1545756imn; Thu, 15 Mar 2018 02:48:48 -0700 (PDT) X-Google-Smtp-Source: AG47ELvoB6+f2oBqL3m4l9hlqbou8xo3Ic9UFjzPim97KJ2ScLWPGgV0gb1eVGzrRICA9nBzyU1w X-Received: by 2002:a17:902:bd8e:: with SMTP id q14-v6mr3670962pls.19.1521107328834; Thu, 15 Mar 2018 02:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521107328; cv=none; d=google.com; s=arc-20160816; b=eys0dx9cZCOeKQXGqggmjLI7Sl41DTlK3YHkLv4/wP4OuG2c6pZsPHkdU6K1nOQlwG oeQ1c+NUnTwAMQjxX33aYiKRaLfDwb8OJcpoikiFN4kdrdFQ84EFpaMfg2DsPIUU1wYt o9Z2l6FeWiF5j4pRWqaJMoY1qbeG4j99czdqS0nwsBQelTcvULuFVoMrFYSogVuQEGbF ym2sK9peJ54ghS0BPKEdYKUPF6ZY9howIhUHSezwDZk/eBPE14WRv1qNadRkwRPSV4yV +eP01jQhwwj7SxjPjiuSLuo3RQYISqxc0frd3xtnWHlyP7+zLeieXYYnkez68WFoDG9N jhcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:arc-authentication-results; bh=P71FH2dHKrszCVxho7Qw7g0ca712eLyfaI+NjItsLs4=; b=MbWBaGABmBQ2bvluXpfM4kEd7NX4sb9ye5wvlYWq2KzUbf2T+C36nRAhTEaZrIqJ2M ozUgoK4R/yjL9XqorsVy26NlCNd6YfpnaTsca1YtcEs+s57hSipG/y1vVuv+HeZbhiyb /C5KoDKlyWHMXNbuS6FOHR091ZweFuFpU61iYZeN1q+LCI7kObcSV74wR0FBx2yNCFtX MMJ05zocerKHyCGdLJWsEfg2shm+meGrQsMRk0SnIFunb9Fz5nKVaMzh5Xmc1MXwNspr 9Twg6R5yivVLzbgUWzmFVdOn2upYQnGQq5HwCHQiALRBDK8dWQ/+7cbAcw4nuXtZD7AZ SARg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=LCxvhSpp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89-v6si3716607pla.572.2018.03.15.02.48.34; Thu, 15 Mar 2018 02:48:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=LCxvhSpp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751757AbeCOJrk (ORCPT + 99 others); Thu, 15 Mar 2018 05:47:40 -0400 Received: from mail-db5eur01on0101.outbound.protection.outlook.com ([104.47.2.101]:28768 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751652AbeCOJrh (ORCPT ); Thu, 15 Mar 2018 05:47:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=P71FH2dHKrszCVxho7Qw7g0ca712eLyfaI+NjItsLs4=; b=LCxvhSppNK1NMLxFpniAeBY3RVPGgTaFwzFaysREYpL9KCD9v4a/0LieaKIpGuKt88WTSAtyM05P8fvSsnPv5RW/INL10laznrm19l4JNjf27vCMY3FBApUV6Qo4AUUavL8qYl1uLhmhsj0+TPPrp0pJifZ5ATSimbnFR5VJ4us= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from [172.16.25.196] (195.214.232.6) by DB6PR0801MB1336.eurprd08.prod.outlook.com (2603:10a6:4:b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.567.14; Thu, 15 Mar 2018 09:47:33 +0000 Subject: Re: netns: send uevent messages To: Christian Brauner , ebiederm@xmission.com, gregkh@linuxfoundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: serge@hallyn.com, avagin@virtuozzo.com References: <20180315001214.19462-1-christian.brauner@ubuntu.com> From: Kirill Tkhai Message-ID: Date: Thu, 15 Mar 2018 12:47:30 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180315001214.19462-1-christian.brauner@ubuntu.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0802CA0006.eurprd08.prod.outlook.com (2603:10a6:3:bd::16) To DB6PR0801MB1336.eurprd08.prod.outlook.com (2603:10a6:4:b::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cdff33fc-7d7c-4290-aa6f-08d58a59c742 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603328)(7153060)(7193020);SRVR:DB6PR0801MB1336; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1336;3:KqYcqD84+u46vpisO36phRSIPgiGjDgCn3eQqUiT7A/B8ikeNi3a16cmf1UI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eHG61F0B/o1pINQC5+DiUUgWS6pW7hA1OmwSrFi+dtEHEoZykxMRYI7T5txbatGOnsEf5m8gFzFLPzg+PXx7PbMjp43WZrXIugFTWY8YFs/ZWe81TzDrpn9sWvNyuBur5y9G2xnpn/iV7Yf0wkSpA8v7PHwEoEqXVUfW3jb8im4fnN/sX55TNNu+yiA9NGVieeq1yWBjBWD3/Fif9D+9CTMRL+leMWTj73nVpVQyeWg16yRgWeJYCphfi/Y1U+GsPiZaHHXaGOosj6VDFOi//4OHgtKJ;4:ps9AYuqUqcv857qkSxHoWbSfLcclfbmui1Z+MMaF6J11s8uDAwjcQFk09rrepOReGVyHX8YZEc3rgpQsn/HXxRjpnFdWQZg6W+J8y7q+IYLjNA3r1hjdNz96ve7E6pawLiZU7cIZ0IDmRWDR9nYwB7nQaeLt4ea6aydkmXGEryUF3Hejcpb5nKvxIIyMoRIjrxTJB2fUYZ7Jb1SpZSuznuwLe8irbeqsWmntqR/yYbdhsNlu4pOsMh/Dh113n11cMfwCLjdzX/FlWonVwk6pHUv11zqL68EQD6t+Nr2Z1QZ5VSLmWgkcVOsS6L8aqJhXdZKICm1+yziKYb6MQN/PQEWTH8AAF99vlEvvWlMFYzKr90YIdQIQgbSRg0LYxZJ7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192374486261705)(788757137089)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3231221)(944501244)(52105095)(93006095)(93001095)(3002001)(10201501046)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011);SRVR:DB6PR0801MB1336;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0801MB1336; X-Forefront-PRVS: 0612E553B4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6049001)(366004)(396003)(39380400002)(346002)(39850400004)(376002)(199004)(189003)(31686004)(3846002)(64126003)(66066001)(65806001)(386003)(97736004)(47776003)(4326008)(53546011)(230700001)(50466002)(6486002)(25786009)(59450400001)(36756003)(106356001)(316002)(65956001)(16526019)(77096007)(6116002)(76176011)(2950100002)(68736007)(305945005)(58126008)(105586002)(16576012)(478600001)(2906002)(26005)(6246003)(65826007)(5660300001)(8676002)(52146003)(8936002)(53936002)(86362001)(7736002)(81156014)(81166006)(229853002)(23676004)(15650500001)(2486003)(107886003)(52116002)(31696002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0801MB1336;H:[172.16.25.196];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtEQjZQUjA4MDFNQjEzMzY7MjM6MUc5RFMzUDUxY2FOWncxaEtTTy90Qm03?= =?utf-8?B?WDZQZXR0eWJXdmtyWGNmd3MyRXBXUWJmdXVUcmhqcU1aSWpucFlvZDJpSE9R?= =?utf-8?B?dS9kNVU3VjZPajVRNWk4UVFRckd6L0wwMUtEbkpQd0ZEQ3o1RDhTNjc0R1c5?= =?utf-8?B?YmNZOVNtQ3Fvci8yNE1Id3NuWUJGbXJHSVREdlEzMDIyT0RuQ0FmRnhJcllm?= =?utf-8?B?WUFYYWVQQnRwVkVFZVNVY1J3YUlHV3JVWGhMbmNpZzRWbWRNRGhEaUFObWxs?= =?utf-8?B?aFRLRE5KRTRvbE1WdTMwWW0wYTZTUTU3SVNTajVVR096eG1WY1A3V0MzTFJQ?= =?utf-8?B?WFkwWU83TGY3UXhHTWQ1aUZxcGdYSHJHWllyYXAyak5jUkdQQ2paaStLQzZF?= =?utf-8?B?Mlo5WXdmVnFOTTdxVmt1K0lZRjhFK3FLRFJQUjhxYlFxbFZISVRGWjJBVWcx?= =?utf-8?B?Mk1maTFkZEcxTy9HTG9mVWYxbW93R3YxODhVTGVGNzVYb0hncGs4RElWclhm?=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hfYioWLtCZ+cVONHO+Yofo5RhGdWsUnz2JPOs15vW8qo+AAw9iCVcuqtI2Y1VHko=;5:B/VHDrqA8aD3xFkuubLpgp7XyRdDzYVbp69Xj6t0gAbRdECP0VHZiqXQHJYpN8VNlS36efJVm2X2+TuxuB984amydfbHRfbnCBB6mL+oOmHPfVFk0ei9cnekPOzJM9sQDYWYCtHNg+f4mp4hBr73+jzjB+932zCe3CWHuknS5G4=;24:Vudm6Gc4McxtsE+kaoFHea6pD19MPvgEMXm47KLrI8HCvY8yVU2NkX/x7m3/WfJ2vJlivlMUvVp4ff+CsrqZ/KxdySvaWS57Lu8dXFSr7wY=;7:4/ilAxfvWNQLlvq2mwqzGgAmUe0reU82SLtJd5vDBQhijeNLwC2GBU29A5NT2zLwpEv2OCsiNaE7xldNkQpwrAgctdPFo6WXtKcY/OgIkuFkLJEp50oC9dM7xV9oZS8NZVEI3tOfl6y8Xv4DoUuW+W/7F2aF0i72TuDh3iu7nSFfGQMdG55G7BDqdHmhroiSOib3dZFEiBwT8tMQQ6h6P406xT+l5hif7YEexwu7Wek/zjaydGiCr2+LDPoRXt9F SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1336;20:mCWhNEXTZN0uttpqzUgH7PBz6EXK6Zq7M04mkJogiGsOc/2k1T9dBmiSMKtIh5+jFqA08waqNISLC3jE/Zv7YCHxN31SmdbS+r4ZAPo7vAVMseMXSI0jn5ZHHERNvsKLt/IlIbRpNYi9WY8hHqQiBBw+FFnmSAecdCIoxfOZCiw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2018 09:47:33.5675 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cdff33fc-7d7c-4290-aa6f-08d58a59c742 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1336 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CC Andrey Vagin On 15.03.2018 03:12, Christian Brauner wrote: > This patch adds a receive method to NETLINK_KOBJECT_UEVENT netlink sockets > to allow sending uevent messages into the network namespace the socket > belongs to. > > Currently non-initial network namespaces are already isolated and don't > receive uevents. There are a number of cases where it is beneficial for a > sufficiently privileged userspace process to send a uevent into a network > namespace. > > One such use case would be debugging and fuzzing of a piece of software > which listens and reacts to uevents. By running a copy of that software > inside a network namespace, specific uevents could then be presented to it. > More concretely, this would allow for easy testing of udevd/ueventd. > > This will also allow some piece of software to run components inside a > separate network namespace and then effectively filter what that software > can receive. Some examples of software that do directly listen to uevents > and that we have in the past attempted to run inside a network namespace > are rbd (CEPH client) or the X server. > > Implementation: > The implementation has been kept as simple as possible from the kernel's > perspective. Specifically, a simple input method uevent_net_rcv() is added > to NETLINK_KOBJECT_UEVENT sockets which completely reuses existing > af_netlink infrastructure and does neither add an additional netlink family > nor requires any user-visible changes. > > For example, by using netlink_rcv_skb() we can make use of existing netlink > infrastructure to report back informative error messages to userspace. > > Furthermore, this implementation does not introduce any overhead for > existing uevent generating codepaths. The struct netns gets a new uevent > socket member that records the uevent socket associated with that network > namespace. Since we record the uevent socket for each network namespace in > struct net we don't have to walk the whole uevent socket list. > Instead we can directly retrieve the relevant uevent socket and send the > message. This keeps the codepath very performant without introducing > needless overhead. > > Uevent sequence numbers are kept global. When a uevent message is sent to > another network namespace the implementation will simply increment the > global uevent sequence number and append it to the received uevent. This > has the advantage that the kernel will never need to parse the received > uevent message to replace any existing uevent sequence numbers. Instead it > is up to the userspace process to remove any existing uevent sequence > numbers in case the uevent message to be sent contains any. > > Security: > In order for a caller to send uevent messages to a target network namespace > the caller must have CAP_SYS_ADMIN in the owning user namespace of the > target network namespace. Additionally, any received uevent message is > verified to not exceed size UEVENT_BUFFER_SIZE. This includes the space > needed to append the uevent sequence number. > > Testing: > This patch has been tested and verified to work with the following udev > implementations: > 1. CentOS 6 with udevd version 147 > 2. Debian Sid with systemd-udevd version 237 > 3. Android 7.1.1 with ueventd > > Signed-off-by: Christian Brauner > --- > include/net/net_namespace.h | 1 + > lib/kobject_uevent.c | 88 ++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 88 insertions(+), 1 deletion(-) > > diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h > index f306b2aa15a4..467bde763a9b 100644 > --- a/include/net/net_namespace.h > +++ b/include/net/net_namespace.h > @@ -78,6 +78,7 @@ struct net { > > struct sock *rtnl; /* rtnetlink socket */ > struct sock *genl_sock; > + struct sock *uevent_sock; /* uevent socket */ Since you add this per-net uevent_sock pointer, currently existing iterations in uevent_net_exit() become to look confusing. There are: mutex_lock(&uevent_sock_mutex); list_for_each_entry(ue_sk, &uevent_sock_list, list) { if (sock_net(ue_sk->sk) == net) goto found; } Can't we make a small cleanup in lib/kobject_uevent.c after this change and before the main part of the patch goes? > > struct list_head dev_base_head; > struct hlist_head *dev_name_head; > diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c > index 9fe6ec8fda28..10b2144b9fc3 100644 > --- a/lib/kobject_uevent.c > +++ b/lib/kobject_uevent.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > #include > > > @@ -602,12 +603,94 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) > EXPORT_SYMBOL_GPL(add_uevent_var); > > #if defined(CONFIG_NET) > +static int uevent_net_send(struct sock *usk, struct sk_buff *skb, > + struct netlink_ext_ack *extack) > +{ > + int ret; > + u64 seqnum; > + /* u64 to chars: 2^64 - 1 = 21 chars */ 18446744073709551615 -- 20 chars (+1 '\0'). Comment makes me think we forgot +1 in buf declaration. > + char buf[sizeof("SEQNUM=") + 21]; > + struct sk_buff *skbc; > + > + /* bump sequence number */ > + mutex_lock(&uevent_sock_mutex); > + seqnum = ++uevent_seqnum; > + mutex_unlock(&uevent_sock_mutex); Commit 7b60a18da393 from Andrew Vagin says: uevent: send events in correct order according to seqnum (v3) The queue handling in the udev daemon assumes that the events are ordered. Before this patch uevent_seqnum is incremented under sequence_lock, than an event is send uner uevent_sock_mutex. I want to say that code contained a window between incrementing seqnum and sending an event. This patch locks uevent_sock_mutex before incrementing uevent_seqnum. Signed-off-by: Andrew Vagin After this change the order will be lost. Also the rest of namespaces will have holes in uevent numbers, as they won't receive a number sent to specific namespace. It seems we should made uevent_seqnum per-net to solve this problem. > + /* prepare sequence number */ > + ret = snprintf(buf, sizeof(buf), "SEQNUM=%llu", seqnum); > + if (ret < 0 || (size_t)ret >= sizeof(buf)) > + return -ENOMEM;> + ret++; > + > + /* verify message does not overflow */ > + if ((skb->len + ret) > UEVENT_BUFFER_SIZE) { > + NL_SET_ERR_MSG(extack, "uevent message too big"); > + return -EINVAL; > + } > + > + /* copy skb and extend to accommodate sequence number */ > + skbc = skb_copy_expand(skb, 0, ret, GFP_KERNEL); > + if (!skbc) > + return -ENOMEM; > + > + /* append sequence number */ > + skb_put_data(skbc, buf, ret); > + > + /* remove msg header */ > + skb_pull(skbc, NLMSG_HDRLEN); > + > + /* set portid 0 to inform userspace message comes from kernel */ > + NETLINK_CB(skbc).portid = 0; > + NETLINK_CB(skbc).dst_group = 1; > + > + ret = netlink_broadcast(usk, skbc, 0, 1, GFP_KERNEL); > + /* ENOBUFS should be handled in userspace */ > + if (ret == -ENOBUFS || ret == -ESRCH) > + ret = 0; > + > + return ret; > +} > + > +static int uevent_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, > + struct netlink_ext_ack *extack) > +{ > + void *msg; > + struct net *target_net; > + struct sock *target_sk; > + > + msg = nlmsg_data(nlh); > + if (!msg) > + return -EINVAL; > + > + target_net = sock_net(NETLINK_CB(skb).sk); > + target_sk = target_net->uevent_sock; > + > + /* > + * Verify that we are allowed to send messages to the target network > + * namespace. The caller must have CAP_SYS_ADMIN in the owning user > + * namespace of the target network namespace. > + */ > + if (!netlink_ns_capable(skb, target_net->user_ns, CAP_SYS_ADMIN)) { > + NL_SET_ERR_MSG(extack, "missing CAP_SYS_ADMIN capability"); > + return -EPERM; > + } > + > + return uevent_net_send(target_sk, skb, extack); > +} > + > +static void uevent_net_rcv(struct sk_buff *skb) > +{ > + netlink_rcv_skb(skb, &uevent_rcv_msg); > +} > + > static int uevent_net_init(struct net *net) > { > struct uevent_sock *ue_sk; > struct netlink_kernel_cfg cfg = { > .groups = 1, > - .flags = NL_CFG_F_NONROOT_RECV, > + .input = uevent_net_rcv, > + .flags = NL_CFG_F_NONROOT_RECV > }; > > ue_sk = kzalloc(sizeof(*ue_sk), GFP_KERNEL); > @@ -621,6 +704,9 @@ static int uevent_net_init(struct net *net) > kfree(ue_sk); > return -ENODEV; > } > + > + net->uevent_sock = ue_sk->sk; > + > mutex_lock(&uevent_sock_mutex); > list_add_tail(&ue_sk->list, &uevent_sock_list); > mutex_unlock(&uevent_sock_mutex); Kirill