From patchwork Wed Jun 12 08:29:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13694637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1BB3C27C75 for ; Wed, 12 Jun 2024 08:29:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 430526B009A; Wed, 12 Jun 2024 04:29:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E0246B009B; Wed, 12 Jun 2024 04:29:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2818E6B009D; Wed, 12 Jun 2024 04:29:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 085B56B009A for ; Wed, 12 Jun 2024 04:29:57 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 73565C112E for ; Wed, 12 Jun 2024 08:29:56 +0000 (UTC) X-FDA: 82221563592.27.059B85E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf29.hostedemail.com (Postfix) with ESMTP id 4D970120013 for ; Wed, 12 Jun 2024 08:29:54 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=HC+NsgFS; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qapP2hSg; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=HC+NsgFS; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qapP2hSg; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718180994; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=543Ixs4ZWLgiYouY+6K/h6dazdyBgWaNSCOWCW6JdR4=; b=ZXAr43z3nfCQs1jQ8QMB8ZEUq0vJ2sji3SoLNPBFBybt5U8ArpsOGkXb9gXmxp2XnE/4t4 hbpYKsukc+eJmb1atW2utXirssCAKj5EdTbvUL1NaG/4/B0suqLUZ4pPkIH5Ia8UvpsRVL tIdsh82VkCFLAx7ctkIXbhT8YB/m9io= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=HC+NsgFS; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qapP2hSg; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=HC+NsgFS; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qapP2hSg; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718180994; a=rsa-sha256; cv=none; b=U4wA0Ip939nrTw4WeTEwaGUczRZnDJc9tay1bRZosJS5yJcboOdZeFa2HmUsiKPXRzSUyR ZZn2LEhtEaEOEURbX9I5ETWWMsCgnVmYcbyhF8o6N5PSJio3N/9WZ4vmmSSh/umY+uC3Rb pncq8PMjtjJCTuMRqxSt9slYniAvMRc= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A97785BEA8; Wed, 12 Jun 2024 08:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718180992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=543Ixs4ZWLgiYouY+6K/h6dazdyBgWaNSCOWCW6JdR4=; b=HC+NsgFSPxyIMlLXYrHKOTbALXSCzRblEh631ikNPGeZtmETx0mAdVK/uAMErpyZlABSWg H7mw8cSbRZwBGYVkAI5912gy/VUY1F1kd0fmOOf5xNG77yIfv+iJbLD345HurFnbec850b 0FfbL6jEhV2hzISCmW3QMEBTiuwJEb0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718180992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=543Ixs4ZWLgiYouY+6K/h6dazdyBgWaNSCOWCW6JdR4=; b=qapP2hSg+MjMW474lK2ZUxie16HHXN6ToyiGPpF0NEqKW5qFwn8j562olet4+IeY9CXJsY 3zN4TlHR9Ye//TCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718180992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=543Ixs4ZWLgiYouY+6K/h6dazdyBgWaNSCOWCW6JdR4=; b=HC+NsgFSPxyIMlLXYrHKOTbALXSCzRblEh631ikNPGeZtmETx0mAdVK/uAMErpyZlABSWg H7mw8cSbRZwBGYVkAI5912gy/VUY1F1kd0fmOOf5xNG77yIfv+iJbLD345HurFnbec850b 0FfbL6jEhV2hzISCmW3QMEBTiuwJEb0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718180992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=543Ixs4ZWLgiYouY+6K/h6dazdyBgWaNSCOWCW6JdR4=; b=qapP2hSg+MjMW474lK2ZUxie16HHXN6ToyiGPpF0NEqKW5qFwn8j562olet4+IeY9CXJsY 3zN4TlHR9Ye//TCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 42D291372E; Wed, 12 Jun 2024 08:29:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id XsffDYBcaWYJXQAAD6G6ig (envelope-from ); Wed, 12 Jun 2024 08:29:52 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , Vivek Kasireddy , Oscar Salvador , syzbot+569ed13f4054f271087b@syzkaller.appspotmail.com Subject: [PATCH] mm/hugetlb: Guard dequeue_hugetlb_folio_nodemask against NUMA_NO_NODE uses Date: Wed, 12 Jun 2024 10:29:36 +0200 Message-ID: <20240612082936.10867-1-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Queue-Id: 4D970120013 X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: cymhiiwi845xe41ascwum784agp1qup8 X-HE-Tag: 1718180994-997220 X-HE-Meta: U2FsdGVkX19xrksX99sngWTTyC+lbPSJv7QKemAad4T2tHNhbFLDPjnBmOVWhVvzZRadXr5fAGzsjQw6ADty7RU2oMLjqM1C95j2VLWL417r9Y1n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73GyaWSPWmy0UJtyOuzSIaNyyO8YU0ga65KUML3XIG0wmju9mDHyFsaRX3VjnSw8iM9Tu0Lsvg8W/djhli38rWs5RzxTMMN7Si/nMNbuRcZe2Gp/P2s7o3XhezlUtEtZgXT5eLmKO1RaQoZGredbX0Bfe/0e4PPuH2id8VbQKErdhyiAl7+0xLt9koDUggfHnjMuYmVi43DZoLAricSaYeXXiKf+N2H9SvoUob64ytVEEAIsFvhoHl9yBi2nCfvPZAry6EsDYS2W+j80zzBqTeZimn9L3+dgIYAhrTmNJ9P53ft/76Yrs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000032, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: dequeue_hugetlb_folio_nodemask() expects a preferred node where to get the hugetlb page from. It does not expect, though, users to pass NUMA_NO_NODE, otherwise we will get trash when trying to get the zonelist from that node. All current users are careful enough to not pass NUMA_NO_NODE, but it opens the door for new users to get this wrong since it is not documented [0]. Guard against this by getting the local nid if NUMA_NO_NODE was passed. [0] https://lore.kernel.org/linux-mm/0000000000004f12bb061a9acf07@google.com/ Closes: https://lore.kernel.org/linux-mm/0000000000004f12bb061a9acf07@google.com/ Reported-and-tested-by: syzbot+569ed13f4054f271087b@syzkaller.appspotmail.com Signed-off-by: Oscar Salvador Reviewed-by: Muchun Song Acked-by: Vivek Kasireddy --- mm/hugetlb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 3518321f6598..6a5ea898e4da 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1355,6 +1355,10 @@ static struct folio *dequeue_hugetlb_folio_nodemask(struct hstate *h, gfp_t gfp_ struct zoneref *z; int node = NUMA_NO_NODE; + /* 'nid' should not be NUMA_NO_NODE. Try to catch any misuse of it and rectifiy. */ + if (nid == NUMA_NO_NODE) + nid = numa_node_id(); + zonelist = node_zonelist(nid, gfp_mask); retry_cpuset: