Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp1335867imi; Fri, 1 Jul 2022 07:44:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t6HIBhjUk807d/nahCkNXlYN0ApQ5JLxaowivVVmaUqPVu9EiK72TpiSLtlzGlYVTobIbw X-Received: by 2002:a63:4d26:0:b0:411:83dd:2c3 with SMTP id a38-20020a634d26000000b0041183dd02c3mr11388707pgb.508.1656686693939; Fri, 01 Jul 2022 07:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656686693; cv=none; d=google.com; s=arc-20160816; b=r8hRwZdLX6vvRtWjp8Mo1f/ELrIx9toLLGhlV+vo9QhDO3B/1sl+DjPQToTJeC+eDa 8N63vL3n1klhKPDWlDrhsEYKlD9Fp2unMmtWk9nQCWUYDTOfTuYaPrfuAoQWrmVhFSoE TeUetnEIejHPEkryUWONyVcPg6/JZ192kG3KF7JyljTycLGg6+WYih8Ue59vhAkfTtnL G1KwReRIeNygciWeA6PiE5QNJ8SSxEWe9db2bpcjcN7V+LNkAYe45b/5gShLkE3cokUR /f57Q4uAxxs+ndGqElxOrmzezcKxyYvoIoiDlmTuTtHRroL6ihOq31ZrVrgcgkrnGBVM zPcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=iGvD4mfjvjSWX+nv6535woTSPAyHTTcU/sEMimyHpxI=; b=JUEH33nSgv20BbQon7ImkpZ8IvDNyKruvoFPTKhGSB7D51f2lh5RZSxQxrKSZuUli4 ipaPxZ9UMnCWRruQxwkqGYFTAAeglH9kYjX9dGFOCoFkPIZGuhneh7kHz+mbZ9mVMXPM D3sacenjCgYPh04v28pCo5R9GYw5n5bUP26Zm8oqFN4AhDuGhCMfnLOSO7RfDAJaBWp/ XEdkXHcqZjLAwBUoh2qRmClFta2nxtdOcpYfbWf5X7tqp02w5wJR1tqXmaObqo2HIIJ6 VEHus+v9ErGSva9GekuJB5b89hK56YoZQNcH03wdOz5UHEw+amNeOTkIt9hu1kqijDZ2 jT0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=P7QKDp3h; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw19-20020a170903045300b0016a138d6a14si23795229plb.261.2022.07.01.07.44.42; Fri, 01 Jul 2022 07:44:53 -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=@google.com header.s=20210112 header.b=P7QKDp3h; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233247AbiGAOal (ORCPT + 99 others); Fri, 1 Jul 2022 10:30:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232994AbiGAO30 (ORCPT ); Fri, 1 Jul 2022 10:29:26 -0400 Received: from mail-lj1-x24a.google.com (mail-lj1-x24a.google.com [IPv6:2a00:1450:4864:20::24a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F2056D563 for ; Fri, 1 Jul 2022 07:25:24 -0700 (PDT) Received: by mail-lj1-x24a.google.com with SMTP id p7-20020a2e9a87000000b0025a99d8c2dcso502649lji.18 for ; Fri, 01 Jul 2022 07:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=iGvD4mfjvjSWX+nv6535woTSPAyHTTcU/sEMimyHpxI=; b=P7QKDp3hV6WoKSuU7RWtHYNnUzKsYPMuoVFYGC5CAEPmJ0nl1tQiRY+9OYfXLY42wB nFSOJB8BBflVDmdDuWSkOCm55g6bwX9dQkpXj4xCR6s6JCEls/jHSMNPkv+lVDZh5nKs hUARMca5KeTe+Ir0fpc6ZOi4Uq5KQZl/WLZTZOatCEOeYcao1NRgQlKKrm6iBVPu3X1Z JYhJ2HBgIVmRPYmPgcVuYdtvK/4rJXCJLuWe7FZ63qgHZC3DxwnGi+wOpBYOkbuzJh/f yrpShYElychLxpVWGpPbFszkIP0ovqs29G1ENpHftNUWpa2XkYBhGLzu4Zi+nYeVFrno cQCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=iGvD4mfjvjSWX+nv6535woTSPAyHTTcU/sEMimyHpxI=; b=zAVXVamtRr+4E2pPkxwAjaGswMr6Mag2vJ7cWkGWV3O/EjnndbocpduJftbNPLrHqE 3/G9n0X4449ksxp153PbVuTvnN9uQhP/+g1yinDClmCIuWEUw4S4sP4EZVjM34vNgb4s DXesznXgznSfkBpf+TNR0fq7u9Pm6Qs/BwiWqJHtiQATSMTbuaVHdPQSOOVNBUtx1tCE wO6Rm+37tvEju3RtLp7CFnSKGrDwwdsuXxfUaV3EkPvoHvJobn1qv0y3kdHE5imjcj7D jD/8YORxEaUX29QtK5r341FxfJY08I90KvhGfSD0z2hNv+JAi6gT0nrft9XHt40FxaBR 1vRg== X-Gm-Message-State: AJIora++NRCQkPfSCrJoI2A5w6AmddtxL7p1TMzdENPDheCSZF+k8s0H cuMbfj2FpK6MoQiw97sckmlKx8uuz34= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:a6f5:f713:759c:abb6]) (user=glider job=sendgmr) by 2002:a05:6512:4c3:b0:47f:6f6e:a7e7 with SMTP id w3-20020a05651204c300b0047f6f6ea7e7mr9859006lfq.674.1656685518270; Fri, 01 Jul 2022 07:25:18 -0700 (PDT) Date: Fri, 1 Jul 2022 16:23:09 +0200 In-Reply-To: <20220701142310.2188015-1-glider@google.com> Message-Id: <20220701142310.2188015-45-glider@google.com> Mime-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 44/45] mm: fs: initialize fsdata passed to write_begin/write_end interface From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , 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 , Matthew Wilcox , "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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 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. Fix this by initializing fsdata with NULL before the call to write_begin(), rather than doing so in all possible a_ops implementations. This patch covers only the following cases found by running x86 KMSAN under syzkaller: - generic_perform_write() - cont_expand_zero() and generic_cont_expand_simple() - page_symlink() Other cases of passing uninitialized fsdata may persist in the codebase. Signed-off-by: Alexander Potapenko --- Link: https://linux-review.googlesource.com/id/I414f0ee3a164c9c335d91d82ce4558f6f2841471 --- fs/buffer.c | 4 ++-- fs/namei.c | 2 +- mm/filemap.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 898c7f301b1b9..d014009cff941 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2349,7 +2349,7 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size) struct address_space *mapping = inode->i_mapping; const struct address_space_operations *aops = mapping->a_ops; struct page *page; - void *fsdata; + void *fsdata = NULL; int err; err = inode_newsize_ok(inode, size); @@ -2375,7 +2375,7 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping, const struct address_space_operations *aops = mapping->a_ops; unsigned int blocksize = i_blocksize(inode); struct page *page; - void *fsdata; + void *fsdata = NULL; pgoff_t index, curidx; loff_t curpos; unsigned zerofrom, offset, len; diff --git a/fs/namei.c b/fs/namei.c index 6b39dfd3b41bc..5e3ff9d65f502 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -5051,7 +5051,7 @@ int page_symlink(struct inode *inode, const char *symname, int len) const struct address_space_operations *aops = mapping->a_ops; bool nofs = !mapping_gfp_constraint(mapping, __GFP_FS); struct page *page; - void *fsdata; + void *fsdata = NULL; int err; unsigned int flags; diff --git a/mm/filemap.c b/mm/filemap.c index ffdfbc8b0e3ca..72467f00f1916 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3753,7 +3753,7 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) unsigned long offset; /* Offset into pagecache page */ unsigned long bytes; /* Bytes to write to page */ size_t copied; /* Bytes copied from user */ - void *fsdata; + void *fsdata = NULL; offset = (pos & (PAGE_SIZE - 1)); bytes = min_t(unsigned long, PAGE_SIZE - offset, -- 2.37.0.rc0.161.g10f37bed90-goog