Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756515AbcJGVSr (ORCPT ); Fri, 7 Oct 2016 17:18:47 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:46858 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750975AbcJGVSh (ORCPT ); Fri, 7 Oct 2016 17:18:37 -0400 Date: Fri, 7 Oct 2016 17:18:18 -0400 From: Calvin Owens To: Al Viro CC: Jeff Layton , "J. Bruce Fields" , Rusty Russell , , , Subject: Re: [PATCH] fs: Assert on module file_operations without an owner Message-ID: <20161007211818.GA84073@calvinowens-mba> References: <48414ef29337b54e2a842bd841f73f01ab74ebe7.1475872278.git.calvinowens@fb.com> <20161007204836.GR19539@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20161007204836.GR19539@ZenIV.linux.org.uk> User-Agent: Mutt/1.6.1 (2016-04-27) X-Originating-IP: [2620:10d:c091:200::3:fd25] X-ClientProxiedBy: CY4PR09CA0005.namprd09.prod.outlook.com (10.172.65.15) To MWHPR15MB1229.namprd15.prod.outlook.com (10.175.2.147) X-MS-Office365-Filtering-Correlation-Id: c193e46b-b06a-4f45-7c43-08d3eef77c52 X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;2:vGFAWB5hkTcDY3ELAMkuPdBOmvUYrbEDB982bbLiI/8VZxhiGFNDcyh2wfFWg/zKTXQBnhGoquqMt6yUbWtn4kQLcQqy0P+pRVOxQnpSnt2kGSLCMWM1tlJyGCM//pik6an2II84eTEZcBxOkHDzQziK7qx8DId0IehZGb+SNcjz5nHR6QAn3tVpd0kp2ZHgM7Bewnc3QWWwAsKyZscBxw==;3:mfIjc9H0CrvZ4DPGvAmvizyee3okPbdQJXfYHvMK9Cnk0UPHq+pjRDTGaDubj20b5a0msjdxxOVvMauQ8yB4/vaGgQoAAy52la42CrknSLXP833DSk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mXLGwmbVxk4QKYM7XhvjAQPW0QRyd3O+Ia4Og8B1TaJMMrstH1CqavCdUwoS2s45o20hqbBLi+IYlBFVabA7a6sgBElWLitcldn+beGMpnanjYur5IZ4osK4SIUFy9DpuwCgPAlDM0/c=;20:d7YCiHcDqMVP0Snoj/FLfQBdNsqWPMP4vqaKG9NgBURLE1Xqz3rfSs6W/CA/NqZD80pWe8/vxB2cl0vnX3QNkkCQLLden85lDpzr8MyBmOonfD/OSv50TwiMiZw/ICfQeKmvFuZvG/TV+CpyQzYLHnzbIf712lNlSJLmdqFta1A=;4:CQHRumSJmS1+S0s9OQkUGaul0tOBA07LTx1w1oOhfR5HwShjJ3Igkg06OYqPgHA70zRv2rWyITl432Jvse2ASaw6N2YutvOqqMs8JxlwYO9fDIMxTuphwjyYUVnk/bshDhOR8ySFUXLXZ/n+n9JDXYWvrSly6GA+LLOXwkT49flXDnrC6NHtNV8geXgycdxDj9okyIjkpaIc6egQTmqnW8H0CcUHYbEfK7b6JkgSOUuvvB1+UpAUna0I1F7yNDw+GQ7jCFSnbViUsnzM8zqCoOTazqM6Q9FnzwvUJJ407OIHjfliuyISjbiasF+nN5zMnfNxeMFK1kezpOP+JXhr6d0IpzJZmS0KytBi3FeMsGRPeW/+OXC14+9MB9HWwEQRrKNZtCiJfbOdLxcoq8TyMQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046);SRVR:MWHPR15MB1229;BCL:0;PCL:0;RULEID:;SRVR:MWHPR15MB1229; X-Forefront-PRVS: 0088C92887 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(24454002)(189002)(199003)(105586002)(68736007)(92566002)(106356001)(2950100002)(86362001)(6916009)(6666003)(83506001)(5660300001)(19580395003)(110136003)(9686002)(7736002)(305945005)(81156014)(586003)(101416001)(1076002)(7846002)(50986999)(97736004)(54356999)(81166006)(6116002)(2906002)(23676002)(76176999)(4326007)(4001350100001)(50466002)(33716001)(189998001)(47776003)(77096005)(42186005)(33656002)(8676002)(18370500001)(3826002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR15MB1229;H:calvinowens-mba;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjE1TUIxMjI5OzIzOnhZaEZZbU9ydlRMeUt3WVBvNEYvNGxHRWVt?= =?utf-8?B?K3lQZ2c3V3cwNmxWNEUrcnZja2s2YkY3UzgrSHg0WTl3U08rM09yMHlWS1cz?= =?utf-8?B?UjltZnEzOVJ5U2lzUTQwWC9XN3pHbXVYYmVpd0ErYi8vSytrZGlmeUVRMFBk?= =?utf-8?B?NUJTcmE0R0ZqbEFSNjNoUHZ6UkJoRGZPMzhFVWRzZWt1Z2dIRjZia2w3MlI4?= =?utf-8?B?eERPUk80bDVvRGVuV2tzeWhSaDZjN3hPRzZZbG9iVmwyMHNWWUZGUlZVNVBM?= =?utf-8?B?OC9ybkVCVzFjdEVJQzJKUFlYK2ZPSDBhdnA5UlViTGRtdGhzZ2lRQkpPY2dI?= =?utf-8?B?VE9TL0xGMTFYSExRcWo4TGxsWVRGYTZWTUQ1VHd1WTJrZXV5ZTdNNSs5UXd0?= =?utf-8?B?TlUxY3locThpVGF1QTZJNjV6alhqaUZJZVdjYVZjbVQ4S00zTmw5RHo2c1pv?= =?utf-8?B?SEJPeDNXUkZWcU5neTRZS3VTUjZOOThoZkhTL1MyRzVnWS9XSytSUVhKUVhO?= =?utf-8?B?R3V3MGVSLzN6d0JVS0JIWHk4SUlVOUJRajRXbHl0K2hhWXFUdlZzZXJRUys1?= =?utf-8?B?WlBZakpRaHVhOEJCbE1RaWFUZjB6UTlRaldUS0ZuaUV3SWNOQTB6dllkWmxP?= =?utf-8?B?dHU2K3B0MCttbkVwclhSd0VML2ovU25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PR15MB1229;6:Z6F9z81DU0QO3yweNwMZcNnCjZSubjMGA/K7VL6+WO+QUfBkgTiNsa5x77qDvRTTVFdUFUP7hkRrG6+qGPwXMJQfG2CvbMCTFY7lbvoY4E70RBHcekLMiZVixZMXoUjSK73PQACMFH409eNb5BgxlMUngq9plWHiRCcw+gGcj6weCRklWQQC3zpfikI/ACqjCHSASHVu9D51SjOLx9QlZbZHtTA35RsKc4/Z+GFPjJoah4tDQayAgVnPcQQPKy5e62wZWQLmsluF3vsDjGUaFlLzbX0uSdPfTOhEE+pa0oP27TB9uGOjIIX0tQwX32q2;5:LGY1ieDk7gaid9f+Lm4gbjo4Ibsq0WUz1f8EwBcTFlQtx+GhLr/0vF+I/nVFQ9XUOr3mPsG78jkemtTgFdoP8F9M3uJmAe/fW3s1L8MukaO9oyejYlMx2ATWJzl8wbjF9MSaVRNAx42cEo866peLEr78gKkisX7PibZ0WPV/dK4=;24:OK2yOVQwZp2OSa43u6V2w0F+gthqPt0gT2iCGod+iU7ToVZMVXInhI5QGkGGpwIkGV2elh3wB/NudbS8hi9Q7dPTAWGUnii2xHfbca7jaMQ=;7:11eA3eS8I3mQpxqJUL9JkAtvrZiyti2OxqOF1pQVp9RitQBYZvF11Y4PhnLCqhi68iGiR7kqlpCUkzBFxEzBZWCYwy1ducGE+ICXGBkvd/RE7bJMpWtnAryshs23WAx72z1IQswigUphklRHbufSzWjDqwAy0aWoyszRctEtsQmMGXwk0wPgfR0RvprAi4alv3ziTeoB0DCGjyx/rJ4xN5BveMtGbdbyKpASOW+OO5F4flxX71/8g8edOikDvQn8daZ5TbsoeorvAOvMxHkfARmoi/09b8wQUDck2eDSeHiZTo3wwiZXiwZW79T5OSYVWmuG5rdTTA+0QKlxIy+t4g== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;20:MB913bRdx9bQr9KseZtVHCtILThcLEPIQhs0tgTkhVCqf9tf9WqAWA8wtuIOWGhxjDqflgRwO0kmml9L1GVRxxwkVUQJxBkM+1qFJxIsz6artGHCHuQyhtR8VnVbuvG2gbsake5G+8IG+IeLaXSDggn5VyiQhG9hb5IcFaeLp74= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2016 21:18:29.0497 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1229 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-07_09:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2049 Lines: 41 On Friday 10/07 at 21:48 +0100, Al Viro wrote: > On Fri, Oct 07, 2016 at 01:35:52PM -0700, Calvin Owens wrote: > > Omitting the owner field in file_operations declared in modules is an > > easy mistake to make, and can result in crashes when the module is > > unloaded while userspace is poking the file. > > > > This patch modifies fops_get() to WARN when it encounters a NULL owner, > > since in this case it cannot take a reference on the containing module. > > NAK. This is complete crap - we do *NOT* need ->owner on a lot of > file_operations. This isn't a theoretical issue: I have a proprietary module that makes this mistake and crashes when poking a chrdev it exposes in userspace races with unloading the module. Of course, the bug is in this silly module. I'm not arguing that it isn't. I was hesitant to even mention this because I know waving at something in an OOT module is a poor argument for changing anything in the proper kernel. But what I'm trying to do here is prevent people from making that mistake in the future by yelling at them when they do. The implicit ignoring of a NULL owner in try_module_get() in fops_get() is not necessarily obvious. > * we do not need that on file_operations of a regular file or > directory on a normal filesystem, since that filesystem is not going > away until the file has been closed - ->f_path.mnt is holding a reference > to vfsmount, which is holding a reference to superblock, which is holding > a reference to file_system_type, which is holding a reference to _its_ > ->owner. > * we do not need that on anything on procfs - module removal is > legal while a procfs file is opened; its cleanup will be blocked for the > duration of ->read(), ->write(), etc. calls. I see why this is true, and it's something I considered. But when there is zero cost to being explicit and setting ->owner, why not do it? > If anything, we would be better off with modifications that would get > rid of ->owner on file_operations. It's not trivial to do, but it might > be not impossible.