From patchwork Tue Jun 29 12:35:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 12349803 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,INCLUDES_PULL_REQUEST, 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 73D3DC11F66 for ; Tue, 29 Jun 2021 12:35:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BD7D61D97 for ; Tue, 29 Jun 2021 12:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233787AbhF2MiJ (ORCPT ); Tue, 29 Jun 2021 08:38:09 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:37377 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233626AbhF2MiG (ORCPT ); Tue, 29 Jun 2021 08:38:06 -0400 Received: from ip5f5bf01b.dynamic.kabel-deutschland.de ([95.91.240.27] helo=wittgenstein.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lyCxm-0008Bi-25; Tue, 29 Jun 2021 12:35:38 +0000 From: Christian Brauner To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [GIT PULL] openat2 fixes Date: Tue, 29 Jun 2021 14:35:33 +0200 Message-Id: <20210629123533.1191246-1-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Hi Linus, /* Summary */ - Remove the unused VALID_UPGRADE_FLAGS define we carried from an extension to openat2() that we haven't merged. Aleksa might be getting back to it at some point but just not right now. - openat2() used to accidently ignore unknown flag values in the upper 32 bits. The new openat2() syscall verifies that no unknown O-flag values are set and returns an error to userspace if they are while the older open syscalls like open() and openat() simply ignore unknown flag values: #define O_FLAG_CURRENTLY_INVALID (1 << 31) struct open_how how = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID, .resolve = 0, }; /* fails */ fd = openat2(-EBADF, "/dev/null", &how, sizeof(how)); /* succeeds */ fd = openat(-EBADF, "/dev/null", O_RDONLY | O_FLAG_CURRENTLY_INVALID); However, openat2() silently truncates the upper 32 bits meaning: #define O_FLAG_CURRENTLY_INVALID_LOWER32 (1 << 31) #define O_FLAG_CURRENTLY_INVALID_UPPER32 (1 << 40) struct open_how how_lowe32 = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID_LOWER32, }; struct open_how how_upper32 = { .flags = O_RDONLY | O_FLAG_CURRENTLY_INVALID_UPPER32, }; /* fails */ fd = openat2(-EBADF, "/dev/null", &how_lower32, sizeof(how_lower32)); /* succeeds */ fd = openat2(-EBADF, "/dev/null", &how_upper32, sizeof(how_upper32)); Fix this by preventing the immediate truncation in build_open_flags() and add a compile-time check to catch when we add flags in the upper 32 bit range. /* Testing */ All patches are based on v5.13-rc3 and have been sitting in linux-next. No build failures or warnings were observed. All old and new tests are passing. /* Conflicts */ At the time of creating this PR no merge conflicts were reported from linux-next and no merge conflicts showed up doing a test-merge with current mainline. The following changes since commit c4681547bcce777daf576925a966ffa824edd09d: Linux 5.13-rc3 (2021-05-23 11:42:48 -1000) are available in the Git repository at: git@gitolite.kernel.org:pub/scm/linux/kernel/git/brauner/linux tags/fs.openat2.unknown_flags.v5.14 for you to fetch changes up to 15845cbcd12a571869c6703892427f9e5839d5fb: test: add openat2() test for invalid upper 32 bit flag value (2021-05-28 17:44:37 +0200) Please consider pulling these changes from the signed fs.openat2.unknown_flags.v5.14 tag. Thanks! Christian ---------------------------------------------------------------- fs.openat2.unknown_flags.v5.14 ---------------------------------------------------------------- Christian Brauner (3): fcntl: remove unused VALID_UPGRADE_FLAGS open: don't silently ignore unknown O-flags in openat2() test: add openat2() test for invalid upper 32 bit flag value fs/open.c | 14 +++++++++++--- include/linux/fcntl.h | 4 ---- tools/testing/selftests/openat2/openat2_test.c | 7 ++++++- 3 files changed, 17 insertions(+), 8 deletions(-)