From mboxrd@z Thu Jan 1 00:00:00 1970 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 53D0EC43334 for ; Fri, 22 Jul 2022 20:15:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FD896B0072; Fri, 22 Jul 2022 16:15:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 885A26B0073; Fri, 22 Jul 2022 16:15:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 726946B0074; Fri, 22 Jul 2022 16:15:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5CEBD6B0072 for ; Fri, 22 Jul 2022 16:15:21 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2EAAAC0D93 for ; Fri, 22 Jul 2022 20:15:21 +0000 (UTC) X-FDA: 79715840442.17.37CB82C Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf09.hostedemail.com (Postfix) with ESMTP id C1A33140005 for ; Fri, 22 Jul 2022 20:15:19 +0000 (UTC) Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-31e62f7b377so46563057b3.17 for ; Fri, 22 Jul 2022 13:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=c/c766f5IweLiXfTzCwsILplI2BRgHB64Zpkrcr5r4c=; b=IVmB1KhfRC9dhpaTkpIjZ6E3f+Szh9fFdOVOyseY1NVukF8w6zwOAocHq6J1WNgOx7 MkeP7D6XmaSW+5oGvdDUL4lzrNGQs+5+3SzlU1AMRuxE8aagduAp2F/E7t9ZmgbuwpjO f306zDfgyelvBDZnfGcG8V+emseVEwfjhn1IjzDmb1pHxpuSwWN5tvBBazNN5/qG4idy 0HIiZvpiJVPJ0ZAcKaJCuS/PXvPEoLzAMUJto3JnYgY7Ng6J/iATPcYHANgx87GtHulV wiCPLmIuBvP3zKYVaBGLJd3oDLj4WIAhZAT9wtlrMeNw2yNlJnbECqep3fMPmM0ZgOif HqKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=c/c766f5IweLiXfTzCwsILplI2BRgHB64Zpkrcr5r4c=; b=H6iCnm5IjpcYRU/He9697snaIhSuMwBoFKE5m9LQ/Eok1Tle1WGx+TQ3LfDhhZ6pW1 4JOn9LqMBbdrX7ryDAirn4C97LDEJeWgS8d4RH1/J9/6Yx46yuh2v3WuLP9YOxP/0vHO 1lthK+zGCoK1JnOCnnjdsUSCT6Lmx+CTd/9NtM447bi6GHI4/7AC3TdypN2bdO/IxuDo ivjfCS0Bn1oX+yrG3xvWrYP7uSziVB3SZWVfOkrN3N6Q2XCftGoXwx31ZAKFVTzbd0VK hT0vpvGfzrnXs5FllbVLFmmg84gu9Za7tVwYd01R6lVtgBSODE3gLQ4ayAlo7zE8n1Qi WoTQ== X-Gm-Message-State: AJIora8xyYzNhgjgWgyEJASApdKTLlH4xRqMcF/BqtbIoHiS5udL2hLN XdebUE+d81e994uuAfOFv57roZeuXg6nPmQelAFl X-Google-Smtp-Source: AGRyM1uRjPK6eRsDWx956R4w3PIY9GowmVfxAwibKdWDAaVTmRSzk/CGssJt4ZsxlokH97WRezORFs8FoPg+8IAOZxDR X-Received: from ajr0.svl.corp.google.com ([2620:15c:2d4:203:1623:4cce:b896:4e2f]) (user=axelrasmussen job=sendgmr) by 2002:a25:af93:0:b0:670:7de3:6c30 with SMTP id g19-20020a25af93000000b006707de36c30mr1242861ybh.569.1658520918930; Fri, 22 Jul 2022 13:15:18 -0700 (PDT) Date: Fri, 22 Jul 2022 13:15:13 -0700 Message-Id: <20220722201513.1624158-1-axelrasmussen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.359.gd136c6c3e2-goog Subject: [PATCH] userfaultfd: don't fail on unrecognized features From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Peter Xu Cc: Axel Rasmussen , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658520919; a=rsa-sha256; cv=none; b=7d5HoJZrTz/GxwckC05BlCKRaX9fz7ihSwYJK4atOiK3yvnN/mydT0LZ7aSQRBLF7WNgfR SGE8X2y5kxJm0gb62YwBKkARW7aDIzDzRYR0Bjo2u1ZFzpObR3IPvmdwLaUJaAwYBzalrC DbCY4x0S0txD2i6k9KQEp8VIqJwheBQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=IVmB1Khf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3VgXbYg0KCOkLiPWcLdXfddPYRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--axelrasmussen.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3VgXbYg0KCOkLiPWcLdXfddPYRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--axelrasmussen.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658520919; 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=c/c766f5IweLiXfTzCwsILplI2BRgHB64Zpkrcr5r4c=; b=5y064RePReD0+U9LyylWanEhDBzvJZ1tfbXhpnYX46rFJHambetnze/1/iEYxd7n5+tNRH duK7bQ1K7Xyis0Mlw9yUQVRdyaJtouQoyNEGGK2KH9fvGUW7tV12+kJGG2JE9ZR4Z+/MRx wfeby5VDObvKvq9b73VBVIEQjGJ2iqE= X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C1A33140005 X-Stat-Signature: 8z7m37qk3gmobnaq3n7tyt6uthzk7p6i Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=IVmB1Khf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3VgXbYg0KCOkLiPWcLdXfddPYRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--axelrasmussen.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3VgXbYg0KCOkLiPWcLdXfddPYRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--axelrasmussen.bounces.google.com X-HE-Tag: 1658520919-673118 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000163, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The basic interaction for setting up a userfaultfd is, userspace issues a UFFDIO_API ioctl, and passes in a set of zero or more feature flags, indicating the features they would prefer to use. Of course, different kernels may support different sets of features (depending on kernel version, kconfig options, architecture, etc). Userspace's expectations may also not match: perhaps it was built against newer kernel headers, which defined some features the kernel it's running on doesn't support. Currently, if userspace passes in a flag we don't recognize, the initialization fails and we return -EINVAL. This isn't great, though. Userspace doesn't have an obvious way to react to this; sure, one of the features I asked for was unavailable, but which one? The only option it has is to turn off things "at random" and hope something works. Instead, modify UFFDIO_API to just ignore any unrecognized feature flags. The interaction is now that the initialization will succeed, and as always we return the *subset* of feature flags that can actually be used back to userspace. Now userspace has an obvious way to react: it checks if any flags it asked for are missing. If so, it can conclude this kernel doesn't support those, and it can either resign itself to not using them, or fail with an error on its own, or whatever else. Signed-off-by: Axel Rasmussen --- fs/userfaultfd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index e943370107d0..4974da1f620c 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1923,10 +1923,8 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, ret = -EFAULT; if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api))) goto out; - features = uffdio_api.features; - ret = -EINVAL; - if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) - goto err_out; + /* Ignore unsupported features (userspace built against newer kernel) */ + features = uffdio_api.features & UFFD_API_FEATURES; ret = -EPERM; if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE)) goto err_out; -- 2.37.1.359.gd136c6c3e2-goog