Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753022AbcJGVlR (ORCPT ); Fri, 7 Oct 2016 17:41:17 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:46116 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750745AbcJGVlI (ORCPT ); Fri, 7 Oct 2016 17:41:08 -0400 Date: Fri, 7 Oct 2016 17:39:37 -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: <20161007213937.GA84465@calvinowens-mba> References: <48414ef29337b54e2a842bd841f73f01ab74ebe7.1475872278.git.calvinowens@fb.com> <20161007204836.GR19539@ZenIV.linux.org.uk> <20161007211818.GA84073@calvinowens-mba> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20161007211818.GA84073@calvinowens-mba> User-Agent: Mutt/1.6.1 (2016-04-27) X-Originating-IP: [2620:10d:c091:200::3:f884] X-ClientProxiedBy: BN6PR20CA0005.namprd20.prod.outlook.com (10.173.158.143) To BN6PR15MB1220.namprd15.prod.outlook.com (10.172.205.150) X-MS-Office365-Filtering-Correlation-Id: 23dd4e80-759b-4df8-d06a-08d3eefa7649 X-Microsoft-Exchange-Diagnostics: 1;BN6PR15MB1220;2:2fxAKuqXas7zP4Oh9h4KQmVC8Uc4+5KkTy+AO/VMv3Lwb904dUoYdbVxNmTPrZ/tJXG3ryFIISjvcNviEkwW8T4+okVbAFgBup/3PeB6ITAg1br6NPrSakzmO9Q9XrWBPxO13B3hYDs09ttrbB0DE1BeWBr3nCsgN+Wvog5wtUNbIRlQ6OkkXi2Jy6j0kR5O;3:nc7TOQQn6QOA0lyo51ad8r68ZRnFefqik+kNEI/Vr+gxiKN5AcjeXegwJ4ivRK1vAV+c4c9ooQLOd+TMOI6B2su4YAF5xROfhH2n61bqxlW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0yq8Hg= X-Microsoft-Exchange-Diagnostics: 1;BN6PR15MB1220;20:0nVeTBLlCV2RmKe+xHKlxRxCKr1qMJ6RF3l+Iy9i2pg7UwsInzWETXUO4CqccINYfLSKiyPvw9MR9OFVP9HQmk9yw8qLSem/Q1N5Ta6WPgGO/MC/eqNBrlqoDGmmfCIVmGIflRmJcZfVO/OepUY+au9P8QWAWG3qiLEN6iURd3o=;4:Z9aQjLMlxr1POSCKEQx1l0eYmQsaDDzTsnIEj3PebyfikbNOqkO5FJ7Bm8ONrbG0HiFftqzFa1hxfa7ULW44tut+UXI7B7GEeja56U2rZeKDx1WQtmoOXF/YQimQ29sLBhPgHntuAQDxuC4FwlYfyFyh3oEVlN09l51hxQiZCR4sQKpYJV7bRBYXm+jzVJSo3uU7pzLCpJSlDVdH00L+rBuJOEQu1Lb3nPxtv6q4lCX+JdrdZ0VlT8/D/jIhYgetRx5YBznPbKXsD0CNIDZN2PGGo8uliTO9vhpHQkQVZEMj7TDG5iH7hFzfXC8sdgWGheCSGFrCJy8FXw7RCuRaKVVn/BDq4v7qjzItZSLY19NijAGjMd5pdaGUvA16+SrdHYcoe54lCS99oCWhfhmS4Q== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001);SRVR:BN6PR15MB1220;BCL:0;PCL:0;RULEID:;SRVR:BN6PR15MB1220; X-Forefront-PRVS: 0088C92887 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(24454002)(189002)(97736004)(106356001)(2906002)(83506001)(7846002)(47776003)(54356999)(105586002)(42186005)(92566002)(4001350100001)(1076002)(19580395003)(110136003)(33656002)(77096005)(68736007)(7736002)(4326007)(86362001)(6916009)(50466002)(586003)(6116002)(2950100002)(81156014)(76176999)(9686002)(8676002)(101416001)(81166006)(33716001)(189998001)(23676002)(5660300001)(6666003)(305945005)(50986999)(18370500001)(3826002);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR15MB1220;H:calvinowens-mba;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjE1TUIxMjIwOzIzOmFqUHZySVdxdTBqU0M2ZGY2R3dOK0x6OXhN?= =?utf-8?B?N1BSbytIQmVLUWNON2x0WXh0UnlzZ0JEeTRjUFo4MVlBaHlEdkRCamlwbGRr?= =?utf-8?B?d2kwK1h1TkdxYjZrTkV6QUVXbFZBcUpuQUpPK2xVVmpRMzA0S1RtdGc1Z09D?= =?utf-8?B?VzlHN0pXRzlQdFpuSWE5WDZMcE1TOE1oUTdGNzBtdHNESG1NNjE1ditsSkxp?= =?utf-8?B?QWlPYlI3L3piSU14WEJYU3dQbDR2bm01NGR2UlBhK20ybDlDYk1ib3FPOW8x?= =?utf-8?B?MG5yeDNCTVlHTzBsSTdaZ3BoWUE4a05oeWtOQ1B0T0YrUmJhbmtXaGdGdFVE?= =?utf-8?B?cEN3dzZRZmR6OW55cVBpY2pZWVlLYUx3cjVmM1F0MHdBRk5pLzhhWm42UVFu?= =?utf-8?B?SmkwdC9zYUs5NnA1L1V0eHpvSDZRUmM2eVJtZ1RTckJyNUdURlg0M2JoTGV6?= =?utf-8?B?TU9MWS9aeWZnZ2cwUm9tT3JzVGlTVzg1d3RvWDkwc2RZZXl0YTEwQUhFaFF6?= =?utf-8?B?ejU5VnU5cXhQeUJSM1d4bkJLMTdZai90WGNSK3BHNjFGL0ZHZTJueUh5a0RT?= =?utf-8?B?amp2bHZYWlh6RGs2ZlB1eUJ4eDhYaEc0YnJoWWwxQVBUOTFvZmU0SkowaXhk?= =?utf-8?B?eEJqenVWV3c1ejRqMWlNNk84c3R2Y0crRUg0cWp5U3hmWFNRam9DVHJ3YTh2?= =?utf-8?B?S1VrN3lWV1lXcjk4MndueUtKblcwc0s1dTlJa3J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c25/BE4u1GmrAAWwri9lYBv+cXsDS8e9THAhaeutch621jkBbf3TIfqHLPgox6tiv6dml11pOBN46lZE8fzXKgotzbBcTYBcUdA622Y30YZ0YaMIEPV/8+P3DmsxiQb92+XmGH05xuIffOZ8HnX1b8hROC61aEHavpTIBnQvQ95wSsA5H+10Fp2PYKdyhSrHJRjqYO/gjwig/f+xc0=;5:NaV/xyCQB2lEUOWCJIulf+X3XtYFCZ6su+oMd2xRuOHENuH/RDBpd80jDmhZZnqnioLrhF1ujnHWf+0aQcLGnM7RciRH0figjRjpJguXNbwqEw8ELcgCH7iixzZBQMeOM1y3f8csx+DQI3MvAwVbAg==;24:otDC02HQVKIuNOvpMCZ3i2OfMLVpDaLXYCZx4Q/byXy5Ip3fdO22Tjo3nuIXXKAjkHKaOh/TuJdHJQ0OaNjzTCzSv2MhobqbPM8CICTfO3U=;7:PfFa7nggjjQmDBsOuCmPVLWNPCx+hPES8KGDN0vNN+y1JjWy7QVnTSpp4LVZ6nz8N7IgayNXbBpkKqyaEW17G/O79BnYIVz32M7s2hpthYLgenH7/EqcnIDsqbibannuBZIVhGaskJ1/HfbcnxidbmB9TFjITeGLOFXHR8T4513iWeQLISv1ikWcyV+OCFSnxiByk21MtMyB6r4ng4rFiQMRNUT5JtXRc1dc+KRPnnt27qtNH3ezMGOfn+qv35Mi5STiqEkJcxRXcpm9peNHMtckcIp2MEqJNg8MsiJtSsjedQayVZNkxq5s3T+0zb1k SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR15MB1220;20:PhVqRncf2bbQOzNkjqtAR3cjhXhx+ni+Uv86tsiVRegIyi9pgMQkoeFYO5CBKNh9tVWXTMsqmsKvDFDaEjVNvgnPKmWhkHj2DZpNIK8Y6XjYJTBah+Z3IAmsmgoVn/qzvMY3rwF9U7D3yRsRnDz40wf+2hsv5nx6dKnfoRKvU74= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2016 21:39:47.9492 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR15MB1220 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: 2309 Lines: 50 On Friday 10/07 at 17:18 -0400, Calvin Owens wrote: > 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. Let's drop this, I should never have sent the patch in the first place. > > * 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. I'll look into this, I'm interested. Thanks, Calvin >