From patchwork Thu Nov 16 20:15:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13458260 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 275FFC54E76 for ; Thu, 16 Nov 2023 20:15:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BDEB6B046F; Thu, 16 Nov 2023 15:15:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 53E706B0498; Thu, 16 Nov 2023 15:15:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36E6A6B0499; Thu, 16 Nov 2023 15:15:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 21CF76B046F for ; Thu, 16 Nov 2023 15:15:58 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E931A805D2 for ; Thu, 16 Nov 2023 20:15:57 +0000 (UTC) X-FDA: 81464923554.18.7C3EEAE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id D6C7480013 for ; Thu, 16 Nov 2023 20:15:55 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ii1Az5lL; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700165755; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rVI0G/o2WVlv6Ps9x/muR3n3l0/Wk8HAmms0O3t+e7A=; b=o6c+8mywdGqYXVdgsJZ8Ah+L1OTTHXRCbHVToSqZBAepP+Ly58EFcLZ7Xd2RI51Z9oVZ6y mx+zBtLDHDFFVD02LVPeVhveelBJQt9JdoWqscPimIb//CfE+NuiLa9Xgry6KfW4165vlo NfV6SW0wqw3zVWCFhIpUUJxijvWPCwg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ii1Az5lL; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700165755; a=rsa-sha256; cv=none; b=5Bk7jSlgFs5TCmdJ7gTDWgls1pslMde6n2C9ToqUY1UZIMzpMh8whHA7mv88TMSPhozjwE VFcTbdp0g+U8SBhXninMjMHE0N76gvlyYLKNNwUoLdXJv0GOIL0j7Hnam1tj+ftM3ltxMW MtxUYX41U9YqRKKeJ0O/H1BYrq/bA18= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700165755; 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: in-reply-to:in-reply-to:references:references; bh=rVI0G/o2WVlv6Ps9x/muR3n3l0/Wk8HAmms0O3t+e7A=; b=Ii1Az5lLM9J0xj4EDONOSftcBEZmqlUUMC8HAoJenvRFx7YW3P3KwetaBhH5sPhKFaCrPQ IfikXw5QiuzOEJ65SrMX/2N4lbMnSwxyKteJoF5de/Aw3+FFNZ/0vTxA+i754lEPfIlZtA NFCqBxC7bz+RLpwleFDFSc4L59OAVP4= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-UTbe9GIPNviGZ-gLQCjNSA-1; Thu, 16 Nov 2023 15:15:54 -0500 X-MC-Unique: UTbe9GIPNviGZ-gLQCjNSA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-77a02ceef95so18075985a.0 for ; Thu, 16 Nov 2023 12:15:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700165753; x=1700770553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rVI0G/o2WVlv6Ps9x/muR3n3l0/Wk8HAmms0O3t+e7A=; b=qTlzMlEdQ7Cu12KMSAug/9OcLkBR/qt7PdnpPUN+tOzaxDBxJv1mDoC1ePlkzf1mUK 0ha0iU5IciOUBwwDhPqPgUwIFNOeCFV4LnR5aSsi16NgsaLIOOi5zgV4bZ4s0TVQhkqw H2xJdnm91LUjjAuuA4pW/O/4Dg/l29vDpAMWgLvCdyyjAVy3DjQSIx5lPbp1DI9I1ODM WCRjySBg+ixXlHg9hygEDZj238LoToGr7AQJzF6nZJ8CseYmx5bRxEMV6zh2BWjzuyd5 sk34r7HT9HHW3xYASy57IhBX2UtSVJ6w+helyArex2t3D32sB95TMwjqA8M/zXnDo3ha nx1A== X-Gm-Message-State: AOJu0Yzmpqi5tdKnavkFOlL8FmCV03SA6ZwCZ1UM1+bEl4sRJh6DnxFF 2cKRvZMRzqQuHNb8nyrlR8iNZ8u+8YIU1EDxIyMVg0iNxryulOUQxaycWuhSsxvECXXTVRU7CGk VOSMTUFKY21//F8Snv6qhZTrpY4dLh0s6F4IEMsct+YtyCKIfE5X0Xf9KCy4DqMka8EoY X-Received: by 2002:a05:620a:bd3:b0:772:5300:1c3d with SMTP id s19-20020a05620a0bd300b0077253001c3dmr9471547qki.0.1700165753286; Thu, 16 Nov 2023 12:15:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6NhVg5ATijtU5gZAjIsSdXlgC1Wv7DJob8yOxfAJNeWszVXZfkcVZW+Oo0riZTR5pk+BEJA== X-Received: by 2002:a05:620a:bd3:b0:772:5300:1c3d with SMTP id s19-20020a05620a0bd300b0077253001c3dmr9471523qki.0.1700165752989; Thu, 16 Nov 2023 12:15:52 -0800 (PST) Received: from x1n.redhat.com (cpe688f2e2cb7c3-cm688f2e2cb7c0.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id b19-20020a05620a271300b007659935ce64sm65524qkp.71.2023.11.16.12.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 12:15:52 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Muhammad Usama Anjum , Andrew Morton , David Hildenbrand , Andrei Vagin , syzbot+7ca4b2719dc742b8d0a4@syzkaller.appspotmail.com Subject: [PATCH 2/3] mm/pagemap: Fix wr-protect even if PM_SCAN_WP_MATCHING not set Date: Thu, 16 Nov 2023 15:15:46 -0500 Message-ID: <20231116201547.536857-3-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231116201547.536857-1-peterx@redhat.com> References: <20231116201547.536857-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D6C7480013 X-Stat-Signature: b4hum3mng13dgqtxy8obghekrq6ba7ce X-HE-Tag: 1700165755-252475 X-HE-Meta: U2FsdGVkX18Fpa6QyfU2VcOUWFG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NjN8VjdkoszTTN0CAjoDZ0OiY1RUTf3jBftumpa4O1MCKpGqHGHsHlQuZFhyrwoFaqTmekGiYEVvQukRYrhzRS5Pmo7/tvURnamk4ZLrHyNyqiW3eDzvlqx0nlYCZ4Gq1MmXSsLqQzltLeuhCcbwMGZK4N4IzNkc1E+rEGvyyPHiQV7fqpIBLPhJVhvcYCYC8IVQyY0dKUDfqRuYmtGs9MSbBmA9La2twbXV+Hl3xSnPCjI59D+XzZTQzbT9E/yE+HYW6kgsY1UioNsVnQUYBhw08hRKepY+j9ltpAOawGZL7gP5/ZVesqGBcHALwQbTX7gL5y5ZoS05p0l8oin/mQP34Fs919mdgsnYB5nw8OtDIWrZE95IW7valcGtFdlH/SPz21WM+BaMsWoPXiiaxwtlp5RYnU651rB7i1l/vSGduphn9hrXssrmT8V09+jQx/5KihQjpCQIc2gijVMwvo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The new pagemap ioctl contains a fast path for wr-protections without looking into category masks. It forgets to check PM_SCAN_WP_MATCHING before applying the wr-protections. It can cause, e.g., pte markers installed on archs that do not even support uffd wr-protect. WARNING: CPU: 0 PID: 5059 at mm/memory.c:1520 zap_pte_range mm/memory.c:1520 [inline] Fixes: 12f6b01a0bcb ("fs/proc/task_mmu: add fast paths to get/clear PAGE_IS_WRITTEN flag") Reported-by: syzbot+7ca4b2719dc742b8d0a4@syzkaller.appspotmail.com Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Andrei Vagin --- fs/proc/task_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index e91085d79926..d19924bf0a39 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2171,7 +2171,7 @@ static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start, return 0; } - if (!p->vec_out) { + if ((p->arg.flags & PM_SCAN_WP_MATCHING) && !p->vec_out) { /* Fast path for performing exclusive WP */ for (addr = start; addr != end; pte++, addr += PAGE_SIZE) { if (pte_uffd_wp(ptep_get(pte)))