Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp222699lqp; Tue, 11 Jun 2024 22:12:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWJCIYm4NiZAb893bNQOEGCqlqU7TchtLG5FiTrciKomkRw8rJQtdIVl1yLfWnXCoXwf6szycuHt/fAikerXy6JcXJ/GaRvCqDTG+Bp7A== X-Google-Smtp-Source: AGHT+IFvHYHmCMyhsYWIbD7r3lcqiIJgBeoqb/Ldx+JWuicbrd0LVlihvdYcn0iKOoHpyHJWaihL X-Received: by 2002:a17:902:e844:b0:1f6:f9aa:e186 with SMTP id d9443c01a7336-1f83b716bafmr9893515ad.57.1718169130844; Tue, 11 Jun 2024 22:12:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718169130; cv=pass; d=google.com; s=arc-20160816; b=VxDiKs4lOh9sQKLbvu60hPHg/Hka/8ifd3tWD3NkjujEu3cqrtDN7skQakQTbV/MTs 8qwlAy4z4IiULsmt6NWd5i5+pUhaH41n+/9V+8JjmjJVcowVtqh2nN+MlRsT4qo9B/Ax x0FAsn/eyhvKR3y69RuPR0kP7yV9HYaSkGf0N+9A+pdb5J9+YWOwJXxk8lXJItZgrAJv jNi02XC5Yfmg/AcB6aKHmXvBo1irndMnIhpWcOmw/CGQh9jtPR8rUvezkPI8EpuLESua aAugzRjNTkrmcfaQ+5HIIhvJsNNWj0tthyGvqlo9zV/bImdd31/P42m+3FUvKEf+ZFyz xgDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=r3YBn/nAZuJl3pGHfMw3MJArLAqmqGFrn2hyTXR70cM=; fh=NJD39bxVhhFSQ8FVXr5vOMPAFkeOrt4XAMUHkxyhocI=; b=Yx9AEWM+RRumOTTSLWRH/cbls4svy/5HR51jRC+WwzaggdyKfC6CJvk41iQwL1E5WT NbRajIFBHIilDJd3sIdaSOakidS8jgr2y83pjPYTDqwPkHc1BaI7I5lxg6eiQT/CHNYp jvWdjNrO9kUntZHhmRMikH1SDpt5cathqBak+LIFLJkPdjyRW8jdEmHMB6VhmnlbqWth w+8dEXLaRDimwULrmMPn6ZKOh2Q2NnAlyR1Z++F4pLOpMj7TL6lrq1wQ0DI+L2w9v8UG UgctkZevYAWOUI9zh6nZzZBWlNCCwYeLPzquLGS6KyoU0dSJPRxNYXymeHNrezCVWH1u WlQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="fX25/7Y5"; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="fX25/7Y5"; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-210936-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210936-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd7e4f7asi72318505ad.385.2024.06.11.22.12.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 22:12:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210936-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="fX25/7Y5"; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="fX25/7Y5"; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-210936-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210936-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 60FA2281C9E for ; Wed, 12 Jun 2024 05:12:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0C6831A83; Wed, 12 Jun 2024 05:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fX25/7Y5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="TQEukDXp"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fX25/7Y5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="TQEukDXp" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 115F528DD1 for ; Wed, 12 Jun 2024 05:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169124; cv=none; b=UoQd8yE+2LL9QMS4Qx0FHItw4GUiCmuZL4wfMj2b+iLMjqdAUaTGpYG+ZJvtQf981+zIeFPi9HNMZG6+P+Db+gQsohAHXD1MShEqJEF2aHt+Uz9raktO4Hdcy2/qKTZshDeSkksTe/fwU9bLzJNpSLoslWZdGhsammIE1+h6FfE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718169124; c=relaxed/simple; bh=As6APksy1IGxV4JLIT2WN1gTJM2ZYvvx3ja6MzDeckM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BN3jH6NaRqeX9mil8nJzMMJvlPGcCxKpFWT+4cM3HnI/nkgdlrzKJX8BHWXLqr/zIJ/+6eSUGpBRDbpK6LBkEZm0kESa9rkr2YbQRpYQKbxQkWebLc52olN6VmUs1T/D/tactp2Tmnn/rlxFh5As3WTYFf8sx8QVPbdclbdDWDg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fX25/7Y5; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=TQEukDXp; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=fX25/7Y5; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=TQEukDXp; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (unknown [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-out1.suse.de (Postfix) with ESMTPS id 1231A33EC2; Wed, 12 Jun 2024 05:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718169121; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r3YBn/nAZuJl3pGHfMw3MJArLAqmqGFrn2hyTXR70cM=; b=fX25/7Y5DzIfPRxSG5CRhJ4ACd8LIvhUipT+cSstyXQ+yiSfeFf8+WXErYQ1K35LOA8jJ4 768G5z2kFRGqZa/R6L2CayIfYFjmkrqRY3/z3AnJpqkZH3KF1zqjA9wPslf6PFB4Ww+uDt UElrJNaMjPwPFt5MfYpWT7byu3Usw4Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718169121; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r3YBn/nAZuJl3pGHfMw3MJArLAqmqGFrn2hyTXR70cM=; b=TQEukDXpbw6EYkkYBQxMR/vDy3gpQQr5imz/npGfEGpWWj4ZtF5o0EXw0TAhGRzd7A6WNT CAIzVzWVfLtY3YAQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718169121; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r3YBn/nAZuJl3pGHfMw3MJArLAqmqGFrn2hyTXR70cM=; b=fX25/7Y5DzIfPRxSG5CRhJ4ACd8LIvhUipT+cSstyXQ+yiSfeFf8+WXErYQ1K35LOA8jJ4 768G5z2kFRGqZa/R6L2CayIfYFjmkrqRY3/z3AnJpqkZH3KF1zqjA9wPslf6PFB4Ww+uDt UElrJNaMjPwPFt5MfYpWT7byu3Usw4Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718169121; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r3YBn/nAZuJl3pGHfMw3MJArLAqmqGFrn2hyTXR70cM=; b=TQEukDXpbw6EYkkYBQxMR/vDy3gpQQr5imz/npGfEGpWWj4ZtF5o0EXw0TAhGRzd7A6WNT CAIzVzWVfLtY3YAQ== 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 A0217137DF; Wed, 12 Jun 2024 05:12:00 +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 +EV7JCAuaWY2KAAAD6G6ig (envelope-from ); Wed, 12 Jun 2024 05:12:00 +0000 Date: Wed, 12 Jun 2024 07:11:59 +0200 From: Oscar Salvador To: Andrew Morton Cc: syzbot , linux-kernel@vger.kernel.org, linux-mm@kvack.org, muchun.song@linux.dev, syzkaller-bugs@googlegroups.com, Vivek Kasireddy Subject: Re: [syzbot] [mm?] general protection fault in dequeue_hugetlb_folio_nodemask (2) Message-ID: References: <0000000000004f12bb061a9acf07@google.com> <20240611103005.ae4170608bd15d63adee2492@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; TAGGED_RCPT(0.00)[569ed13f4054f271087b]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; SUBJECT_HAS_QUESTION(0.00)[] X-Spam-Flag: NO X-Spam-Score: -2.80 X-Spam-Level: On Tue, Jun 11, 2024 at 07:52:06PM +0200, Oscar Salvador wrote: > On Tue, Jun 11, 2024 at 07:46:33PM +0200, Oscar Salvador wrote: > > On Tue, Jun 11, 2024 at 10:30:05AM -0700, Andrew Morton wrote: > > > On Tue, 11 Jun 2024 03:34:25 -0700 syzbot wrote: > > > > > > > Hello, > > > > > > > > syzbot found the following issue on: > > > > > > Thanks. > > > > > > > Call Trace: > > > > > > > > alloc_hugetlb_folio_nodemask+0xae/0x3f0 mm/hugetlb.c:2603 > > > > memfd_alloc_folio+0x15e/0x390 mm/memfd.c:75 > > > > memfd_pin_folios+0x1066/0x1720 mm/gup.c:3864 > > > > udmabuf_create+0x658/0x11c0 drivers/dma-buf/udmabuf.c:353 > > > > udmabuf_ioctl_create drivers/dma-buf/udmabuf.c:420 [inline] > > > > udmabuf_ioctl+0x304/0x4f0 drivers/dma-buf/udmabuf.c:451 > > > > vfs_ioctl fs/ioctl.c:51 [inline] > > > > __do_sys_ioctl fs/ioctl.c:907 [inline] > > > > __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:893 > > > > do_syscall_x64 arch/x86/entry/common.c:52 [inline] > > > > do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83 > > > > entry_SYSCALL_64_after_hwframe+0x77/0x7f > > > > > > I think we can pretty confidently point at the series "mm/gup: > > > Introduce memfd_pin_folios() for pinning memfd folios". I'll drop the > > > v14 series. > > > > jfyi: I am trying to reproduce this locally. > > Actually, should not memfd_alloc_folio() pass htlb_alloc_mask() instead > of GFP_USER to alloc_hugetlb_folio_nodemask? Or at least do > GFP_HIGHUSER. Ok, I spot the issue. memfd_alloc_folio() was calling alloc_hugetlb_folio_nodemask with preferred_nid being NUMA_NO_NODE, but that is bad as dequeue_hugetlb_folio_nodemask will do: zonelist = node_zonelist(nid, gfp_mask) which will try to get node_zonelists from nid, but since nid is -1, heh. The below patch fixes the issue for me, but I think that the right place to fix this up would be alloc_hugetlb_folio_nodemask(), so we can place the numa_node_id() if preferred_nid = NUMA_NO_NODE in there as a safety net. This way we catch this before exploding in case the user was not careful enough. I will cook up a patch shortly. Another thing is why memfd_alloc_folio uses GFP_USER instead of GFP_HIGHUSER, but that maybe because I see that memfd_pin_folios() is used by some DMA driver which might not have access to HIGH_MEMORY. diff --git a/mm/memfd.c b/mm/memfd.c index 8035c6325e3c..2692f0298adc 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -68,12 +68,13 @@ static void memfd_tag_pins(struct xa_state *xas) struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) { #ifdef CONFIG_HUGETLB_PAGE + int nid = numa_node_id(); struct folio *folio; int err; if (is_file_hugepages(memfd)) { folio = alloc_hugetlb_folio_nodemask(hstate_file(memfd), - NUMA_NO_NODE, + nid, NULL, GFP_USER, false); > > > -- > Oscar Salvador > SUSE Labs > -- Oscar Salvador SUSE Labs