From patchwork Sat Mar 11 06:58:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9618443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 324B660414 for ; Sat, 11 Mar 2017 07:00:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 248BC2879D for ; Sat, 11 Mar 2017 07:00:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 196C2287A8; Sat, 11 Mar 2017 07:00:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8D65287A3 for ; Sat, 11 Mar 2017 07:00:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752741AbdCKHAO (ORCPT ); Sat, 11 Mar 2017 02:00:14 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:35467 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752283AbdCKHAM (ORCPT ); Sat, 11 Mar 2017 02:00:12 -0500 Received: by mail-pg0-f68.google.com with SMTP id g2so8059616pge.2; Fri, 10 Mar 2017 23:00:11 -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; bh=PG+9dBrxatu+U9K3wS8gpsV7H41063zWLeVl4TCVCIo=; b=uukgPtb1PwvgTIRdlqxajeQR35Z3CaJovFRDvZk37O7NUZXNSoFUkiy2lFe8Z5aJe7 T1Sj8AkLrjZxXDS7AzsRCeD1IzzEtk/vk1Jrx/SmiDkJBy5/xUZJyc3UfvKTxZBcmKCf SW5q2ZDJIfcLrX1h71x8jPfmv2zLzUkcPQXWAJgy+HdOkjWdyljtjUzCxbft/PMd7ezr OU+NOEXdbrTrxGFh1km9YjCA+0qfbIfh9G5XX+xe+A+iy+qpV9RZfwGXnJaDM89++wiX sae0TzMFfQaWyVMVd/vEsd1Dk2znZjMMlm3XqmxIIEkG+uaakhfp+eWYV57KLIZDi1cD zH+g== 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; bh=PG+9dBrxatu+U9K3wS8gpsV7H41063zWLeVl4TCVCIo=; b=e3sDdStgrIK4Fu0t88vFFa5jLHd8M/hiSHQ1884ZALtn5bj5ovxp1aYxJpSixcMfHW jco4mXBAPJ6eGdG+Ib6zAmmhdt84Y+sndPjOqwhXrYuUZ54HNVO2R+NsXX7F0SdDGu1f RoO2dW9ivPIN8MR2N/3AzCtr1wOITi/7X7XrFwUSDhS/Uv9GXCmCRrVGrB7g6JpDOmIf JCmVmaoY5/nWsOS4vdpEDWiOSbpUGldBOjP/YHVMq8RE9q6+MO/HD8ahMOpizTi+IWPo WvqLacrKwA6jjOpFx88s2BymXZO2MjYwGi67G1eNy4MHD+29iMakksXGlD/sCEUIYxpX EfRg== X-Gm-Message-State: AMke39mPRTKlS6wXAMcNOxOkJTub6GSC+7/fv2oRwabEYUDcVluwzZHXrUeH0u22xb9A8w== X-Received: by 10.84.134.228 with SMTP id 91mr31536410plh.116.1489215611253; Fri, 10 Mar 2017 23:00:11 -0800 (PST) Received: from zzz.hsd1.wa.comcast.net (c-73-239-167-150.hsd1.wa.comcast.net. [73.239.167.150]) by smtp.gmail.com with ESMTPSA id w131sm22145917pfd.34.2017.03.10.23.00.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Mar 2017 23:00:10 -0800 (PST) From: Eric Biggers To: linux-fsdevel@vger.kernel.org Cc: Alexander Viro , David Howells , mtk.manpages@gmail.com, Christoph Hellwig , "Darrick J . Wong" , Linux API , linux-xfs@vger.kernel.org, Eric Biggers Subject: [PATCH] statx: reject unknown flags when using NULL path Date: Fri, 10 Mar 2017 22:58:23 -0800 Message-Id: <20170311065823.4415-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.12.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers The statx() system call currently accepts unknown flags when called with a NULL path to operate on a file descriptor. Left unchanged, this could make it hard to introduce new query flags in the future, since applications may not be able to tell whether a given flag is supported. Fix this by failing the system call with EINVAL if any flags other than KSTAT_QUERY_FLAGS are specified in combination with a NULL path. Arguably, we could still permit known lookup-related flags such as AT_SYMLINK_NOFOLLOW. However, that would be inconsistent with how sys_utimensat() behaves when passed a NULL path, which seems to be the closest precedent. And given that the NULL path case is (I believe) mainly intended to be used to implement a wrapper function like fstatx() that doesn't have a path argument, I think rejecting lookup-related flags too is probably the best choice. Signed-off-by: Eric Biggers --- fs/stat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/stat.c b/fs/stat.c index fa0be59340cc..df484a60846d 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -130,9 +130,13 @@ EXPORT_SYMBOL(vfs_getattr); int vfs_statx_fd(unsigned int fd, struct kstat *stat, u32 request_mask, unsigned int query_flags) { - struct fd f = fdget_raw(fd); + struct fd f; int error = -EBADF; + if (query_flags & ~KSTAT_QUERY_FLAGS) + return -EINVAL; + + f = fdget_raw(fd); if (f.file) { error = vfs_getattr(&f.file->f_path, stat, request_mask, query_flags);