From patchwork Mon Apr 29 22:09:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 10922575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 990EB1395 for ; Mon, 29 Apr 2019 22:09:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A595285BA for ; Mon, 29 Apr 2019 22:09:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EC34287EA; Mon, 29 Apr 2019 22:09:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A19F285BA for ; Mon, 29 Apr 2019 22:09:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E2CF6B0008; Mon, 29 Apr 2019 18:09:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0947B6B000A; Mon, 29 Apr 2019 18:09:54 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EECC46B000C; Mon, 29 Apr 2019 18:09:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id CD4F36B0008 for ; Mon, 29 Apr 2019 18:09:53 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id p26so11591312qtq.21 for ; Mon, 29 Apr 2019 15:09:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=XPoMyuuM4ApL6KB762g1/x7lGygMjp3tNkFYSkeVl1Y=; b=mrjlJOCTMhR4Nk0WsWlU9JhPIfs4fAj7G1q/SGkiP7fN7tsup0a4Dq/aJ6hB5d7zvM rzlyDSweidDx34aoy/X1QaaIUEfLQnWn1v0KkEMnel896IoSccYCuNqFJJ3KxT7rwSiq 2V2SH6GAn6b3BIYWRZwGKdy7YOh1x1OkeWqbRfTD/KftQF5AnyiuScgooLl381jj1AW0 bdEMfLPQBJaJ63pp/5m75Y2DufuWlgiqKUSfm9iRB3o8ls1llKXYaZOtKKAmRwqae+Yb l/AXXSjIrsuRZMJOIEDBuL0HCZovH3fXGoTcQbMtSUnywz66xx0TcJRwXIQhpRfjJ64L tkPA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of agruenba@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=agruenba@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAXFzIRcHH/gwTIy6z8a1t01S13t6fXbszre7B0s1wLLM1i51vzi xA8sT/rzOojRfrOQl1S52rjJrTtlSfvA0c0FhQFlBy1XJC6tIFv4TnTHTgFTvX/d0l8FDsiPkvI MxtgTwPLPYRyIQNPzXJRUt+mUUJtGgxTwBllJaigeu46SZsWjPxy5ODILbGKXDw3OJQ== X-Received: by 2002:a37:6315:: with SMTP id x21mr40254052qkb.265.1556575793621; Mon, 29 Apr 2019 15:09:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJGwcHKSMvSJzQ8NmatdhdlK1HoDNg1QkcJDdIV8xPHWF0xMouZ+YZegcDWr2GYrsxqYpC X-Received: by 2002:a37:6315:: with SMTP id x21mr40254007qkb.265.1556575792965; Mon, 29 Apr 2019 15:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556575792; cv=none; d=google.com; s=arc-20160816; b=iNvrPJyHvapKRp6QzEzlpIC5L3NAPQnXhK2WSFTkzK21zXMD/vAa/xy5T0jlwBHdQq 4OGCSfD9WXWjkhEgHqrMSqNiY9uIn6XmRjeh2hXZT/Ou6XQlaQLrKNuE5ZDGOK87ro6c XZ+/YJ4HzZPSXcXKLUuh8phNvLOeDnWRAf8SrRQ4IiPf1emBd5KoqYQKP4objcY7P7LG 6muQSZAZQgMjy23x/jpr1E2s1q+BXU3MwZLQoY/wCgKreAyTgDPIuY+5dX01uMA7lS+N mi0MOozZlN9EzLlrVhkovHYUuQm5EqNrHSPGHsklPNtlDrc+usMraUUDP5Hjcyag9jRE AngQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=XPoMyuuM4ApL6KB762g1/x7lGygMjp3tNkFYSkeVl1Y=; b=HeyFlnMZqyYNAYr+yn2rTKfe6rZ5vGHNeiTBmKaTc8rvOdMHIxFP9ZeuXT3TRwCXsL oDHuDmjgFKMSxzebXtnOY2nQ+M6wdBxfbDJuCstiXoAwu6jrLVsX37xTqbSQgKvq3R0z nJFapZDVJE88aAnx6HyntXP86MGSj400p0hEkkT1wbKxD0j8qVl4WPtX7OT8v94UEd6I Vj6MrBQ+cXQGWX8gzuTG6RTac0QlSowhrYl4nf7ACCROjhGwn5ndNcoznzIoux8b13TQ uSjhBQWe1qXJXi3srPySlo1jwmFNXNF6NY+oWPTCaSMetwQcKE6xFGHv//7PUGhdQICo ok9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of agruenba@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=agruenba@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id 55si1269525qtt.144.2019.04.29.15.09.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Apr 2019 15:09:52 -0700 (PDT) Received-SPF: pass (google.com: domain of agruenba@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of agruenba@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=agruenba@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E63C308624B; Mon, 29 Apr 2019 22:09:52 +0000 (UTC) Received: from max.home.com (unknown [10.40.205.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7467717CCB; Mon, 29 Apr 2019 22:09:49 +0000 (UTC) From: Andreas Gruenbacher To: cluster-devel@redhat.com, "Darrick J . Wong" Cc: Christoph Hellwig , Bob Peterson , Jan Kara , Dave Chinner , Ross Lagerwall , Mark Syms , =?utf-8?b?RWR3aW4gVMO2csO2aw==?= , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Andreas Gruenbacher Subject: [PATCH v7 3/5] iomap: Fix use-after-free error in page_done callback Date: Tue, 30 Apr 2019 00:09:32 +0200 Message-Id: <20190429220934.10415-4-agruenba@redhat.com> In-Reply-To: <20190429220934.10415-1-agruenba@redhat.com> References: <20190429220934.10415-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 29 Apr 2019 22:09:52 +0000 (UTC) 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: X-Virus-Scanned: ClamAV using ClamSMTP In iomap_write_end, we're not holding a page reference anymore when calling the page_done callback, but the callback needs that reference to access the page. To fix that, move the put_page call in __generic_write_end into the callers of __generic_write_end. Then, in iomap_write_end, put the page after calling the page_done callback. Reported-by: Jan Kara Fixes: 63899c6f8851 ("iomap: add a page_done callback") Signed-off-by: Andreas Gruenbacher Reviewed-by: Jan Kara Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/buffer.c | 2 +- fs/iomap.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/buffer.c b/fs/buffer.c index e0d4c6a5e2d2..0faa41fb4c88 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2104,7 +2104,6 @@ void __generic_write_end(struct inode *inode, loff_t pos, unsigned copied, } unlock_page(page); - put_page(page); if (old_size < pos) pagecache_isize_extended(inode, old_size, pos); @@ -2160,6 +2159,7 @@ int generic_write_end(struct file *file, struct address_space *mapping, { copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); __generic_write_end(mapping->host, pos, copied, page); + put_page(page); return copied; } EXPORT_SYMBOL(generic_write_end); diff --git a/fs/iomap.c b/fs/iomap.c index f8c9722d1a97..62e3461704ce 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -780,6 +780,7 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len, __generic_write_end(inode, pos, ret, page); if (iomap->page_done) iomap->page_done(inode, pos, copied, page, iomap); + put_page(page); if (ret < len) iomap_write_failed(inode, pos, len);