Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754523AbbK3StF (ORCPT ); Mon, 30 Nov 2015 13:49:05 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:10337 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754061AbbK3StB (ORCPT ); Mon, 30 Nov 2015 13:49:01 -0500 X-AuditID: cbfec7f5-f79b16d000005389-65-565c9a194cc7 Subject: Re: [PATCH v1 0/1] ioctl to disallow detaching kernel USB drivers To: Greg KH References: <565C8376.6070505@samsung.com> <20151130172028.GA1088@kroah.com> Cc: Alan Stern , =?UTF-8?Q?Emilio_L=c3=b3pez?= , kborer@gmail.com, reillyg@chromium.org, keescook@chromium.org, linux-api@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, jorgelo@chromium.org, dan.carpenter@oracle.com From: Krzysztof Opasiak Message-id: <565C9A18.6000006@samsung.com> Date: Mon, 30 Nov 2015 19:48:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-version: 1.0 In-reply-to: <20151130172028.GA1088@kroah.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRmVeSWpSXmKPExsVy+t/xq7qSs2LCDD7N0bJ4/W86i0XHozVM Fs2L17NZtEy8yWqx/PRxVosz3bkWm793sFlc3jWHzWLRslZmi/NbDzBbTPh9gc2B22N2w0UW j7/Pr7N47Jx1l91j/9w17B4fn95i8Zh99wejx+dNcgHsUVw2Kak5mWWpRfp2CVwZLRM3sBR8 laj4v+woWwNjk0gXIyeHhICJROO1dWwQtpjEhXvrgWwuDiGBpYwSs7dvYQVJCAk8Z5SYcM8b xBYW8JJY+WMHWIOIgIbEy6O3WCAa+hklLs6eDuYwC2xmkti/dRtQFQcHm4C+xLxdoiANvAJa Eheu9oANZRFQlVh+aQYLiC0qECFx6uxbNogaQYkfk++BxTkF9CRm/p4NFmcWsJVY8H4dC4Qt L7F5zVvmCYwCs5C0zEJSNgtJ2QJG5lWMoqmlyQXFSem5RnrFibnFpXnpesn5uZsYIRHydQfj 0mNWhxgFOBiVeHglzKLDhFgTy4orcw8xSnAwK4nw7s6NCRPiTUmsrEotyo8vKs1JLT7EKM3B oiTOO3PX+xAhgfTEktTs1NSC1CKYLBMHp1QDY+y7JUkmnqq3Z55Z/8bIyODVpB2Xehw2TXe4 Jc3kutB6ptly1r7LTIzv99mFrfqkv3y+bO1uZXt7nY2f9CtFyyOUK3ltWmrsF3mJrTm+a/FT Rcl2kb6t8xedNt59cv6yrZdNDCp9efkWl69Q9zXcdfxqLV9qgpcq2+VjrEqBIeyHLhRZB3/5 psRSnJFoqMVcVJwIAMr3rOmMAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3374 Lines: 69 On 11/30/2015 06:20 PM, Greg KH wrote: > On Mon, Nov 30, 2015 at 06:12:22PM +0100, Krzysztof Opasiak wrote: >> >> >> On 11/30/2015 05:16 PM, Alan Stern wrote: >>> On Fri, 27 Nov 2015, Krzysztof Opasiak wrote: >>> >>>>>> I run through your code and as far as I understand above is not exactly >>>>>> true. Your patch allows only to prevent userspace from accessing interfaces >>>>>> which has kernel drivers, there is no way to stop an application from taking >>>>>> control over all free interfaces. >>>>>> >>>>>> Let's say that your device has 3 interfaces. First of them has a kernel >>>>>> driver but second and third doesn't. You have 2 apps. One should communicate >>>>>> using second interface and another one third. But first app is malicious and >>>>>> it claims all free interfaces of received device (your patch doesn't prevent >>>>>> this). And when second app starts it is unable to do anything with the >>>>>> device because all interfaces are taken. How would you like to handle this? >>>>> >>>>> You can't, and why would you ever want to, as you can't tell what an app >>>>> "should" or "should not" do. If you really care about this, then use a >>>>> LSM policy to prevent this. >>>> >>>> Well, an app can declare what it does and what it needs in it's manifest >>>> file (or some equivalent of this) and the platform should ensure that >>>> app can do only what it has declared. >>>> >>>> I would really like to use LSM policy in here but currently it is >>>> impossible as one device node represents whole device. Permissions (even >>>> those from LSM) are being checked only on open() not on each ioctl() so >>>> as far as I know there is nothing which prevents any owner of opened fd >>>> to claim all available (not taken by someone else) interfaces and LSM >>>> policy is unable to filter those calls (unless we add some LSM hooks >>>> over there). >>> >>> How about this approach? Once a process has dropped its usbfs >>> privileges, it's not allowed to claim any interfaces (either explicitly >>> or implicitly). Instead, it or some manager program must claim the >>> appropriate interfaces before dropping privileges. >>> >> >> I agree that restricting interface claiming only to privileged process is a >> good idea. Unfortunately this generates a problem when program needs more >> than one interface (like in cdc - data + control for example). We need to >> declare both of them in first call to "usb-manager" or reopen the dev node >> at second call and claim all interfaces claimed using this fd till now and >> claim one more and then drop privileges and send a new fd. > > Have you seen such a device that is controlled this way in userspace? > Don't over-engineer something that is probably pretty rare... > Yes I have seen such devices (not cdc of course) and they were driven using libusb (vendor specific service + "driver" to bypass publishing protocol code due to kernel's GPL). I have even seen an android app written in java which claims and uses multiple interfaces using android's USB API, so it's real;) -- Krzysztof Opasiak Samsung R&D Institute Poland Samsung Electronics -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/