linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Potapenko <glider@google.com>
To: glider@google.com
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andrey Konovalov <andreyknvl@google.com>,
	Andy Lutomirski <luto@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Borislav Petkov <bp@alien8.de>, Christoph Hellwig <hch@lst.de>,
	Christoph Lameter <cl@linux.com>,
	David Rientjes <rientjes@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Eric Dumazet <edumazet@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Ilya Leoshkevich <iii@linux.ibm.com>,
	Ingo Molnar <mingo@redhat.com>, Jens Axboe <axboe@kernel.dk>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Kees Cook <keescook@chromium.org>, Marco Elver <elver@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Matthew Wilcox <willy@infradead.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Pekka Enberg <penberg@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Petr Mladek <pmladek@suse.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Vegard Nossum <vegard.nossum@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	kasan-dev@googlegroups.com, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v6 43/44] mm: fs: initialize fsdata passed to write_begin/write_end interface
Date: Mon,  5 Sep 2022 14:24:51 +0200	[thread overview]
Message-ID: <20220905122452.2258262-44-glider@google.com> (raw)
In-Reply-To: <20220905122452.2258262-1-glider@google.com>

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 <glider@google.com>
---
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,
-- 
2.37.2.789.g6183377224-goog


  parent reply	other threads:[~2022-09-05 12:34 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 12:24 [PATCH v6 00/44] Add KernelMemorySanitizer infrastructure Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 01/44] x86: add missing include to sparsemem.h Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 02/44] stackdepot: reserve 5 extra bits in depot_stack_handle_t Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 03/44] instrumented.h: allow instrumenting both sides of copy_from_user() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 04/44] x86: asm: instrument usercopy in get_user() and put_user() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 05/44] asm-generic: instrument usercopy in cacheflush.h Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 06/44] kmsan: add ReST documentation Alexander Potapenko
2022-09-06  3:10   ` [PATCH v6 6/44] " Bagas Sanjaya
2022-11-07 14:24     ` Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 07/44] kmsan: introduce __no_sanitize_memory and __no_kmsan_checks Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 08/44] kmsan: mark noinstr as __no_sanitize_memory Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 09/44] x86: kmsan: pgtable: reduce vmalloc space Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 10/44] libnvdimm/pfn_dev: increase MAX_STRUCT_PAGE_SIZE Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 11/44] kmsan: add KMSAN runtime core Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 12/44] kmsan: disable instrumentation of unsupported common kernel code Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 13/44] MAINTAINERS: add entry for KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 14/44] mm: kmsan: maintain KMSAN metadata for page operations Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 15/44] mm: kmsan: call KMSAN hooks from SLUB code Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 16/44] kmsan: handle task creation and exiting Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 17/44] init: kmsan: call KMSAN initialization routines Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 18/44] instrumented.h: add KMSAN support Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 19/44] kmsan: unpoison @tlb in arch_tlb_gather_mmu() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 20/44] kmsan: add iomap support Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 21/44] Input: libps2: mark data received in __ps2_command() as initialized Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 22/44] dma: kmsan: unpoison DMA mappings Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 23/44] virtio: kmsan: check/unpoison scatterlist in vring_map_one_sg() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 24/44] kmsan: handle memory sent to/from USB Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 25/44] kmsan: add tests for KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 26/44] kmsan: disable strscpy() optimization under KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 27/44] crypto: kmsan: disable accelerated configs " Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 28/44] kmsan: disable physical page merging in biovec Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 29/44] block: kmsan: skip bio block merging logic for KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 30/44] kcov: kmsan: unpoison area->list in kcov_remote_area_put() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 31/44] security: kmsan: fix interoperability with auto-initialization Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 32/44] objtool: kmsan: list KMSAN API functions as uaccess-safe Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 33/44] x86: kmsan: disable instrumentation of unsupported code Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 34/44] x86: kmsan: skip shadow checks in __switch_to() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 35/44] x86: kmsan: handle open-coded assembly in lib/iomem.c Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 36/44] x86: kmsan: use __msan_ string functions where possible Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 37/44] x86: kmsan: sync metadata pages on page fault Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 38/44] x86: kasan: kmsan: support CONFIG_GENERIC_CSUM on x86, enable it for KASAN/KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 39/44] x86: fs: kmsan: disable CONFIG_DCACHE_WORD_ACCESS Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 40/44] x86: kmsan: don't instrument stack walking functions Alexander Potapenko
2022-09-09  8:57   ` Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 41/44] entry: kmsan: introduce kmsan_unpoison_entry_regs() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 42/44] bpf: kmsan: initialize BPF registers with zeroes Alexander Potapenko
2022-09-05 12:24 ` Alexander Potapenko [this message]
2022-09-05 12:24 ` [PATCH v6 44/44] x86: kmsan: enable KMSAN builds for x86 Alexander Potapenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220905122452.2258262-44-glider@google.com \
    --to=glider@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@google.com \
    --cc=arnd@arndb.de \
    --cc=ast@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=cl@linux.com \
    --cc=dvyukov@google.com \
    --cc=edumazet@google.com \
    --cc=elver@google.com \
    --cc=gor@linux.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=iii@linux.ibm.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=mst@redhat.com \
    --cc=penberg@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    --cc=vegard.nossum@oracle.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).