From patchwork Wed Apr 12 16:38:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 82593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp479440vqo; Wed, 12 Apr 2023 10:05:47 -0700 (PDT) X-Google-Smtp-Source: AKy350ZcLcZhLiGXOdj4Qwqh5AiGIjpc4Ib8CuOmXgHt10U66H5jO9C7efOXF0bwF6KqSJAsOTP/ X-Received: by 2002:a17:902:cec3:b0:1a5:2993:8aa6 with SMTP id d3-20020a170902cec300b001a529938aa6mr21373104plg.63.1681319147049; Wed, 12 Apr 2023 10:05:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681319147; cv=none; d=google.com; s=arc-20160816; b=zqWbk/20iutGfiw1OeCbbjJqdzYhpIzYwBB61y8tLokRYyikVdR0erBqVQvz/L3rz7 A07s2QEEaekBKzpp9IPYmbU3dg4uOVQvu166JNvwCS2gclL73cIQukaRU0vQ6rewO8Nw Glh3mPXUGHT3dcTQ1gUou7roFfdEnJozqohymS6xdI0EAJkoEXVNU4neBAiLWspYCVby u+oLjfUbswLKfZYOd1rH9Pg9aUYCaY/8GcnlSoKGTrfsYX+g/GGUNlpRryJZokcpYjFm QRjwx2mj8cS4XwOqFMX7Q0k6uEIPmfUbkziFEvufz8M1u/XonM8UTDIf4QbxdW6QKNkm 5UtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=09jtKKMdBkZ99/jQ3MHG3Gpu4kZKeE61xD5S9ADSCnE=; b=Rb08ed8j3Da3E/a5ixhKG/8NXCUvx7RBEjgyMfrBz6Jw1dV87LCf6B5A77BAZuQ/sA FKv4+h603AINtAZmZyQiYse3+6KtJbQzNLYoBJftVjDckwHVPygzDVX5srTZqqobk1eb jLRCxM7UtHukcjuLXYUCiHVKf+K6Fwt5oC6yulwO1OPe49u7hCM5nJwOErcdIQKkCmBq N/1gosqXeqPIG4E1097zJbLZSD2ghJiwHugIM9IkTWMz+pN5DDiD1ATytU+wiUGP6lTJ RGu9+EbY/EdwtB/EdehgueKV2MgSrKaZwPCZmKc6+W5d1mzhqU8FUBJCP5ojXbhomY6s Otvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QQL4bDt5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id km3-20020a17090327c300b0019f25dae4f5si15829995plb.198.2023.04.12.10.05.33; Wed, 12 Apr 2023 10:05:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QQL4bDt5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbjDLQmW (ORCPT + 99 others); Wed, 12 Apr 2023 12:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbjDLQmP (ORCPT ); Wed, 12 Apr 2023 12:42:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06398268B for ; Wed, 12 Apr 2023 09:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=09jtKKMdBkZ99/jQ3MHG3Gpu4kZKeE61xD5S9ADSCnE=; b=QQL4bDt5LMYcrAWuj9OeLBN47vVfL3HJybzVJlLa9Ru7R8oPNjLO30qg4TarXSvIQ2GAh+ MobKBXMajBrxEipfW09FB0GIBom6h8UnBlHtFTC0lpr+7C5Z8afSoC95BFvxFU7tTOEnHH +RD3bPjHQQVRgv57/CzIiNf2+KLw00s= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-222-vzCsdpQ7OzepawJY9Cp-HA-1; Wed, 12 Apr 2023 12:39:27 -0400 X-MC-Unique: vzCsdpQ7OzepawJY9Cp-HA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-5ef4122d2dbso1347536d6.1 for ; Wed, 12 Apr 2023 09:39:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317565; x=1683909565; 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=09jtKKMdBkZ99/jQ3MHG3Gpu4kZKeE61xD5S9ADSCnE=; b=ijjePcHlUR0deFx6fOVFQbKKoZBFQNmRoWpOZICwPua3Bbz2c5heXOgCmRQiQSkCxm Ij9/QMAc0OW3PCIeZgP7DzqYLKPVL4nPBFJbW8TVuNNH0YEA9gHvuzhwEAvZzV9IjQk0 psQ9Yaok4J2pv1DQVxtXR66Q5c2ckjfDNeVw5/Pf7x65jh/EYZNfZ+gEdD3U3Zi+Z67V s8esR22rXozSdmFO+xiwzwIw3bTXUovUW6MjTtSaCZQc2vumx0UUaPFWiR/4oP/o/K2c M7FThfF/mENFmY4ZBNLF+41t8y0bAv/hFBtWFAUUF8G8a6LcCRucJFLNUiN2fquQ1ulq T9wQ== X-Gm-Message-State: AAQBX9ckovkZejSY6CJqHbUWYlWkk+7DpY8l7+uIvU5XsiL1cDQiaA5E +m6CzlaBHVm9EaKgNYjJ5f4okDlo60AniHYKd3fy8cDRGPWTPaIBC20GRz/gXVB/e3eT6Z6rM+t Q/O2wpSsqq3qoM2NppD2cxzng X-Received: by 2002:a05:6214:401a:b0:5ea:a212:3fe1 with SMTP id kd26-20020a056214401a00b005eaa2123fe1mr4433892qvb.4.1681317565691; Wed, 12 Apr 2023 09:39:25 -0700 (PDT) X-Received: by 2002:a05:6214:401a:b0:5ea:a212:3fe1 with SMTP id kd26-20020a056214401a00b005eaa2123fe1mr4433881qvb.4.1681317565461; Wed, 12 Apr 2023 09:39:25 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id u13-20020a0cc48d000000b005ead602acfesm2669536qvi.35.2023.04.12.09.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:39:24 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Leonardo Bras Soares Passos , Andrea Arcangeli , Axel Rasmussen , Nadav Amit , Andrew Morton , Mike Rapoport , Mike Kravetz , David Hildenbrand , peterx@redhat.com, Dmitry Safonov <0x7f454c46@gmail.com>, linux-stable Subject: [PATCH v2 01/31] Revert "userfaultfd: don't fail on unrecognized features" Date: Wed, 12 Apr 2023 12:38:52 -0400 Message-Id: <20230412163922.327282-2-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990906337987517?= X-GMAIL-MSGID: =?utf-8?q?1762990906337987517?= This is a proposal to revert commit 914eedcb9ba0ff53c33808. I found this when writting a simple UFFDIO_API test to be the first unit test in this set. Two things breaks with the commit: - UFFDIO_API check was lost and missing. According to man page, the kernel should reject ioctl(UFFDIO_API) if uffdio_api.api != 0xaa. This check is needed if the api version will be extended in the future, or user app won't be able to identify which is a new kernel. - Feature flags checks were removed, which means UFFDIO_API with a feature that does not exist will also succeed. According to the man page, we should (and it makes sense) to reject ioctl(UFFDIO_API) if unknown features passed in. Link: https://lore.kernel.org/r/20220722201513.1624158-1-axelrasmussen@google.com Fixes: 914eedcb9ba0 ("userfaultfd: don't fail on unrecognized features") Cc: Axel Rasmussen Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Mike Rapoport Cc: linux-stable Acked-by: David Hildenbrand Signed-off-by: Peter Xu --- fs/userfaultfd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 8395605790f6..3b2a41c330e6 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1977,8 +1977,10 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, ret = -EFAULT; if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api))) goto out; - /* Ignore unsupported features (userspace built against newer kernel) */ - features = uffdio_api.features & UFFD_API_FEATURES; + features = uffdio_api.features; + ret = -EINVAL; + if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) + goto err_out; ret = -EPERM; if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE)) goto err_out;