Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1452942rwl; Fri, 31 Mar 2023 11:18:36 -0700 (PDT) X-Google-Smtp-Source: AKy350bNZoyu+Q9u94OsZRUIpjN+24RliKPY7J9dlG3eh+ZunXrohNCRgaBj2Mwj1ajqsFQsHsdO X-Received: by 2002:a17:906:7382:b0:93b:dddf:4be2 with SMTP id f2-20020a170906738200b0093bdddf4be2mr5303851ejl.3.1680286716167; Fri, 31 Mar 2023 11:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680286716; cv=none; d=google.com; s=arc-20160816; b=McdCIIlUQsX+2lQf1xWnm+iR6JBW1IQlm77wEVkNo2WB5gcq10yUnJJo5QucL1oJSR wyTRNXuWbMDU8cmr+kFj5vV0JUBiVO5nJh3nRCfVb2eh3B2hQVB2yIl1OS3943nr/eq5 HcK5NFlv3v6T0vYIBB4oPJU3fQ2W36d30T2lYGhMMAqv5Ps7ky5kKzpHsqhAqYqo98Sm LST0uzHEH06E5EWzptRrZnoDq5+QVn06D1bxsP/EY4jaAsH3vZZ81BlTU6Dn+81yN6ot lA79zrjoTOBJtY2+2f9/Ul1KJxnEsttBZFZ7ylHOpru49AUVrwSFI/Z2FRgYueU7TB5T FXyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=M3lL8ptrd/luySMEjAQve8KEssZBP6yJTIAyyXPQHgg=; b=v+P1oaYruZmq/Nv8IT5zinoywxxGGIIZcKrFzjHhDhd3FsVfWYT0QT5TAjKZpJ2HoT GXg77RQleNw8XCCQYlWeJG/feWu3Z2bFEYnEuT1IGVVVAIPG1rjWMv3dPWUbwWXnFcRG hpT9xOUam08Z2GNb+w+lihHRCrfFCPoEzgrp0NBqXNOrsMCPAFx2uSeKxGD9KOuWhgRA 7ebBJBdvE8E9lSjvo1BdFm1JvfFMzRP1Sr67ePpf4PI5W/DDydXRJPWpuhq2THj2MmWh iv6jMheyezx0IlwNW+OCL6juSw3bQwrlHCaNTnMv7lMCWrCSFqgdnnx38tdK4iWjSvIq rwNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TijtgZgJ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a05640200ce00b004fe042c5a6esi531492edu.453.2023.03.31.11.18.11; Fri, 31 Mar 2023 11:18:36 -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=@gmail.com header.s=20210112 header.b=TijtgZgJ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232633AbjCaSId (ORCPT + 99 others); Fri, 31 Mar 2023 14:08:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231609AbjCaSIc (ORCPT ); Fri, 31 Mar 2023 14:08:32 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB0C133; Fri, 31 Mar 2023 11:08:31 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id 72-20020a9d064e000000b006a2f108924cso817929otn.1; Fri, 31 Mar 2023 11:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680286111; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=M3lL8ptrd/luySMEjAQve8KEssZBP6yJTIAyyXPQHgg=; b=TijtgZgJPoSAkrcF9V9ctcDVZf1Gr7uaoWdV1AaSjm/KZE5h4sYlBoiTiAt9zc1eCT bEzo5N3F1nEvBlji5hWX5MiJWmvZ4/j1AY1gk3EaP6GT+eGUy5iA1vfl34lH6syE08ih 5m+fEYn4UId09hnyghSoIsBqnVREoKJ8cktxaK3unfkBnREtG+Tvg7W0FV9yFKoyTZ28 7RspSMLiGq/E5fUE0YWIYczKAThUMo5PGLplYoO3wc0tbyvULkxXR5Wdd8hGWdjz9Ki/ n8HzZzHwhI8BbETWOExrjzXGl+KiuUgdPOU4xcX+xg6NhdUtZvU71oUmjKhit4SAKBYP 03KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680286111; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M3lL8ptrd/luySMEjAQve8KEssZBP6yJTIAyyXPQHgg=; b=PXzEbaWzswOO8Dn7YjaWq2iMZdVDrDPvbPIju6OJGqapmdLCwk0RN4NOSmMHcTEjTu LddJgE2fFYht/vZ5Gz+s8HRQbqc1BSyHf3ddgm4WR1n2BCXrmZmow2pwwVybiLVSAfx2 kvuieix+Z8EHoa51Ba+aK25hcqqKuLWwXYfCpJ6RI4M9Y1vqRCdrkzSrddktNs/iTr2J ViCeWZKTe6KV96Pc/ZIdUGk0THvZskXLWCgOX2FKGSbmU37Ud1vBRpGrh/oUTz2yoAAL BNYRFR9Xlej0s2UXj8q2PVAiZJMoE8TRreWrJCevE1P3kSPrhHPSNUAXfLDHgjuedhv3 mN3Q== X-Gm-Message-State: AO0yUKUax8pCKXGn/pMxnumnPZXKe5S0lASIjkaZA66h0fXVWz6GUfx3 SGzdfJV3woGIwd8MEwaeLiNwra536+3ExPyTFbE= X-Received: by 2002:a05:6830:86:b0:69f:2a7b:22b9 with SMTP id a6-20020a056830008600b0069f2a7b22b9mr8992270oto.0.1680286110928; Fri, 31 Mar 2023 11:08:30 -0700 (PDT) MIME-Version: 1.0 References: <20230330155707.3106228-1-peterx@redhat.com> <20230330155707.3106228-2-peterx@redhat.com> In-Reply-To: From: Dmitry Safonov <0x7f454c46@gmail.com> Date: Fri, 31 Mar 2023 19:08:19 +0100 Message-ID: Subject: Re: [PATCH 01/29] Revert "userfaultfd: don't fail on unrecognized features" To: Axel Rasmussen Cc: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Kravetz , Andrew Morton , Andrea Arcangeli , Mike Rapoport , Nadav Amit , Leonardo Bras Soares Passos , David Hildenbrand , linux-stable Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On Fri, 31 Mar 2023 at 17:52, Axel Rasmussen wro= te: > > On Thu, Mar 30, 2023 at 3:27=E2=80=AFPM Peter Xu wrot= e: > > > > On Thu, Mar 30, 2023 at 12:04:09PM -0700, Axel Rasmussen wrote: > > > On Thu, Mar 30, 2023 at 8:57=E2=80=AFAM Peter Xu = wrote: > > > > > > > > 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 !=3D 0xa= a. 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. If features/flags are not checked in kernel, and the kernel doesn't return an error on an unknown flag/error, that makes the syscall non-extendable, meaning that adding any new feature may break existing software, which doesn't sanitize them properly. https://lwn.net/Articles/588444/ See a bunch of painful exercises from syscalls with numbers in the end: https://lwn.net/Articles/792628/ To adding an additional setsockopt() because an old one didn't have sanity checks for flags: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?= id=3D8917a777be3b (not the best example, as the new setsockopt() didn't check flags for sanity as well (sic!), but that's near the code I work on now) This is even documented nowadays: https://www.kernel.org/doc/html/latest/process/adding-syscalls.html#designi= ng-the-api-planning-for-extension ...and everyone knows what happens when you blame userspace for breaking by not doing what you would have expected it to do: https://lkml.org/lkml/2012/12/23/75 [..] > > There's one reason that we may consider keeping the behavior. IMHO it = is > > when there're major softwares that uses the "wrong" ABI (let's say so; > > because it's not following the man pages). If you're aware any such ma= jor > > softwares (especially open sourced) will break due to this revert patch= , > > please shoot. > > Well, I did find one example, criu: > https://github.com/checkpoint-restore/criu/blob/criu-dev/criu/uffd.c#L266 Mike can speak better than me about uffd, but AFAICS, CRIU correctly detect= s features with kerneldat/kdat: https://github.com/checkpoint-restore/criu/blob/criu-dev/criu/kerndat.c#L12= 35 So, doing a sane thing in kernel shouldn't break CRIU (at least here). Thanks, Dmitry