Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3468158imu; Sun, 11 Nov 2018 15:47:59 -0800 (PST) X-Google-Smtp-Source: AJdET5dimA4qEZMX1+IixRhE50wLCoMrnS7RcoHdDopHruCK69axwhl7SuNk7R/UbVpL5KthmuXV X-Received: by 2002:a17:902:b598:: with SMTP id a24-v6mr17774746pls.231.1541980079333; Sun, 11 Nov 2018 15:47:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980079; cv=none; d=google.com; s=arc-20160816; b=ntb6gkDkFulBd6X2deJ8P2lyC3nkXA8KWP1q52BIzkpooYm14yfbM5k9xgSzDs5VUA u/draSE8hfNhe60YLRVPVXbmVoZvgL5RuuzQmfUW+WWlmYjmlE08lky3Oky/IEBk3RZd vPIFHtZdBr/noKeamh/xNnQ/G2OQQ4pJwM6xhLlLaxAABu8K/SM2USDIB+UdQotMs3Rv REAQvsOvTMIyFfF8RQvuNy2PGqgivgVGp5QZwa0zhIchfgdDPPrRxnhR1ExCHAmfhaAQ Ttu3QGgoRHD6H2z3LrvCb8OmFG6hKuIJAtHliHO5MllErdWO/2v5FVhmt5D5X8FI7NgG 7Q6w== 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=mCrN+tCSyt46+ZQNcNJF/EG2RWHPI36fdTxXpvq1CbQ=; b=KaGfQM4m0q1fKOgHGdN1yXnSA62u4alXk8SqTtEYB28SE8bC3MDny1GHLGNht6XmPq PfUFpsPvxMeGZ90N0HgT3pahNqyBdYsrcX2XufEbDJeRYCc3eCKJI43Z1IZb/Xg7/zor DEh/lVYtatkd9oN+VsVPvJB+5nAFTGHeYWi/x4kPcQTSBMjiW9YOxTDvwUqPuPNMiWje 7wYM0YukB8RmKviIGKAcrDOVMugGCeGz7ibvor6nJqANcIC0IImGL9B+hs+APx+yqz+g 8wESuRwZTzJ8XCSaKHRDUOSQE6FZxeEWEhaRXMXnJScNQ4zz8CG4jicx9HoAp9CINHaW uCWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xdhB+kZn; 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 t74si3862418pgc.150.2018.11.11.15.47.43; Sun, 11 Nov 2018 15:47:59 -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=xdhB+kZn; 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 S1733170AbeKLISs (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:39252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733152AbeKLISr (ORCPT ); Mon, 12 Nov 2018 03:18:47 -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 7678521508; Sun, 11 Nov 2018 22:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975331; bh=0dNY8VtQ93xABMPcA7qdOd7s4UrmGZhL70ACCt+J6/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xdhB+kZnZGhoovDOO7U7QUCI7vBm3XpnFy7ExTbPzhiPzFrVhvz32tt9QqtMLLgAX o1N7Vq+d51k6wNJuCmFkpFcU/576cAOsDnq/xUCrIzfev3rTe1ZJgHgvXtR16mUu3H XFI2nTeXtxX7uonVkov0rkX500E1kc8sMRjIdg64= 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.19 345/361] Btrfs: fix null pointer dereference on compressed write path error Date: Sun, 11 Nov 2018 14:21:32 -0800 Message-Id: <20181111221701.068568354@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -503,6 +503,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; }