Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp963058imm; Fri, 13 Jul 2018 09:09:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfUjxUTMqX18JvqJUf23HwxWJ1OSNptJAQSAKC0EzzK3pYDpev025rU5cuAyKyPzP9kKfWw X-Received: by 2002:a62:d94a:: with SMTP id s71-v6mr7653919pfg.164.1531498159606; Fri, 13 Jul 2018 09:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531498159; cv=none; d=google.com; s=arc-20160816; b=Wn4+G33F3U6q5LUWEwn6WhLEf9qk2PlCh/cB9Jwu0TbqASZvB14JtrWD65ZehRftsP +g7pWiKT16+CNtxUrKrCHT00n9Tu3aCX1YMaaVtLycVAEghX3xDvC48jk6iwuDSM52wF 18pqN9wg7uXCEkQ2/XFnyf88PesDYSweR4337ERnZUeWmLntksQcGK+AC6Td4euLkAtp ZOgjhJIxk3lwVSBKsmyDmqpkFeIMNDL/Z/0yR0lYwHtuXdaw0uce2EI18LB5N52LaJ9o +5FlWkZ3XvCv4ddY1YhEXWlvA46I8NXVTRtLptBd+tVw2EHaG08i7y9agboqp2F/Wv+X JmbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=NjIlRXO3KZMAxz5ts2YT5oPBE3hjzPWTvSLj8Z633Cs=; b=lVUJzteDlEqim/596f77SjbJ7lFl64a3B5FoOlVwu/TmUu5V+FRmxTeekmMtbJtHjU du35V9p+/PlLOpKA2/otJ94m96wXPBJoGJ1KYAGC+33qI4czEuyScwJ170euFSbi98iZ 66ZL6OhaqEZah8tolPGsXsArE/GCujVs7txn4cz9U1dtsRkiFCHrECeMtKJT9ngKG8+P xmYXK0SDKInEmWEyVtCcUTEaBWosmgDLzLczHo2nZd+INPrfKM+/mEgn3in1t1873X7a AgThB6wvFlngXUHmcxhj4bhcapg7PPWSGXX/PE+EAtujvgQSuaF83MqKcy6XqgYuKpH6 ywLQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4-v6si23313272plp.128.2018.07.13.09.08.59; Fri, 13 Jul 2018 09:09:19 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732746AbeGMQXb (ORCPT + 99 others); Fri, 13 Jul 2018 12:23:31 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38397 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729784AbeGMQXb (ORCPT ); Fri, 13 Jul 2018 12:23:31 -0400 Received: from 2.general.tyhicks.us.vpn ([10.172.64.53] helo=sec.ubuntu-ci) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1fe0c8-0006pX-L1; Fri, 13 Jul 2018 16:08:12 +0000 From: Tyler Hicks To: Greg Kroah-Hartman , Tejun Heo , "David S. Miller" , Stephen Hemminger Cc: Dmitry Torokhov , "Eric W. Biederman" , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bridge@lists.linux-foundation.org, Linux Containers Subject: [PATCH net-next v2 4/7] driver core: set up ownership of class devices in sysfs Date: Fri, 13 Jul 2018 16:05:46 +0000 Message-Id: <1531497949-1766-5-git-send-email-tyhicks@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531497949-1766-1-git-send-email-tyhicks@canonical.com> References: <1531497949-1766-1-git-send-email-tyhicks@canonical.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Torokhov Plumb in get_ownership() callback for devices belonging to a class so that they can be created with uid/gid different from global root. This will allow network devices in a container to belong to container's root and not global root. Signed-off-by: Dmitry Torokhov Reviewed-by: Tyler Hicks --- drivers/base/core.c | 9 +++++++++ include/linux/device.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index df3e1a44707a..276c7e3f754c 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -866,10 +866,19 @@ static const void *device_namespace(struct kobject *kobj) return ns; } +static void device_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid) +{ + struct device *dev = kobj_to_dev(kobj); + + if (dev->class && dev->class->get_ownership) + dev->class->get_ownership(dev, uid, gid); +} + static struct kobj_type device_ktype = { .release = device_release, .sysfs_ops = &dev_sysfs_ops, .namespace = device_namespace, + .get_ownership = device_get_ownership, }; diff --git a/include/linux/device.h b/include/linux/device.h index 055a69dbcd18..fe6ccb6dc119 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -384,6 +384,9 @@ int subsys_virtual_register(struct bus_type *subsys, * @shutdown_pre: Called at shut-down time before driver shutdown. * @ns_type: Callbacks so sysfs can detemine namespaces. * @namespace: Namespace of the device belongs to this class. + * @get_ownership: Allows class to specify uid/gid of the sysfs directories + * for the devices belonging to the class. Usually tied to + * device's namespace. * @pm: The default device power management operations of this class. * @p: The private data of the driver core, no one other than the * driver core can touch this. @@ -413,6 +416,8 @@ struct class { const struct kobj_ns_type_operations *ns_type; const void *(*namespace)(struct device *dev); + void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid); + const struct dev_pm_ops *pm; struct subsys_private *p; -- 2.7.4