From patchwork Thu Sep 15 15:04:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12977560 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 94D44ECAAA1 for ; Thu, 15 Sep 2022 15:06:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27EF38D0010; Thu, 15 Sep 2022 11:06:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E0348D0001; Thu, 15 Sep 2022 11:06:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 032E98D0010; Thu, 15 Sep 2022 11:06:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E79ED8D0001 for ; Thu, 15 Sep 2022 11:06:34 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C67E0120409 for ; Thu, 15 Sep 2022 15:06:34 +0000 (UTC) X-FDA: 79914646308.28.2C2D2FB Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf20.hostedemail.com (Postfix) with ESMTP id 63A1B1C00CA for ; Thu, 15 Sep 2022 15:06:34 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id m13-20020a056402510d00b004519332f0b1so9678542edd.7 for ; Thu, 15 Sep 2022 08:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=RV5QTvMygwcM31S/hyrs6MnTkve28DlweGTrQchhxXo=; b=iXaNCvcxi4+6qBN7tuBlJCkmsRSEsjGSfB3SfZeymm0XXHHMDLmZS5purDypcnvs9C VSctdYvWkvSVdi7VcQVA/jXEY/asOBe0sjr7IHcePpfoj8cjbpyxzwMKoub6Mbfbj/u3 hdcX9KTPHnInN6LBhE2giGnIHgk4ArxBm8oNZQjrxTqj6l10QwAzi4OrPQG/dmLjnKeM uG5cIFQDMadCU8TrBcbzjSQl+YJOZv/uTPg3+I9KzZbdQlENHqwWW95ACZVZT9BbHfi5 bSJ9Yx8C2yAe2rvI5sDbQK6kyk//DTTYryP9Ky1nwr9gD2c+Xh/G4lERiS/g/gDCekau srrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=RV5QTvMygwcM31S/hyrs6MnTkve28DlweGTrQchhxXo=; b=Cg8ITyFdvvpvE3wJ9JSy9hJelDoCfI8JOcdtDaoqjG8UWOzzPuQqwoyyDbM1mNuUjJ g9fktOiPqAvIat28CNEg+m1AzUOcF5Jv/N7A9PFOQJ31iVlfHX+bCv79EgH8teU/Qeqv pS9FSvJ813P1ZWDCRJ7LWKECll1gMy8e5SQmIs8OFgc11uBU9CEk7ycC/jHTQHFf280D fGkHuVAz6U/UuH2FqpyKXYD7sMcWAWPmaUdjR10wyAPAlFda+mjXWkRxFM7uw13/RBx4 vesQlfhb12qiroQMFwU4bZVHL7X3Ch7lKe4AJ8kH2Wfr8uxEFDgJm7YtuydOIzYmqZ1f Calw== X-Gm-Message-State: ACrzQf1fSzCJexbGUL5qPA9xsVHBXtE8DGQV/iN5TWB1hLcB3SQfF4/B HRW/1ZCxKAe82z2G2HoLRM/UEedjD3I= X-Google-Smtp-Source: AMsMyM7bqtOZHqD5TLNiPJxrMbK30CsOC2CMkBTDAk4Y4jRe7EslTuJmgx6bYvgk5Yw3mmLO7YowFoN6c2M= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:686d:27b5:495:85b7]) (user=glider job=sendgmr) by 2002:a05:6402:4306:b0:451:8034:bcb6 with SMTP id m6-20020a056402430600b004518034bcb6mr291044edc.198.1663254393224; Thu, 15 Sep 2022 08:06:33 -0700 (PDT) Date: Thu, 15 Sep 2022 17:04:16 +0200 In-Reply-To: <20220915150417.722975-1-glider@google.com> Mime-Version: 1.0 References: <20220915150417.722975-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915150417.722975-43-glider@google.com> Subject: [PATCH v7 42/43] 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 Biggers , 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 , Stephen Rothwell , 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663254394; h=from:from: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=RV5QTvMygwcM31S/hyrs6MnTkve28DlweGTrQchhxXo=; b=3ke9Kv31zWcQiUMKtfqHbKbEBMxesPUDfALNk+A7uU3RwOLhhs8W/gyacgZ8Bu4kvtv5pc 2DmJip1gAbWW4ssd44A8OMzA0oK4yKJIQjnrJPnJkLfyjza0pn4ermToV3cf9ifAqnN1vH WxQlAHE374Mnzv4NnXgZpzVUBq66exc= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=iXaNCvcx; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3eT8jYwYKCKQKPMHIVKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3eT8jYwYKCKQKPMHIVKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663254394; a=rsa-sha256; cv=none; b=6YyQRsxGOE6tVaNAT51kHCOwjuEXzBVYJlIg2ZnTE2dbq5TM91P+0n+KFECozv+iTkcUsG MSwtbPUofd9Q2nu95p5HdW7iNaXDurQSIPrqBY82KPI3m4Yc88mHcLPirkb5Peymm6pJOV 4+xCjb8/VIgty9owjHSco0hTT1SECwU= Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=iXaNCvcx; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3eT8jYwYKCKQKPMHIVKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3eT8jYwYKCKQKPMHIVKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--glider.bounces.google.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 63A1B1C00CA X-Stat-Signature: 1haqdsi8cbuxfyd69rk7tino15y4aqax X-HE-Tag: 1663254394-447067 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: 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/Ie300c21bbe9dea69a730745bd3c6d2720953bf41 --- 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 55e762a58eb65..e1198f4b28c8f 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2352,7 +2352,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); @@ -2378,7 +2378,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 53b4bc094db23..076ae96ca0b14 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -5088,7 +5088,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 15800334147b3..ada25b9f45ad1 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3712,7 +3712,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,