From patchwork Wed Jul 12 01:27:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13309502 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 E40E0EB64DD for ; Wed, 12 Jul 2023 01:27:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 765E76B0071; Tue, 11 Jul 2023 21:27:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 716376B0072; Tue, 11 Jul 2023 21:27:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62C406B0075; Tue, 11 Jul 2023 21:27:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 523B06B0071 for ; Tue, 11 Jul 2023 21:27:22 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 21378140415 for ; Wed, 12 Jul 2023 01:27:22 +0000 (UTC) X-FDA: 81001221924.18.9614B20 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf14.hostedemail.com (Postfix) with ESMTP id 5C160100017 for ; Wed, 12 Jul 2023 01:27:20 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=EZl5Paqi; spf=pass (imf14.hostedemail.com: domain of hughd@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689125240; a=rsa-sha256; cv=none; b=LLYuKpTDYk0WlKtDsJMeki634tQuIbn5AdzJmeR2vqtcEM0xYbdWCX4K/BVPrt7A3uof8V TedtR8IXbkoLrnj6+Byv1MGqIfrTVf5xKGbqgWhYwcJo5+PQYmzMTJygYmeEy123VL3s98 8VmboKDmVjqoBkg49kNeswszPKgQndE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=EZl5Paqi; spf=pass (imf14.hostedemail.com: domain of hughd@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689125240; 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:in-reply-to: references:dkim-signature; bh=W3VURGA9KkY7yQ9bvu7bWVg+pvqDf+VYMl7RgWF9KGc=; b=xxe7ogqJoEUA3ZNPvcTJ1nBIHQkmZdB7mou6gOQFmKg4VroOqubLcq7OC7MS3FqcD60aZU 57o9Y9a6uO4aaUctNPjVVOOxdnbZlJkzkQTUrnvABonVchjfuFCqev5bWL+CI5aRXqJj8g PKsU2Vcjt/FxirLmEU9LzPN1Oh9aOmI= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-57045429f76so72044017b3.0 for ; Tue, 11 Jul 2023 18:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689125239; x=1691717239; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=W3VURGA9KkY7yQ9bvu7bWVg+pvqDf+VYMl7RgWF9KGc=; b=EZl5PaqiU0Ni1ubh4OmeVIuaKMkTuonNnVm/amx4/t0NpnxSe8NOkC8JVXXQSSIlS1 qWTnyEywPa1ijdl+lbKPp3ulNCeTzTSIoz65mdUoP3hIArF/tnVp9cDHTEsWfCszcHXu Q1p3rI1WJffxshF2KYU4xXK1xa4Kmm4P+gDcp8siX4tEe1klL07CYnRWcguoRyyEM8D3 3lhmxOak0qXRre7gotdpgov9QUR2FLlDLu9UI2ikdcs9K5TUQRMvos1xa4D1oUAGp+zV 4FGGG/IPThTF0i7ARjiC8eaB/tQRjOtlidKVh/8FvrquEHBIK+WeKSj63MmNelatiqH/ MlGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689125239; x=1691717239; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=W3VURGA9KkY7yQ9bvu7bWVg+pvqDf+VYMl7RgWF9KGc=; b=GkDyLUKk7nxqzS3Oq0NQJHSQ0l7P8f6VH7r0zTPP9O9t5KeExzICFFR+9A7Y7QZDsG OJ+F6JT+BeqZIC9oarzhPvT75EyiLNi2iaVMgBGa/om0fIve+4pE+GLhxAlASAcsPOdy 3TTJbQBIe5ld7zOylnuHBuq2SwQgqXpwJZXKvRGUwx9zTUpNfSjBUTvTpLExZfTQholK MgJBK7v95z2njkbsWE6PbNcNUWK8sDfM1bbJdVNgRBBdyigKpY8qkLuLVmaZH4wcFAAI fAq2iCGidXBlvcx5DhVeml6wQWrPnUWGznFHStpkhb3R5tRRv+BtUCcCaKkze9IC355u KL+Q== X-Gm-Message-State: ABy/qLYlH8ZZJezYAHGXTFTLe7rVhhtdFtX41VHQu/M3icSdDIjsBGIE CJB2GUnaUmKuDa8Yq2005OrJHA== X-Google-Smtp-Source: APBJJlGSb2kYvbvr/IaDAaPfyAo47fs5o0/d0B8BdxmIGDxGyZ5XZtX1rbPeuQeIVJe+sI2S8wX4WA== X-Received: by 2002:a81:a104:0:b0:57a:8de8:58d9 with SMTP id y4-20020a81a104000000b0057a8de858d9mr5546560ywg.33.1689125239397; Tue, 11 Jul 2023 18:27:19 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id q6-20020a0dce06000000b0055a881abfc3sm904633ywd.135.2023.07.11.18.27.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 18:27:18 -0700 (PDT) Date: Tue, 11 Jul 2023 18:27:17 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Dan Carpenter , Hugh Dickins , Axel Rasmussen , Peter Xu , linux-mm@kvack.org Subject: [PATCH mm-unstable fix] mm: userfaultfd: add new UFFDIO_POISON ioctl: fix Message-ID: MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5C160100017 X-Stat-Signature: 99nohx7xynzfry7odbaiyraj5wijw9bq X-Rspam-User: X-HE-Tag: 1689125240-512397 X-HE-Meta: U2FsdGVkX1+7iUeAxq0EPZ3xZM7JDesNsQsGHwVWQw/pqpN9qi21Q2I44J0NAUZwZ8yiJBqYz1VwPrZrKf3jznWbH9yWy0NZkCKDPacUiT3zYWGgRDktyfS9aJQp+GnIcr4cMLOB0WiRHv7kNHtGVEiYF9WTCOzvv9GwXifhO0FJlBPDKkJ+aU4Z3F6//qJsHsSoMzEPCEE8t8admb/0oo2w1dosEdstiyAxSbTi+MnkdOZn2LxzYlsGLF6DynuGj0FdPe5vimX04gyexB6gKvF16MoBXWlALn8TxxQ5A4PIw4Ze/UXm2tAqUXPAkENzd7ZDjfqEb0e7b7TLUQQaEcDsN68Wa+HAcMqCTyusSlxfJ2tiVgCanA81xUIlWoFzIB72WkR41YdgWA+xm8UW5k1H3S56Qg7ZLBCTjB37rzarz8wu/40FSc/SkR+ERt2l7uUe2v5MUDX1sTVxlG5enVLL7Ux9LXzHyZoCJYtWSxd/8J/cCNC+t5chx/bBHHa4OrWN6pKbTl2tQvazSUxIzLaGaTkT+XRRHhoNRlomk7ZL7Yt8RD0OmFHuzNM3bsvSvDNdoZe4EH0CzUzA6Se9uLPNVn51MgwoqaQn186bmxaLB61HMDbdKHjQUXbt0SHNkgLQnhFC5OLdRKvs6iq3ehf1gAJ/Dz34JUi58xu1CauEnq2s3LJUpJ6PDKOHa49+rkufMhCFwuCXZcBKYDo4XtU1GLYnBcDAEzVFCfs48lWMZB3AcFluJTl92e1QevLft0qW2lBPzR59FVYki/ygn3o1S850oVG/qu+7HuAxIcAFRvEL/U9v5PiLSFwKedfr8jVUuVccKXg+u5eowSic+yd67twdfd0yln6bOvVyhilcymUM36NpFkewvci9dBTuAvwbvXspuu5kLdGIPUd8EXV8U1YLUKAWQTBEjT/0gOUfGJWgO7JW66gz4MjsCjUsBXUl/PKc5HA2+nh+w8n KM/w6peI ppcsJSHbG283peBLsqpkRNdA5Hcl6cxwE0WhQhY5OQuBvIHSact1VY15QUCPcM7JmGpN40QRychKQVxMEMhZtxajdNgbmF7U6DXCAcEHPJUOuF30v5qsHRXYks2iy8uRc/wIZJDU+6MpXH2edYbJCM+XpF6FVJzko051gRuSgnSXdFa+dxgfL1LL31/+LhUmxcQjeJacEh23U7IYg7+mQtMwWIjLzB693bEItKXjXByB+WMoTpLr9iEujNr2yaCFvhkUoYoxKps28RkJszoQtgbD9KesjcJk5PToLf5EWPRQkqX1vcxQt5dbvTPSSGdde+6kE4BTcEIXqpTxSmIzp8nMomb2NHlK31shvtYgrPtzuM5/SOjkd8TA5Bv546yM6tJc3LL85BRNYiARXgsmUcJXTH8WVlbqw7bvoOdgIqkHAIMQ= 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: Smatch has observed that pte_offset_map_lock() is now allowed to fail, and then ptl should not be unlocked. Use -EAGAIN here like elsewhere. Signed-off-by: Hugh Dickins Reviewed-by: Axel Rasmussen --- Axel, Peter: this seems right as a fix to the patch in mm-unstable; but in preparing this, I noticed mfill_atomic()'s code before calling mfill_atomic_pte(), and think that my original choice of -EFAULT was therefore better than -EAGAIN for all of these; and that mfill_atomic()'s BUG_ONs there would be better deleted (and is its BUG_ON(folio) safe??). Something one of us should address, after this fixup is in akpm's tree. mm/userfaultfd.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -300,7 +300,10 @@ static int mfill_atomic_pte_poison(pmd_t *dst_pmd, spinlock_t *ptl; _dst_pte = make_pte_marker(PTE_MARKER_POISONED); + ret = -EAGAIN; dst_pte = pte_offset_map_lock(dst_mm, dst_pmd, dst_addr, &ptl); + if (!dst_pte) + goto out; if (mfill_file_over_size(dst_vma, dst_addr)) { ret = -EFAULT; @@ -319,6 +322,7 @@ static int mfill_atomic_pte_poison(pmd_t *dst_pmd, ret = 0; out_unlock: pte_unmap_unlock(dst_pte, ptl); +out: return ret; }