Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2370349rdf; Mon, 6 Nov 2023 12:03:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAILVrS3CRmUlnCzS/mZuPYR0FtIi3DPw8117UmcNSLYBPZINgZwEQa9FvzNz54gxAInFh X-Received: by 2002:a9d:65d4:0:b0:6c4:ded2:44d0 with SMTP id z20-20020a9d65d4000000b006c4ded244d0mr33310741oth.27.1699301038152; Mon, 06 Nov 2023 12:03:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699301038; cv=none; d=google.com; s=arc-20160816; b=KxdgpzdKAbqD2oYhtknrJ6Fa0yK+BwH/qaOVuvRt988puXduh+mKXvO62TeUlflF4u hCNuDruV08/e/s+Y31k+vQ5CxIkZh4WbKBwSz5qgo54QFcINyyL3pGQa8d6MfyQ4l3rC kH8GFRy+sAdIoM8bQ07wDs9oL7Zi3MPJT5Mpw5oFz+xWS+qwlXytR4LHUNmfH+OrHu6H 8WF9pgqO3gotHb7Y7lhpUOD7L+JJMez29jkC8Fb95NqrNeNrOqbAU8NAKN5/4ya91SY4 /3jUvj0V0cpNAaKe1mo7llhw6tHYfPhDI72FUyLLNtZtfDyBNp/ebXpFX3vkGdDEgzVa 8rcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language:cc:to :subject:from:mime-version:date:dkim-signature:message-id; bh=vU+9mLKaBt/9PJ4s/VTap23H3EjIRGGrzaVjKta+G/s=; fh=xlqUB/qUfq6Wucj1GJj9gGkLZlZKWhc3o9dxAjJZNE8=; b=fqXLBH10mK656aQDjGfpJyxPHUG+RN5f9JrgTbY391mFEKeiJdVVzDWHG6xh33lDpD LuVSNSqwcLqwgXKQv4IpKuJVVkHywNF+oy6nPUhYUJVCiS6hHtX/3kYEVSp4tHldQT6i qFZbK1uAMo6pjvfI547g1ZT8EA7g5XEmxvC/tMGFCyKWqpSJEM4oUpY8gNPO0PQNNGfN 5EbVmc4WF1XtvSSZtoMMfxck+PCV5Q/egqlK5qwpnW/6yuZ/dJqfIoEAWmXWYY4GtyLs b9P7+lkWlg6dNejTSkQ9oGMvpCQi8Cizpc0+vr6X0AMS+dQCnFgZtup7kKbjsVW/i/8p Lvjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xpCJ1ElK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id v18-20020a9d4e92000000b006ce2cc48fa5si3259932otk.145.2023.11.06.12.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:03:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xpCJ1ElK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1A46180323E3; Mon, 6 Nov 2023 12:03:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232686AbjKFUDh (ORCPT + 99 others); Mon, 6 Nov 2023 15:03:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231777AbjKFUDf (ORCPT ); Mon, 6 Nov 2023 15:03:35 -0500 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [IPv6:2001:41d0:203:375::b7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38BBBD45 for ; Mon, 6 Nov 2023 12:03:32 -0800 (PST) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699300471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vU+9mLKaBt/9PJ4s/VTap23H3EjIRGGrzaVjKta+G/s=; b=xpCJ1ElKH72f9/zGJuXVlwvCzM3N90Yye4IigCBUUFw0Glb8AM0AmVBD5Y/9aGSVXPOGdG haJI+msf6/4p9LW156nfi/eW4Yg8aUOo7H6BvjnykClnGgXvbGsme+B79lfQU05+IpEk31 onMDf3PLaoP5YdCGA9mwkmkRTQsuMI4= Date: Mon, 6 Nov 2023 22:54:28 +0300 MIME-Version: 1.0 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Vasily Averin Subject: [PATCH] zram: unsafe zram_get_element call in zram_read_page() To: Sergey Senozhatsky , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, zhouxianrong Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 06 Nov 2023 12:03:55 -0800 (PST) Taken lock is required to access the content of zram entry. Fixes: 8e19d540d107 ("zram: extend zero pages to same element pages") Signed-off-by: Vasily Averin --- drivers/block/zram/zram_drv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index d77d3664ca08..9ac3d4e51d26 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1362,14 +1362,14 @@ static int zram_read_page(struct zram *zram, struct page *page, u32 index, ret = zram_read_from_zspool(zram, page, index); zram_slot_unlock(zram, index); } else { + unsigned long entry = zram_get_element(zram, index); /* * The slot should be unlocked before reading from the backing * device. */ zram_slot_unlock(zram, index); - ret = read_from_bdev(zram, page, zram_get_element(zram, index), - parent); + ret = read_from_bdev(zram, page, entry, parent); } /* Should NEVER happen. Return bio error if it does. */ -- 2.34.1