Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3112191pxm; Mon, 28 Feb 2022 12:15:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKKOMVdcDQAB+oABDbk9UiYpMjBxWFxK7cabqbU5r33zRsFbqbJI2gqlHPaTtbSM0JZPNB X-Received: by 2002:a05:6a00:1901:b0:4f3:c0f6:5c47 with SMTP id y1-20020a056a00190100b004f3c0f65c47mr22410488pfi.69.1646079341628; Mon, 28 Feb 2022 12:15:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079341; cv=none; d=google.com; s=arc-20160816; b=ASC1UjU3rQBKSC1P8uvSBxkX5VB4uNVrTIFiRW3KEV1Wki6WSLCNp4DEuHydVjWqLP pjsCHDFom9+eP0DsH9hzALC25bxtEW2vdxoOEHwSFLI99En3wgoeR2lnONitw6Sj3P4B CPQD/P2dIxrrImQ7FlkW9cdhKJeAAbZoQDMhzBLD3+DVVwIyMNXgHWcXN+aHoS+FmMeU JyXiDLIwrlAghFMNDCMSFbF9zr/VZFswW7mpY4I5CHEDiKiDgU5HV4OxpQ3I5q7dizuK BW1fMaREaMnEpBMK/XhSj46pBE8wmtgHNkQz3+4luUqySKxm9u/kNMIn1WzLTwUMmykF 3Fyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KQ34Y/VZhJAeCcxFWZhnOiEvAiUrOAy/f1iwYFgtgag=; b=egj0eiPyknO+ZygVRKc8VjWSdgvjvv9AOVTEB0X955Vq8nE1NS5uXmgb4EfEmfEkOh USYuoAX4TovEZ++lN1DV6Z+ahvaAoiq+frNlDxNb1hsrVkVgUZPjYUMC1PqQ55MD5jjm UbCugv6CXdykddiXWlV7P5XfqtRPHwn3mdcAZOwdDlOQVRKT8qhBQUyOpsqCqNNWSNNb DBm1uHkAJT5cAA5LUTivRDODIDyjbAHSrPmOYhLoQV4PHaL3hBo3N9okchIuNwcuIgTx nSabXfU+6YSUP4E4EIJlwIcvCEcMmO31zldrXmatQOKBjh9LoQ4CxuMI/7ZToQ1TIUie rLPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MlgezriO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c193-20020a6335ca000000b003700bb51acesi10354676pga.830.2022.02.28.12.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:15:41 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MlgezriO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BAF5617E34D; Mon, 28 Feb 2022 11:37:58 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237565AbiB1Rrf (ORCPT + 99 others); Mon, 28 Feb 2022 12:47:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239412AbiB1RoI (ORCPT ); Mon, 28 Feb 2022 12:44:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 450FB9D0F4; Mon, 28 Feb 2022 09:36:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 85B65614CC; Mon, 28 Feb 2022 17:36:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E666C340F4; Mon, 28 Feb 2022 17:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646069779; bh=X9Sr+rdd3b35f9HJB8DUKe1EYqkMTwI/FJ63jaiHMT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MlgezriOp73C5zpIO9FqTzurqrYGZ0x7A3oRueHaiAXTMGWWE+V4oPX6oX5KzzTT1 Nx5Z45nzMiDoPRDKlnLGnFpQ5n0WvvycawNSd8b27X/y7kGITLltsINLiH82DB/l/K fH6bjiVOWcZ0n2rJ9Bq4cmCB1T/RIe/g79lEInJQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, "stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, Song Liu" Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vlastimil Babka , "Matthew Wilcox (Oracle)" , Adam Majer , Dirk Mueller , Takashi Iwai Subject: [PATCH 5.15 001/139] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Date: Mon, 28 Feb 2022 18:22:55 +0100 Message-Id: <20220228172347.742815203@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172347.614588246@linuxfoundation.org> References: <20220228172347.614588246@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Matthew Wilcox (Oracle)" When a THP is present in the page cache, we can return it several times, leading to userspace seeing the same data repeatedly if doing a read() that crosses a 64-page boundary. This is probably not a security issue (since the data all comes from the same file), but it can be interpreted as a transient data corruption issue. Fortunately, it is very rare as it can only occur when CONFIG_READ_ONLY_THP_FOR_FS is enabled, and it can only happen to executables. We don't often call read() on executables. This bug is fixed differently in v5.17 by commit 6b24ca4a1a8d ("mm: Use multi-index entries in the page cache"). That commit is unsuitable for backporting, so fix this in the clearest way. It sacrifices a little performance for clarity, but this should never be a performance path in these kernel versions. Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read") Cc: stable@vger.kernel.org # v5.15, v5.16 Link: https://lore.kernel.org/r/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.cz/ Analyzed-by: Adam Majer Analyzed-by: Dirk Mueller Bisected-by: Takashi Iwai Reported-by: Vlastimil Babka Tested-by: Vlastimil Babka Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Greg Kroah-Hartman --- mm/filemap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2354,8 +2354,12 @@ static void filemap_get_read_batch(struc break; if (PageReadahead(head)) break; - xas.xa_index = head->index + thp_nr_pages(head) - 1; - xas.xa_offset = (xas.xa_index >> xas.xa_shift) & XA_CHUNK_MASK; + if (PageHead(head)) { + xas_set(&xas, head->index + thp_nr_pages(head)); + /* Handle wrap correctly */ + if (xas.xa_index - 1 >= max) + break; + } continue; put_page: put_page(head);