Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10544384imu; Mon, 31 Dec 2018 01:43:52 -0800 (PST) X-Google-Smtp-Source: AFSGD/XHXwTH1qQ7s1lG/I110fhNr1PgaHjZzlHkrxoXdrll1KZP3VL/960ToMIJt40V3gu0IwOk X-Received: by 2002:a62:1b50:: with SMTP id b77mr37677788pfb.36.1546249432570; Mon, 31 Dec 2018 01:43:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546249432; cv=none; d=google.com; s=arc-20160816; b=QaKaErbxD+TjqassSTZv4hz3Qe8fZnhd+fLbNqoSnvAE4F4wx6rIk44hrOH4DOEI5w J0aoeoVXOhXRu4SheTVPia0MNbrf2BDgWCQqdoJXOnPCyhISkpa4Xaazqd3bKXorrCwe 84aCFyuWMcNBJyN0WZrVBr7CrnvQ/wzE8YfSA/vRwAbhDJwxkOVlMXvkyqjyeeREzykx 0KYapfJD2CK+R8UEAfHhFowwvk5me2C+z10y3Qe9i0fKQTtNRmEPRPz2dbGP3W+tfGEu hRP03kzaeAp46D6QL5NW2/ksgM7p0WqgxO1hzsjJQchnC1HmJrcM8CkiK4KOg1FD4jXZ ELZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0QSFncDnVkVm2RIuWWTTEo5dJN8ypgj1yPneaqchuIw=; b=Yqm45B21bI1n/U8Lcq6jwZeDG/Y951C0vCzjHgBzaE51CBli70Kod9ebMfhZ364SO5 PJn6RWUHP/9sAwp58XzP9QiTAamLXzoX1IB6Fb5CV+YHGBnRESwIqFdK5L5le6Am1Unv gT5r/QFJ02KndLZKAG6pEGRPNqny3qXgW8YT0jWRVQBj8w2Zx3I3m8x+UXjRbSfYqm9J wHGStVEHSAWX9YaD/QPkeZvcI7PrLdea0Dihjh3kM0eB5lFC2K3fnZpWG8JsCU1kj37j vGPa4mgl9AUYOZHpbWoPFQcqTmvjXlG0b4zRwJhsyHVOcPZH3dKlaA6gAmtnR052yE/O Ttog== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si24194624pgd.68.2018.12.31.01.43.37; Mon, 31 Dec 2018 01:43:52 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727228AbeLaJlb (ORCPT + 99 others); Mon, 31 Dec 2018 04:41:31 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:50468 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727142AbeLaJlb (ORCPT ); Mon, 31 Dec 2018 04:41:31 -0500 Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Mon, 31 Dec 2018 10:41:29 +0100 Received: from linux-l9pv.suse (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Mon, 31 Dec 2018 09:41:16 +0000 Date: Mon, 31 Dec 2018 17:41:05 +0800 From: joeyli To: Greg Kroah-Hartman Cc: "Lee, Chun-Yi" , "Rafael J . Wysocki" , Pavel Machek , Len Brown , "Martin K . Petersen" , Randy Dunlap , Joe Perches , Bart Van Assche , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Chen Yu , Giovanni Gherdovich , Jann Horn , Andy Lutomirski Subject: Re: [PATCH 0/2] [RFC] sysfs: Add hook for checking the file capability of opener Message-ID: <20181231094105.GO3506@linux-l9pv.suse> References: <20181230132856.24095-1-jlee@suse.com> <20181230144506.GA18985@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181230144506.GA18985@kroah.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, Thanks for your review! On Sun, Dec 30, 2018 at 03:45:06PM +0100, Greg Kroah-Hartman wrote: > On Sun, Dec 30, 2018 at 09:28:54PM +0800, Lee, Chun-Yi wrote: > > There have some discussion in the following mail loop about checking > > capability in sysfs write handler: > > https://lkml.org/lkml/2018/9/13/978 > > A sysfs callback should not care about stuff like this. > > Worst case, do a simple: > if (!capable(CAP_FOO)) > return -EPERM > > you don't care or need to worry about the file handle for that at all, > right? > The capable() can be bypassed. Unprivileged process may reads or writes those sysfs if file permission be relaxed by root for non-root user. > > Sometimes we check the capability in sysfs implementation by using > > capable function. > > Which should be fine, right? > If file permission is enough to restrict sysfs that can only be used by root. Why do some sysfs interfaces use capable()? It's not redundancy? > > But the checking can be bypassed by opening sysfs > > file within an unprivileged process then writing the file within a > > privileged process. The tricking way has been exposed by Andy Lutomirski > > for CVE-2013-1959. > > And who does this for a sysfs file? And why? > Just want to bypass the capable() checking. > > Because the sysfs_ops does not forward the file descriptor to the > > show/store callback, there doesn't have chance to check the capability > > of file's opener. > > Which is by design. If you care about open, you are using sysfs wrong. > OK~ So the sysfs doesn't care opener's capability. > > This patch adds the hook to sysfs_ops that allows > > different implementation in object and attribute levels for checking > > file capable before accessing sysfs interfaces. > > No, please no. > > > The callback function of kobject sysfs_ops is the first implementation > > of new hook. It casts attribute to kobj_attribute then calls the file > > capability callback function of attribute level. The same logic can > > be implemented in other sysfs file types, like: device, driver and > > bus type. > > > > The capability checking logic in wake_lock/wake_unlock sysfs interface > > is the first example for kobject. It will check the opener's capability. > > Why doesn't the file permission of that sysfs file determine who can or > can not write to that file? > I agree that the file permission can restrict the writer of sysfs. But, I still confused for why do some sysfs interface use capable()? Thanks a lot! Joey Lee