Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3427512imu; Sun, 11 Nov 2018 14:52:03 -0800 (PST) X-Google-Smtp-Source: AJdET5dQt45qib6d0vUceQSCoUyafwoXj0NKLhuxusXQoXCbli4Fu2rEWMVZDCEn1SQot5jQtPdj X-Received: by 2002:a62:670f:: with SMTP id b15-v6mr17783956pfc.243.1541976723292; Sun, 11 Nov 2018 14:52:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541976723; cv=none; d=google.com; s=arc-20160816; b=Dj6bOuy3po8GoJT4b7Yxz0kfDL+bUvgFcNRUu/WoXJ5x+nW6ZPmk7oLx/YCFwAXWmK NWujTuSkTQcOFz5P89svtRyT8cJjGEq01AsGFX/ISPNPTRHBW4qEKSduM6WJGJ9KhfuB wvbX73F6uAU3VGeq6N4d1AcYln4DWZB6w1RktZejRSYmNCw1GmcPYshnPjIR+mo+q7LR UQGp7ZJ7yoegsnKw7+BjSkzmw6jR+AOS0SrmGYMX11OntOB3YtrWpYoPpQyCV5n+YW4j xYxa98PpNrmud61Jde0J5JVDgDKH2Fz88nEGE2UDBWXKDKt0ickDcQvbgoTR37JRLPu1 zMwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=psei2jXJPpf9+3ddjdVIkbc9osflbduWzt4rgOknuAg=; b=Cfet6PjAlI14a0at1kIi10ioAU8UsNJh1fF76CpZEOhB741etAau3HPekFnVj5LQIM qL1x7mZnsoQTUgxaCA+mEtKIQQF3UAZxqD13W1ZNbC5GkOnIWRNJg5W3JdUrV8qsjBpo bN2u+0Pang2Wjq4MoiQ0cFXhZ277EBl+6bltoOxACwYW9cOm6j6W0+OORr6PK1F8DO2t i3irEnoqXbTyFiq61Ok1+CnCdw8uv9McEGOX0tyL9N8nF9eF6vPqn2WwRbpk62o3GkY3 wOyspVOe/pOquDwS9P+END89+TdWaNkqiIwCpcHykNB71e+/Tg8VQC3pbV9w/RjyiYUn MJJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UQwxxmrW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 131-v6si16223125pfx.213.2018.11.11.14.51.48; Sun, 11 Nov 2018 14:52:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UQwxxmrW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390997AbeKLIkU (ORCPT + 99 others); Mon, 12 Nov 2018 03:40:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:54672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404246AbeKLIXL (ORCPT ); Mon, 12 Nov 2018 03:23:11 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E78902245E; Sun, 11 Nov 2018 22:33:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975594; bh=eTXCHD2S5FF4WkCPS8H5+n9UD7YSfgaI1NoOlx8et9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UQwxxmrWSyNut6W26DVNPz1NobUc8cNRZLJvPUio9+0jaDQ7UECSTo6J+nYzXEaZy KnPcMvQD914f94ISb9maTbK1W48euHRzPYiTSgKVTNNUWw/sl0wtSVqb1ols2AJ1rw j9Lg0sRW6QUSud+Os0EjBkn8H4iWYy2OPRvwklGQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Bo , Filipe Manana , David Sterba Subject: [PATCH 4.14 211/222] Btrfs: fix null pointer dereference on compressed write path error Date: Sun, 11 Nov 2018 14:25:08 -0800 Message-Id: <20181111221705.407853567@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana commit 3527a018c00e5dbada2f9d7ed5576437b6dd5cfb upstream. At inode.c:compress_file_range(), under the "free_pages_out" label, we can end up dereferencing the "pages" pointer when it has a NULL value. This case happens when "start" has a value of 0 and we fail to allocate memory for the "pages" pointer. When that happens we jump to the "cont" label and then enter the "if (start == 0)" branch where we immediately call the cow_file_range_inline() function. If that function returns 0 (success creating an inline extent) or an error (like -ENOMEM for example) we jump to the "free_pages_out" label and then access "pages[i]" leading to a NULL pointer dereference, since "nr_pages" has a value greater than zero at that point. Fix this by setting "nr_pages" to 0 when we fail to allocate memory for the "pages" pointer. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201119 Fixes: 771ed689d2cd ("Btrfs: Optimize compressed writeback and reads") CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Liu Bo Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -524,6 +524,7 @@ again: pages = kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS); if (!pages) { /* just bail out to the uncompressed code */ + nr_pages = 0; goto cont; }