From patchwork Sun Nov 29 00:45:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 11938879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC779C63777 for ; Sun, 29 Nov 2020 00:49:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5641620731 for ; Sun, 29 Nov 2020 00:49:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B6+nMYKw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5641620731 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E46E06B005D; Sat, 28 Nov 2020 19:49:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DAA986B0068; Sat, 28 Nov 2020 19:49:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C25F06B006C; Sat, 28 Nov 2020 19:49:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 9CAF06B005D for ; Sat, 28 Nov 2020 19:49:57 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6A2A9180AD82F for ; Sun, 29 Nov 2020 00:49:57 +0000 (UTC) X-FDA: 77535623634.02.death24_60082a627395 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 5311410097AA0 for ; Sun, 29 Nov 2020 00:49:57 +0000 (UTC) X-HE-Tag: death24_60082a627395 X-Filterd-Recvd-Size: 4468 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Sun, 29 Nov 2020 00:49:56 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id q10so7773837pfn.0 for ; Sat, 28 Nov 2020 16:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l/Z8FKlQx4uPsR2N2TmU0wX19nThj5BIa2agvJuzNHs=; b=B6+nMYKwKJ4hMGar1ZDhLuHnwmrkqzZ1MImfumwqd2HseKfQ5iE6w4aXKmat5EOLN2 ZgtFyypw79nA5lB+2B7b3FOLsq214EIQ73rgnlo7Bm+w8+aOagMI36mmeu0c/OEo6umq WKJmEokmFR3+kgrNkiPI9mVwklCmL7CBFt0cX2L6ltEtkbzs0y3hEwQTLyTuuC3f2xMl TvhSoE7YajZWGu40VmH3ezKqZCIE5TqIo1ZMpNsE0UaLl4QNx24hhOd1VmfCsILiADwN 8ZRzzuKUD8EDfBacEoKs2dzJzuKkklRM7htDJlz3hxhXr5UAV2iw78MokJXHycR3+0cS aoyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l/Z8FKlQx4uPsR2N2TmU0wX19nThj5BIa2agvJuzNHs=; b=j0Trqz4B2ZgESVVNh6uJdxrupCdiTzhIQJvLgnkrJU2J1bcVjrVPyuQcDnKeiYIqeO ywbOYnDmzucjYoRj+Z+SEPhL7+2ZWWvQHdxjM4nDwnpEFST7dEraXxlpUgU++xnEH6bu 7ByHBKsLI9vltLZ5jbTa+S0xs3IUkYBvmTgpyoPKzZ2sC4QfAyL6Eq0t4xQRhctJY2Uh KHMrxKtqs7rR2/mDCJR9R69t5lhrHBXGSQHyYPQJm34d+quZv4eY2ECEUr7Uz9P9Til0 cfFLrW0jgsr+F1wTe//Aa0IRM27UpYlWhqJfLmsOSu8F1y68ZVBlNVXs8YzLhJ2Jy408 YH+A== X-Gm-Message-State: AOAM5335dCy+1c3q1FdKxLEOPtIVp0CGeiwKB0cbYmjxJDKR7sbQOl5h gvjm48tL8fQnDwAD+patw+0= X-Google-Smtp-Source: ABdhPJywBaA7WF3l1QVlZ/0iev6HcvYcWxP1cEM+D4hAm7IrnJMAcUdTAhr+98nM4pSoy1jJk5U9Nw== X-Received: by 2002:aa7:9501:0:b029:155:3b11:d5c4 with SMTP id b1-20020aa795010000b02901553b11d5c4mr12958529pfp.76.1606610995913; Sat, 28 Nov 2020 16:49:55 -0800 (PST) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id gg19sm16444871pjb.21.2020.11.28.16.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2020 16:49:55 -0800 (PST) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-fsdevel@vger.kernel.org Cc: Nadav Amit , Mike Kravetz , Jens Axboe , Andrea Arcangeli , Peter Xu , Alexander Viro , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 01/13] fs/userfaultfd: fix wrong error code on WP & !VM_MAYWRITE Date: Sat, 28 Nov 2020 16:45:36 -0800 Message-Id: <20201129004548.1619714-2-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201129004548.1619714-1-namit@vmware.com> References: <20201129004548.1619714-1-namit@vmware.com> MIME-Version: 1.0 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: From: Nadav Amit It is possible to get an EINVAL error instead of EPERM if the following test vm_flags have VM_UFFD_WP but do not have VM_MAYWRITE, as "ret" is overwritten since commit cab350afcbc9 ("userfaultfd: hugetlbfs: allow registration of ranges containing huge pages"). Fix it. Cc: Mike Kravetz Cc: Jens Axboe Cc: Andrea Arcangeli Cc: Peter Xu Cc: Alexander Viro Cc: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Fixes: cab350afcbc9 ("userfaultfd: hugetlbfs: allow registration of ranges containing huge pages") Signed-off-by: Nadav Amit Reviewed-by: Mike Kravetz --- fs/userfaultfd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 000b457ad087..c8ed4320370e 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1364,6 +1364,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, if (end & (vma_hpagesize - 1)) goto out_unlock; } + ret = -EPERM; if ((vm_flags & VM_UFFD_WP) && !(cur->vm_flags & VM_MAYWRITE)) goto out_unlock;