From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 907DCC43334 for ; Mon, 4 Jul 2022 20:30:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C655E6B0071; Mon, 4 Jul 2022 16:30:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C148D6B0073; Mon, 4 Jul 2022 16:30:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADDD36B0074; Mon, 4 Jul 2022 16:30:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9DC576B0071 for ; Mon, 4 Jul 2022 16:30:49 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 70B5B34501 for ; Mon, 4 Jul 2022 20:30:49 +0000 (UTC) X-FDA: 79650561018.06.CDD3710 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) by imf12.hostedemail.com (Postfix) with ESMTP id 9C5B040012 for ; Mon, 4 Jul 2022 20:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0ahdG6vwtrla/GfArjvdjqG8Ieo6jXxVEyUk4N9P1DU=; b=ne0Uf/6y0BOWxJovHIrHEvr2xA xwOaT8SpGI4pQyxrDEsz0MXWEP5fU5BfmjkOS9uiXA2/uYafTL8z3mZG61t3pF8Yp5qDYFUM7dg0S 55ceSjFJBLdMCEPY8wiIS4wC5EWV4pUiB3jRlbbqEtE6dLqHsMTI3kvXXpvDrKj3EFnC7Jy9L9kyl iFqZTArbZn0Ub6BGDXrPH2SDexvyUvZH3gwVyWJGfZABlTfprEuLob7jWWY+L3v2nMp1bCnQ2+KGF G/mLSR88wuG9n29bHZMonvBJFlpsljyW7iZOnelikF61rHzsxzej0HSZFkj1WUecw35IcXl8USJUW /mXzlagg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o8Sho-0088HH-1A; Mon, 04 Jul 2022 20:30:04 +0000 Date: Mon, 4 Jul 2022 21:30:03 +0100 From: Al Viro To: Matthew Wilcox Cc: Alexander Potapenko , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 44/45] mm: fs: initialize fsdata passed to write_begin/write_end interface Message-ID: References: <20220701142310.2188015-1-glider@google.com> <20220701142310.2188015-45-glider@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656966647; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0ahdG6vwtrla/GfArjvdjqG8Ieo6jXxVEyUk4N9P1DU=; b=by2TO3aQQwfEjnqFVdqJDQ59WGN+gKaOAZ8+OV2jx8OW1l+fXygb2dUORVku2tKc3aA+H4 PsdYd4DLmvz9hr80hfVnqHr81Fv8cbk2U/AJFRzUNt58DG13JKH1I/lBPApyvOb+3wmdMo QtPmO8Bp1AT5QscsjJH2l9pTFXj9ffA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.org.uk header.s=zeniv-20220401 header.b="ne0Uf/6y"; dmarc=pass (policy=none) header.from=zeniv.linux.org.uk; spf=none (imf12.hostedemail.com: domain of viro@ftp.linux.org.uk has no SPF policy when checking 62.89.141.173) smtp.mailfrom=viro@ftp.linux.org.uk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656966647; a=rsa-sha256; cv=none; b=004vz6N/F5kTaRxdKD3ZUHsqkQ3YeyZ15RsFkkzRvG5f+mCu2hyasT9J563sWz+9eD45m6 QoUibD8yCRABd3tTEx9EN6Pu9NFdPH6iBW8JxDISNqnv54gUqs+pLq0vWpUksEJzDjLMmP 9IjiipUGTAzf3Q4nJTW8PntiwzymjZI= X-Rspam-User: X-Rspamd-Queue-Id: 9C5B040012 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.org.uk header.s=zeniv-20220401 header.b="ne0Uf/6y"; dmarc=pass (policy=none) header.from=zeniv.linux.org.uk; spf=none (imf12.hostedemail.com: domain of viro@ftp.linux.org.uk has no SPF policy when checking 62.89.141.173) smtp.mailfrom=viro@ftp.linux.org.uk X-Stat-Signature: rmw3n3nopodq98dfgxq4y47e1irokhrx X-Rspamd-Server: rspam08 X-HE-Tag: 1656966645-146872 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jul 04, 2022 at 09:07:43PM +0100, Matthew Wilcox wrote: > On Fri, Jul 01, 2022 at 04:23:09PM +0200, Alexander Potapenko wrote: > > Functions implementing the a_ops->write_end() interface accept the > > `void *fsdata` parameter that is supposed to be initialized by the > > corresponding a_ops->write_begin() (which accepts `void **fsdata`). > > > > However not all a_ops->write_begin() implementations initialize `fsdata` > > unconditionally, so it may get passed uninitialized to a_ops->write_end(), > > resulting in undefined behavior. > > ... wait, passing an uninitialised variable to a function *which doesn't > actually use it* is now UB? What genius came up with that rule? What > purpose does it serve? "The value we are passing might be utter bollocks, but that way it's obfuscated enough to confuse anyone, compiler included". Defensive progamming, don'cha know? I would suggest a different way to obfuscate it, though - pass const void ** and leave it for the callee to decide whether they want to dereferences it. It is still 100% dependent upon the ->write_end() being correctly matched with ->write_begin(), with zero assistance from the compiler, but it does look, er, safer. Or something. Of course, a clean way to handle that would be to have ->write_begin() return a partial application of foo_write_end to whatever it wants for fsdata, to be evaluated where we would currently call ->write_end(). _That_ could be usefully typechecked, but... we don't have usable partial application.