Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3023564ybt; Mon, 29 Jun 2020 13:11:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6JV3JpTagYRPszs2sjFeAkUHTtonBFHWd5WdDfkiaPCbwq6vp3OqFUGs+uPN2FUwsWrn1 X-Received: by 2002:a05:6402:1c86:: with SMTP id cy6mr6445027edb.30.1593461466577; Mon, 29 Jun 2020 13:11:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593461466; cv=none; d=google.com; s=arc-20160816; b=dDmsxyMqa/iGdk+tBfGrCHIwK4KvWDNtl+9XP7bqQxhSeTxrZVu/2KY0uh9zvlvnyN 5a9BZ6PO/VqScrHZ9q3/MGN4jSe82ihUpyMpacpDAsWIiMCG8ABiAH4qFR/rKT4qczB5 J7wu2GzG0FgJcBpim1idqg7XOBDpf1kB4FiGuGJPFXR0L4GpzTMVMolQDt91I3Mrgekb gEbtoQKxCGHcwxrnbO0JhN5SvH1sr//JOu6rjSzectzmT5WnKvC0CKdSpgKJF2HHZuye TTRuYWJBEdVev3P3/yrsF/zgr8Va7S1vypI/pF8AD+qll4kWgaFJU4F+Z3b6RLy1NY6O 8Aiw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ov1A4CjtBWgjhTT5a2pNQ2gRAavlYIqaKANHt+hVZ8M=; b=nlrQXQ0Q+yXm1RrUVpEV0vcWTmCaznp/F+rciM/Z8lEcO1iJD6qPB2aPqv9zj6o61F 9i7Ao4UMB0OYQKwIk2cyZ2javWylVA6EPeDsd73ytiJQd7c/eBQJPdGEDXXl66AUsGVJ M5oOU5dX2gUCNiO9lUVQ+y72Vykv34LxxAWOC1yeVrnnGBNVSbjfAHDzeasEnI9dntKt 0P8v4GDt289OVN65CRDi+553aiQF73dcjjitKf8hslw0BrbSn5WGFJ1a47tzTZFbZFrD Xb4VEnw7h27z1dxz8mAoyz84AeW24EbWlYUfaLc3PN1JM2IS4k18tmeVstIxDhzdalbe 2h6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jcFGgtNC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n20si351592ejs.158.2020.06.29.13.10.43; Mon, 29 Jun 2020 13:11:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jcFGgtNC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727015AbgF2UJq (ORCPT + 99 others); Mon, 29 Jun 2020 16:09:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:40554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732924AbgF2TaW (ORCPT ); Mon, 29 Jun 2020 15:30:22 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0755A25298; Mon, 29 Jun 2020 15:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593445006; bh=UiTGzYgiwJtil1e+utSA+jGg7dXl4VCjtAJXPf4JREM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jcFGgtNCfGGGXFEA5cbjwYlfDH9A5qD41cvgCeFK4X1MRUYZ9I6PZXHbhQVTEzz3Z vVhQF2Gf13EH6xdFvf0r8OyK4xII3Kb4qp4+vhHyPvv+AQkXXQvu5WK8nljXc6knjX 591j8GzBAOee7iwg0+HmDYVWwNjBuHHWsxUtVdyQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Gao Xiang , Hongyu Jin , Chao Yu , Greg Kroah-Hartman Subject: [PATCH 4.19 107/131] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup Date: Mon, 29 Jun 2020 11:34:38 -0400 Message-Id: <20200629153502.2494656-108-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629153502.2494656-1-sashal@kernel.org> References: <20200629153502.2494656-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.131-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.131-rc1 X-KernelTest-Deadline: 2020-07-01T15:34+00:00 X-stable: review X-Patchwork-Hint: Ignore 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 3c597282887fd55181578996dca52ce697d985a5 upstream. Hongyu reported "id != index" in z_erofs_onlinepage_fixup() with specific aarch64 environment easily, which wasn't shown before. After digging into that, I found that high 32 bits of page->private was set to 0xaaaaaaaa rather than 0 (due to z_erofs_onlinepage_init behavior with specific compiler options). Actually we only use low 32 bits to keep the page information since page->private is only 4 bytes on most 32-bit platforms. However z_erofs_onlinepage_fixup() uses the upper 32 bits by mistake. Let's fix it now. Reported-and-tested-by: Hongyu Jin Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support") Cc: # 4.19+ Reviewed-by: Chao Yu Link: https://lore.kernel.org/r/20200618234349.22553-1-hsiangkao@aol.com Signed-off-by: Gao Xiang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/erofs/unzip_vle.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/staging/erofs/unzip_vle.h b/drivers/staging/erofs/unzip_vle.h index 684ff06fc7bf8..630fd1f4f123d 100644 --- a/drivers/staging/erofs/unzip_vle.h +++ b/drivers/staging/erofs/unzip_vle.h @@ -169,22 +169,22 @@ static inline void z_erofs_onlinepage_init(struct page *page) static inline void z_erofs_onlinepage_fixup(struct page *page, uintptr_t index, bool down) { - unsigned long *p, o, v, id; -repeat: - p = &page_private(page); - o = READ_ONCE(*p); + union z_erofs_onlinepage_converter u = { .v = &page_private(page) }; + int orig, orig_index, val; - id = o >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT; - if (id) { +repeat: + orig = atomic_read(u.o); + orig_index = orig >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT; + if (orig_index) { if (!index) return; - BUG_ON(id != index); + DBG_BUGON(orig_index != index); } - v = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) | - ((o & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned)down); - if (cmpxchg(p, o, v) != o) + val = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) | + ((orig & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned int)down); + if (atomic_cmpxchg(u.o, orig, val) != orig) goto repeat; } -- 2.25.1