Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5893003imb; Fri, 8 Mar 2019 04:56:08 -0800 (PST) X-Google-Smtp-Source: APXvYqwzmb6cjRdmjcsPdldKroiya1scC7Z/6us91gTBGGn8NlJba0HmSM9S8a25ToUTiwX2Etpn X-Received: by 2002:a62:45da:: with SMTP id n87mr11781605pfi.160.1552049768820; Fri, 08 Mar 2019 04:56:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552049768; cv=none; d=google.com; s=arc-20160816; b=yUQSXsRn/Zy68ji7oIcUoHDJbdmjN0hNkStz9sj5lMhPG6JKJLRMzAPhbpmmbIMKkF 0MwlY3/Q8CKtc7nLS2+y3ZFIWXBniOfXey4bSHCf8y/+hnqtnLPCVskL4W8SN3/3WY0h pBcBqf7vIbyoVPiB0LkCznuWszwzxZnYOL7LyUKLY60ekr8gdlCESkdshRVTBgIHdeXm FkIm9kI5rl2I7P/32LNlxTijXLS6uqnhVQvyIGOr7u2ScxjmLR4nDrFbQ6Sca+g9El9k W+5ZigySdobnzWeNZGpOh1sSthWUwCItcI8B0yizxSKn2qQeclr7Ng97c5bndArM3lhp yu2w== 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=/Bv82vkjE6rhGFvS7bm2UrKLDWIm+SPNf3lbeNgpBSs=; b=b8Br1wGsKzV87j31P5Y8yZhaOBpROy2S3eKJ+ZXtCOtp/AyNifv2M4vWyQ3YRNrWEo oU0G6hKw5GSIlvMkgR3jipPPlFQzfOnsz9eB/8F6OFSQTcvbJ6KY16F29F0p8XLSRSUh EuujFpEXxsT78FCefYN9dlw1dPgLU+wu2yFmyu9C4OgSXUZgh53PwYW4DppcMIyV2qe7 kcFBpR66T5omKVAH0bR07J34tUk0IntklA4XUDi7s4C43a3F1Tj+3o/HzSmEtwVYymck uOvIbrPxKvTPpXrQg0Qx6miWJaoR6iTw+Hky3yssNTR/FCHc9V5adRvioHsgm2WFFp7f +nmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Dwr2aV8r; 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 ck9si7484880plb.196.2019.03.08.04.55.53; Fri, 08 Mar 2019 04:56:08 -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=Dwr2aV8r; 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 S1727173AbfCHMxk (ORCPT + 99 others); Fri, 8 Mar 2019 07:53:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:57292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726763AbfCHMxi (ORCPT ); Fri, 8 Mar 2019 07:53:38 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 557F72133F; Fri, 8 Mar 2019 12:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552049616; bh=EShz7fnOTlvMOfgPn9Xy3ZHlCcDrtiynqbqlAPTZ9Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dwr2aV8rCRZW2C6wtGEB5Kk/W7jnMjE4NnhmGyooXUpHHwA23wLJYoaPwDzNWES4V cuPGjfL5NtiPu3Tpn8ubDrIMQSnoYbXmcitOWZ76Y2p+7XRIB7MDjMHCU8qeI+GFSk dGJjX1tnaVWithG8fh7XW2PHDUlt4UcdAQ+Vo3HQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gao Xiang , Chao Yu Subject: [PATCH 4.20 11/76] staging: erofs: fix illegal address access under memory pressure Date: Fri, 8 Mar 2019 13:49:23 +0100 Message-Id: <20190308124915.182837841@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190308124914.789210760@linuxfoundation.org> References: <20190308124914.789210760@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gao Xiang commit 1e5ceeab6929585512c63d05911d6657064abf7b upstream. Considering a read request with two decompressed file pages, If a decompression work cannot be started on the previous page due to memory pressure but in-memory LTP map lookup is done, builder->work should be still NULL. Moreover, if the current page also belongs to the same map, it won't try to start the decompression work again and then run into trouble. This patch aims to solve the above issue only with little changes as much as possible in order to make the fix backport easier. kernel message is: <4>[1051408.015930s]SLUB: Unable to allocate memory on node -1, gfp=0x2408040(GFP_NOFS|__GFP_ZERO) <4>[1051408.015930s] cache: erofs_compress, object size: 144, buffer size: 144, default order: 0, min order: 0 <4>[1051408.015930s] node 0: slabs: 98, objs: 2744, free: 0 * Cannot allocate the decompression work <3>[1051408.015960s]erofs: z_erofs_vle_normalaccess_readpages, readahead error at page 1008 of nid 5391488 * Note that the previous page was failed to read <0>[1051408.015960s]Internal error: Accessing user space memory outside uaccess.h routines: 96000005 [#1] PREEMPT SMP ... <4>[1051408.015991s]Hardware name: kirin710 (DT) ... <4>[1051408.016021s]PC is at z_erofs_vle_work_add_page+0xa0/0x17c <4>[1051408.016021s]LR is at z_erofs_do_read_page+0x12c/0xcf0 ... <4>[1051408.018096s][] z_erofs_vle_work_add_page+0xa0/0x17c <4>[1051408.018096s][] z_erofs_vle_normalaccess_readpages+0x1a0/0x37c <4>[1051408.018096s][] read_pages+0x70/0x190 <4>[1051408.018127s][] __do_page_cache_readahead+0x194/0x1a8 <4>[1051408.018127s][] filemap_fault+0x398/0x684 <4>[1051408.018127s][] __do_fault+0x8c/0x138 <4>[1051408.018127s][] handle_pte_fault+0x730/0xb7c <4>[1051408.018127s][] __handle_mm_fault+0xac/0xf4 <4>[1051408.018157s][] handle_mm_fault+0x7c/0x118 <4>[1051408.018157s][] do_page_fault+0x354/0x474 <4>[1051408.018157s][] do_translation_fault+0x40/0x48 <4>[1051408.018157s][] do_mem_abort+0x80/0x100 <4>[1051408.018310s]---[ end trace 9f4009a3283bd78b ]--- Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support") Cc: # 4.19+ Signed-off-by: Gao Xiang Reviewed-by: Chao Yu Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/staging/erofs/unzip_vle.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/staging/erofs/unzip_vle.c +++ b/drivers/staging/erofs/unzip_vle.c @@ -626,8 +626,12 @@ repeat: /* lucky, within the range of the current map_blocks */ if (offset + cur >= map->m_la && - offset + cur < map->m_la + map->m_llen) + offset + cur < map->m_la + map->m_llen) { + /* didn't get a valid unzip work previously (very rare) */ + if (!builder->work) + goto restart_now; goto hitted; + } /* go ahead the next map_blocks */ debugln("%s: [out-of-range] pos %llu", __func__, offset + cur); @@ -641,6 +645,7 @@ repeat: if (unlikely(err)) goto err_out; +restart_now: if (unlikely(!(map->m_flags & EROFS_MAP_MAPPED))) goto hitted;