Received: by 2002:a05:7412:4e10:b0:e2:908c:2ebd with SMTP id gb16csp50469rdb; Mon, 6 Nov 2023 23:39:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2yHrXJxRUOaBFVLiJaZ+tUDK90BNAUqn//8YLwI5JNssRtQhZYckcDllq5iNIMsd+EFmq X-Received: by 2002:a05:6870:d97:b0:1f0:c29:d75c with SMTP id mj23-20020a0568700d9700b001f00c29d75cmr2256377oab.47.1699342768363; Mon, 06 Nov 2023 23:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699342768; cv=none; d=google.com; s=arc-20160816; b=RBqCCohOd5aEtVlNwVnwJnaB/MPzVQdybtlX422zYlQH8bq+U8rYY9/H9WFcB8JZ8n EQLJLvM9U0qcY1AsOVC6IcW1eky89OEU18o8RkNxK+Vh3EntFt1lkm7NFDqw627/mQNo rE9xokskSJJH0v+aB7bDjLtk03pQo+MNcsqK3k+z9/S12v6PNHTjIoyE97PpiQaufAII +3iuxfQa4AZ79mTxjSwpnA6FkQv471/ZFTnD90MJ3aj8S4D9W7rjXjnLTsShb0qVMoT/ Jj43+guF7uQPeqf5+cDCMDr+aaehsir+2rRf/N4fdlWsQZaAHULUGiuUYQQPLO+Ekhr3 kyJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0b2uAK0sTnMtt8sJVqtZt8wq7e4UQ5SUD8tyD2zEIAY=; fh=3u4I00XLrqgSS1+2heF6TIddZOICFQlIlU7B/7Vvjts=; b=Zslubj/eHQAxDc7tetllyJ2Y/uXyukHzNxPz/N9BogAVKZ9ly0aowJJ0MW+lXBtrTw TvMHTPLKXHKGm+J1uIpQrJlcYC+hsyZRgy09kTln0/aQ1hMpnlzTbLxSfkvp7MHVrolK 4BEinGa5L7pEUT65320ruBorxjk3+Jo/uVgD51VkwSnnRTSc7LfZwaAxA5tYOknT2+68 VGTH0QeTiMJ87I0sqXvEbMssDM30k0/eIDIBhgyv5X09SyxQsbcgF/XcZNXxlNPitamB q0OPFTG9Jhz132crUVm7xWC73g6M7GirX24DUGoGYo28URzgolFHLSK7qa4PzZC93kmc ljVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ksipwHS1; 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=chromium.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y184-20020a638ac1000000b005bd052042f4si1663785pgd.69.2023.11.06.23.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 23:39:28 -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=@chromium.org header.s=google header.b=ksipwHS1; 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=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E2C778027F65; Mon, 6 Nov 2023 23:39:25 -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 S233559AbjKGHjT (ORCPT + 99 others); Tue, 7 Nov 2023 02:39:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbjKGHjS (ORCPT ); Tue, 7 Nov 2023 02:39:18 -0500 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA36C6 for ; Mon, 6 Nov 2023 23:39:15 -0800 (PST) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5a8ee23f043so62606247b3.3 for ; Mon, 06 Nov 2023 23:39:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699342755; x=1699947555; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0b2uAK0sTnMtt8sJVqtZt8wq7e4UQ5SUD8tyD2zEIAY=; b=ksipwHS19zH2ls3agE6j8mx1huUfmPqJJ1kaxOsECCEPJMeO5O1er/+kpclJWSDpZa huTP8ughYgWPQjChg8tg6YNeXU239LTttMlgPzhEs3Iy8iQArfwI0oeXb7c3I+3gsfII i0JLt0/wS1mJ3e1soD/fItalfEqm2PQZ3wokk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699342755; x=1699947555; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0b2uAK0sTnMtt8sJVqtZt8wq7e4UQ5SUD8tyD2zEIAY=; b=A5d9xf210eLGc6rAl3nGYheSjQqzsmMMSY3abMn9y5r4DqzAL4dnSC8ihAxLcdGjKS Oa40p+svScB1dyaA/GRAafsDYzMs3uaIMK3MBEFe/HWBaVBYhySecwfIv8OhnJAB4zJp J2Nbe8ir5RhjVBG1LfEUA1KxSkat6eggV2iV0SgRaeUFTpDts9UKbJY6yuVuDToORrkq x1vj36FIXeX4GmmsArPrPrdF2GtnqPwaNhYtdxHiM5LqPhWJG9h98hLxHOy/tPGpaGSJ 0PkfyfzIhFbSxO4z6GygiaviQEcrlxFNBcmWU3/LnKX62Fk1hsBw7zReNonhQc83AEWt 1qgw== X-Gm-Message-State: AOJu0Yxz3PmPuCzt3MZsSDwysMsxvRwAfnuO6BcnvVf91mmGRpIMZGpc YQfrANZrgM/hjZNZ32VENl+nuQ== X-Received: by 2002:a25:cecd:0:b0:d9a:bfe4:d827 with SMTP id x196-20020a25cecd000000b00d9abfe4d827mr33406692ybe.19.1699342754897; Mon, 06 Nov 2023 23:39:14 -0800 (PST) Received: from google.com ([2401:fa00:8f:203:7d66:31e7:94a6:e6a9]) by smtp.gmail.com with ESMTPSA id h22-20020a056a00231600b006be0bd6a4d8sm6666858pfh.36.2023.11.06.23.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 23:39:14 -0800 (PST) Date: Tue, 7 Nov 2023 16:39:11 +0900 From: Sergey Senozhatsky To: Minchan Kim Cc: Sergey Senozhatsky , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, zhouxianrong , Vasily Averin Subject: Re: [PATCH] zram: unsafe zram_get_element call in zram_read_page() Message-ID: <20231107073911.GB11577@google.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE,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 23:39:26 -0800 (PST) On (23/11/06 22:54), Vasily Averin wrote: > @@ -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); Hmmm, We may want to do more here. Basically, we probably need to re-confirm after read_from_bdev() that the entry at index still has ZRAM_WB set and, if so, that it points to the same blk_idx. IOW, check that it has not been free-ed and re-used under us. Minchan, what do you think? Is that scenario possible?