Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp509089imw; Mon, 4 Jul 2022 13:50:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uQaAmmfQc3m+R5ycsE9EITI0XIFTradjJbfokUOMH9ixs7ILv/I44pz2Ew8f/YbYwRyeIB X-Received: by 2002:a17:902:7618:b0:16a:23ec:75f6 with SMTP id k24-20020a170902761800b0016a23ec75f6mr38596219pll.158.1656967805239; Mon, 04 Jul 2022 13:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656967805; cv=none; d=google.com; s=arc-20160816; b=xiq6BEpKPrvtHgJ2LTUVF34dIcem7ka6JqKsT2XPom9D9eQIT6c5XwNhjCnAqdG0c7 yv+8fI069DZ69f/uyx3wH9Cv5qxL/OZFatmfCDaoNoPQ511IEDNvV4sRcTDm0gJL2q9k saZj5yCtSaMue9vMAdzJJYXwDgbYnwcgdPOWbutcnAePQQB1rl6WizgV4nD75B7+B5Qq VyMoYLFaaDChuo/UZCbD2VgvMqV206lETCkzfoF36mSU53YOvPOPUWQiuUr1c2Uzafap CHqKFxeibsARAI6Hv1jvygeg+N7bR1zVI10mCa+mAI204x1eKA6toMMu2V9B5f4/6Sq+ roKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=0ahdG6vwtrla/GfArjvdjqG8Ieo6jXxVEyUk4N9P1DU=; b=VGpuyaCKNcDoBlLvG5X3OpdUMr78TrPQJJhFPOp55NCyd0CMd2eEs8OPBAjloaZ4fO WRubTKjuuKUIAt9xLrGCGoB1oZHNVwF9GZmPaOaufAFK7L4kUqVhfB1lUY5mCav6MDdF V9p/+o9O0M5ExzQImpqXFjJO8kPQzafddE0qQOWr+8mN9gUDgzR+YvDAMmYg+4vlsVm7 iso9d0nBsHDwYKraNX6XljfHzCI1jD0HIrxLCUsgmD8RlGJEHRnuquJS4Y/BeqTGzxce 9t9oBvtpxgCCjNtPVW8yDZGXWbE3STGVre4dNMEznI9NQuk/rexS11eBt+Y9QZsTZmTt zvfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="ne0Uf/6y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k193-20020a636fca000000b0040528e32768si15766676pgc.659.2022.07.04.13.49.52; Mon, 04 Jul 2022 13:50:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="ne0Uf/6y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233028AbiGDUar (ORCPT + 99 others); Mon, 4 Jul 2022 16:30:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiGDUaq (ORCPT ); Mon, 4 Jul 2022 16:30:46 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A09176306; Mon, 4 Jul 2022 13:30:45 -0700 (PDT) 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: Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.