Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3705510ybv; Mon, 10 Feb 2020 05:03:29 -0800 (PST) X-Google-Smtp-Source: APXvYqxbtrAyOGgmI9PfC2eoXTqj4K8fLOb0sATBejeSRVEo4FyZS3Tpc6brZwRnvGHpfgf51qIh X-Received: by 2002:a9d:6653:: with SMTP id q19mr1010492otm.94.1581339809686; Mon, 10 Feb 2020 05:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339809; cv=none; d=google.com; s=arc-20160816; b=S5ERZ9Xd7pbgoD+XAwAHQ9VLtJgibAXea0gBZa0Vf10CHoD285bUHuC9n7H0137Vhz 6/aDeAqtEtFZ7tJaUvrVmi5Bjo/6WV+TjCwkNnWWD/uYZQ1e4zAR1ruSLoY4uiq/G6aE jbwETGFgvtDDphMNZARzyB2E3basIMKMYjmlCGQROy0z+XK2VhEapl2k/8CHOL/jaaFM dQnbvU3LIIGQNufYdyu+SlvNpvKghKTe8xcz55BvrEJuw/j9t4C60o5Sbgf3uXJGZvPy pHnupPSgXIHu4wQXH2F36NHm0SNYkdYhmqqC1/hZFcM+WY4/0vjQ0ZLsn1PA4u5W4+rG WeIQ== 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=vomFQJUds5jOdfo2ttPlT5U4KVGEWeRUh2FmOaKvgJA=; b=KopaxDw57Kh5QNF9z/c93RN2YYy4qLmhgszO6LkbSysdHdBNeenUJ1tRmJlFBt8qYp B4hYfT5kBXOFZ+vFVTJhem3hPPYIDF+NHhZMtnoRivgA0vA2sn9fSTKC6PtH+x42LWX5 3+GZVFabbu3ClsIlxNxqW9mfzgJGZ9jjyovJnvhokvlR6X3gkjhOb+k+mtO4iBvodNXW ulC5n7ySqvDOqhtR/GdqrjvoU3IpNgXQHVMaCTRtWIeL0cvccwIsiL9/UidC9y6JiGrk S0s4S0aVZ8dtskv0avPzkw0qS5kel6T8E7Kq1lG+M1/tZ68bsnatLGbncxRtSs8Q7D1u fKuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="09gt/pf9"; 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 z62si139179oiz.271.2020.02.10.05.03.14; Mon, 10 Feb 2020 05:03:29 -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="09gt/pf9"; 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 S1730600AbgBJNC3 (ORCPT + 99 others); Mon, 10 Feb 2020 08:02:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:40902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729758AbgBJMke (ORCPT ); Mon, 10 Feb 2020 07:40:34 -0500 Received: from localhost (unknown [209.37.97.194]) (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 B6BBA2467D; Mon, 10 Feb 2020 12:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338433; bh=GRrgdaBKjL7H/DYU4S4r9eSeGzhbrKumaiPdWRarlHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=09gt/pf9EhDv4aVgp5Q0QQqduVAFglknzCUv6dSSPM2OlsjbHemOeb9GDiEfLQsn/ 2jK+g/VD2+rH91o4BafA4OAdwI1zcVtKZopZXft8xWFpbpnygCktqtptQ3kiaoTVwT TXFuLxavg2vzoJFdO7tn61WxSocO2lx/172Mw6QE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Gao Xiang Subject: [PATCH 5.5 123/367] erofs: fix out-of-bound read for shifted uncompressed block Date: Mon, 10 Feb 2020 04:30:36 -0800 Message-Id: <20200210122436.153487613@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Gao Xiang commit 4d2024370d877f9ac8b98694bcff666da6a5d333 upstream. rq->out[1] should be valid before accessing. Otherwise, in very rare cases, out-of-bound dirty onstack rq->out[1] can equal to *in and lead to unintended memmove behavior. Link: https://lore.kernel.org/r/20200107022546.19432-1-gaoxiang25@huawei.com Fixes: 7fc45dbc938a ("staging: erofs: introduce generic decompression backend") Cc: # 5.3+ Reviewed-by: Chao Yu Signed-off-by: Gao Xiang Signed-off-by: Greg Kroah-Hartman --- fs/erofs/decompressor.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -306,24 +306,22 @@ static int z_erofs_shifted_transform(con } src = kmap_atomic(*rq->in); - if (!rq->out[0]) { - dst = NULL; - } else { + if (rq->out[0]) { dst = kmap_atomic(rq->out[0]); memcpy(dst + rq->pageofs_out, src, righthalf); + kunmap_atomic(dst); } - if (rq->out[1] == *rq->in) { - memmove(src, src + righthalf, rq->pageofs_out); - } else if (nrpages_out == 2) { - if (dst) - kunmap_atomic(dst); + if (nrpages_out == 2) { DBG_BUGON(!rq->out[1]); - dst = kmap_atomic(rq->out[1]); - memcpy(dst, src + righthalf, rq->pageofs_out); + if (rq->out[1] == *rq->in) { + memmove(src, src + righthalf, rq->pageofs_out); + } else { + dst = kmap_atomic(rq->out[1]); + memcpy(dst, src + righthalf, rq->pageofs_out); + kunmap_atomic(dst); + } } - if (dst) - kunmap_atomic(dst); kunmap_atomic(src); return 0; }