Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10542222imu; Mon, 31 Dec 2018 01:40:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN624TKnrfdOLbLgVOcdKG0+NjKUe1BhGsOcGPvuYwnnspHlutLViluU0Jiubskj0tKeA985 X-Received: by 2002:a63:7418:: with SMTP id p24mr7025234pgc.196.1546249242347; Mon, 31 Dec 2018 01:40:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546249242; cv=none; d=google.com; s=arc-20160816; b=FkADb+etfleX6YkfRQt59paexZu7N9JnX93zzb78OqjewW3S9rt9YPQ71P/6poGaw9 +JrxHiEUJcaWRVu8L/g7Wbx5nbfQ0iZMp6apWinQuC4BmEGZBjoP+JcVJM9XsMMbQ6n5 zcPZmkaFqgv2sk6JZtCl3FhDhOkmLeEgIKitWBsYGS0D/BrlDnFSY/ZUYn+v9FqUg475 Hy5vEVScGE3n4fqZTJ0AtEVacvOBMhsu3wPvpdx7cG/004vSxYEhnutLGYsdoJABDi3F vN/zru88xE/pRdqseuvF0N+0n3j4JIENocel+jfEKJadJjzMNbC2yV+F00KMlkepWIga geAA== 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=XuzbDzmI6NWCoU33GnY/jJis/uqVdccY0TB5o5YcYqA=; b=A5s18Jt6vtdaPzAs5ExxXl/ME1EDvgACJOEyCbt2LHCRo/lio+TZYYLSyWFOY9bD8K 9P+gg7FcuQ48BdNnh2r/cMPYhXE64mJUBO+g/Rbex0gNa6PNWjKJvQCW3VKj0aFKoZz5 RChIP3eTHcaBgwK+PJANhyPWvksYD/+xTekujODh5fDPNCYlRGw7Ww9s5GIvD7hjGApg wOpb1AQ9n+Ob8QaQUqk1VEvYfYwnj7ejq3O6+hi84nlIltMxOc6DxIl+Zm/S/UoL+Jkk AsLUxItjm21hQai/6hPwDa0nGst2smS/mP82LDlYTWxuLA7IOnSEZmtQK7BzvTpctS3u BlAw== 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 k22si42854127pll.276.2018.12.31.01.40.24; Mon, 31 Dec 2018 01:40:42 -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 S1727132AbeLaJjd (ORCPT + 99 others); Mon, 31 Dec 2018 04:39:33 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:59830 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726457AbeLaJjc (ORCPT ); Mon, 31 Dec 2018 04:39:32 -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:39:30 +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:39:04 +0000 Date: Mon, 31 Dec 2018 17:38:51 +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 2/2] PM / Sleep: Check the file capability when writing wake lock interface Message-ID: <20181231093851.GN3506@linux-l9pv.suse> References: <20181230132856.24095-1-jlee@suse.com> <20181230132856.24095-3-jlee@suse.com> <20181230144835.GB18985@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181230144835.GB18985@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, On Sun, Dec 30, 2018 at 03:48:35PM +0100, Greg Kroah-Hartman wrote: > On Sun, Dec 30, 2018 at 09:28:56PM +0800, Lee, Chun-Yi wrote: > > The wake lock/unlock sysfs interfaces check that the writer must has > > CAP_BLOCK_SUSPEND capability. But the checking logic can be bypassed > > by opening sysfs file within an unprivileged process and then writing > > the file within a privileged process. The tricking way has been exposed > > by Andy Lutomirski in CVE-2013-1959. > > Don't you mean "open by privileged and then written by unprivileged?" > Or if not, exactly how is this a problem? You check the capabilities > when you do the write and if that is not allowed then, well > Sorry for I didn't provide clear explanation. The privileged means CAP_BLOCK_SUSPEND but not file permission. The file permission has already relaxed for non-root user. Then the expected behavior is that non-root process must has CAP_BLOCK_SUSPEND capability for writing wake_lock sysfs. But, the CAP_BLOCK_SUSPEND restrict can be bypassed: int main(int argc, char* argv[]) { int fd, ret = 0; fd = open("/sys/power/wake_lock", O_RDWR); if (fd < 0) err(1, "open wake_lock"); if (dup2(fd, 1) != 1) // overwrite the stdout with wake_lock err(1, "dup2"); sleep(1); execl("./string", "string"); //string has capability return ret; } This program is an unpriviledged process (has no CAP_BLOCK_SUSPEND), it opened wake_lock sysfs and overwrited stdout. Then it executes the "string" program that has CAP_BLOCK_SUSPEND. The string program writes to stdout, which means that it writes to wake_lock. So an unpriviledged opener can trick an priviledged writer for writing sysfs. > And you are checking the namespace of the person trying to do the write > when the write happens, which is correct here, right? > > If you really want to mess with wake locks in a namespaced environment, > then put it in a real namespaced environment, which is {HUGE HINT} not > sysfs. > I don't want to mess with wake locks in namespace. > So no, this patch isn't ok... > Thanks a lot! Joey Lee