From patchwork Fri Jun 28 00:26:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 13715208 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF3B43224 for ; Fri, 28 Jun 2024 00:26:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719534392; cv=none; b=VbTHAcTOYN0hEGl26EcGkMEjAgWMoqWA9i6CWcAZcMlToJj0b5ARm8NEe/O0B51MlLteoonG0JYpOUvsDtaxP8T1DS9F+GZqwrK+BWps9rAREilgymYmCe6awzKkjNpF0M1qhJXazU0xZybpaVBJSF2vZ1Fgn2ySqqs04hW7C3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719534392; c=relaxed/simple; bh=hh11G/iodh5iWE0DKtFfqmVHr22By8Ulh9rirP+ZYcQ=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=incQVo4kqmen2sv7ODKS/vb7zvWW3CCKD5RZawLa7mbGr3j1UVnAB9cLeSNXCYvlHExA18i4DGie0nNiM0OuGemq/LD/lEEjzNiATLPyOkp4yxqRhswHr8Jc0ID8ZVYIKQ6VPcrau2mEVm4DVdBKTZ4WXKmIx8AtDSKaYCOjEi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iSr7furU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iSr7furU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719534389; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F920R5yaBE3PsuRdteKVNVN6MSLZBpfM90SMj8g8nmA=; b=iSr7furUaS2gJqXitvUGAqK8ZXk5LCqEEk3UqgvZ+GjgZWfHImtWq0yNawvCs+jX1btpvZ q/iQ+R0BcMySoLmlsLaB/6kcgus0H3O02SMYpHA1AH6zgC4CVWqqL+qVlDMibjgyoG2o4p gEWzccliw+Gb4Cg6hhoIQvKd9tzzwmA= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-01FArMrGOXSuqUHq8DVqrA-1; Thu, 27 Jun 2024 20:26:26 -0400 X-MC-Unique: 01FArMrGOXSuqUHq8DVqrA-1 Received: by mail-io1-f71.google.com with SMTP id ca18e2360f4ac-7e1fe2ba2e1so2902639f.3 for ; Thu, 27 Jun 2024 17:26:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719534386; x=1720139186; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=F920R5yaBE3PsuRdteKVNVN6MSLZBpfM90SMj8g8nmA=; b=FBThTmNctWC0dm4dxKfeDTNRn601s5RLOlbXqI4jNgatdfqN8lQnxuQmfkxMQBddgy Dm+4yq7hjxqw6l5xqnsGuexluF6xpRh+mzHjmZVHzDGTS5duu87tqwlvnoV0Zn3eWkdR +fWgYRcNaHEYKZlKlB0uRFfW+/3XUC0Jec0Gvt65ZvYTGOGHtCiIL7t/6UI7NIIgeg0r CwT5dJAQ1uIkGketPjpjWAqhcv9ri4Xe23g9TqbdmHmik5fSHNsrkUiN1QLluGvnD1uc EU+8KG9XyGzpD+pfg79l3Asq44p3cGXF4O1JbgrMQ1d0/uk30GVdDnEirTQVqTuKyyOA MVSQ== X-Forwarded-Encrypted: i=1; AJvYcCW3X33/u+tc9luMMeg4USF66zqlJjTz3VSMFRu9IQkAFwGSFRX3lE5G3Iz18Emle2lFkDoqVjJsU4N0F4zupOgNhkAUiGwk/SU1HOYzu4IFy6C9 X-Gm-Message-State: AOJu0YzgABr66PYstjk3rfOZPXrlSrLVBnV/V/buB+g71L/jaWOFKQXn SJbsM3HiQ1NjNcmhlixUvTMktHnCe5XZnK/jcOPiGLvX9gqHnUNi+ZgCT9gZL7OfEcPywFQaus9 3I/Oqp9o/Fu7f/Dgh2LY9PC1mZ7AcKVC2yIDpkhAevt5yXHGQCuLYkW953sTp5sPIglFWVQ== X-Received: by 2002:a6b:730e:0:b0:7f3:d863:3cf8 with SMTP id ca18e2360f4ac-7f3d8634018mr415331339f.4.1719534385816; Thu, 27 Jun 2024 17:26:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLQ+evTqW23iP2xMhQPr9hw69BKkkeaSh3vRZVLP5nIJpjBkoHrAggDlvkHwnRujUOQkyNmA== X-Received: by 2002:a6b:730e:0:b0:7f3:d863:3cf8 with SMTP id ca18e2360f4ac-7f3d8634018mr415329439f.4.1719534385516; Thu, 27 Jun 2024 17:26:25 -0700 (PDT) Received: from [10.0.0.71] (sandeen.net. [63.231.237.45]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4bb73dd541dsm219330173.55.2024.06.27.17.26.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Jun 2024 17:26:25 -0700 (PDT) Message-ID: Date: Thu, 27 Jun 2024 19:26:24 -0500 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 01/14] fs_parse: add uid & gid option option parsing helpers From: Eric Sandeen To: linux-fsdevel@vger.kernel.org, Christian Brauner Cc: autofs@vger.kernel.org, "Rafael J. Wysocki" , linux-efi@vger.kernel.org, Namjae Jeon , linux-ext4@vger.kernel.org, Miklos Szeredi , linux-mm@kvack.org, Jan Kara , ntfs3@lists.linux.dev, linux-cifs@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Hans Caniullan References: <8dca3c11-99f4-446d-a291-35c50ed2dc14@redhat.com> In-Reply-To: <8dca3c11-99f4-446d-a291-35c50ed2dc14@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Multiple filesystems take uid and gid as options, and the code to create the ID from an integer and validate it is standard boilerplate that can be moved into common helper functions, so do that for consistency and less cut&paste. This also helps avoid the buggy pattern noted by Seth Jenkins at https://lore.kernel.org/lkml/CALxfFW4BXhEwxR0Q5LSkg-8Vb4r2MONKCcUCVioehXQKr35eHg@mail.gmail.com/ because uid/gid parsing will fail before any assignment in most filesystems. Signed-off-by: Eric Sandeen --- Documentation/filesystems/mount_api.rst | 9 +++++-- fs/fs_parser.c | 34 +++++++++++++++++++++++++ include/linux/fs_parser.h | 6 ++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Documentation/filesystems/mount_api.rst b/Documentation/filesystems/mount_api.rst index 9aaf6ef75eb5..317934c9e8fc 100644 --- a/Documentation/filesystems/mount_api.rst +++ b/Documentation/filesystems/mount_api.rst @@ -645,6 +645,8 @@ The members are as follows: fs_param_is_blockdev Blockdev path * Needs lookup fs_param_is_path Path * Needs lookup fs_param_is_fd File descriptor result->int_32 + fs_param_is_uid User ID (u32) result->uid + fs_param_is_gid Group ID (u32) result->gid ======================= ======================= ===================== Note that if the value is of fs_param_is_bool type, fs_parse() will try @@ -678,6 +680,8 @@ The members are as follows: fsparam_bdev() fs_param_is_blockdev fsparam_path() fs_param_is_path fsparam_fd() fs_param_is_fd + fsparam_uid() fs_param_is_uid + fsparam_gid() fs_param_is_gid ======================= =============================================== all of which take two arguments, name string and option number - for @@ -784,8 +788,9 @@ process the parameters it is given. option number (which it returns). If successful, and if the parameter type indicates the result is a - boolean, integer or enum type, the value is converted by this function and - the result stored in result->{boolean,int_32,uint_32,uint_64}. + boolean, integer, enum, uid, or gid type, the value is converted by this + function and the result stored in + result->{boolean,int_32,uint_32,uint_64,uid,gid}. If a match isn't initially made, the key is prefixed with "no" and no value is present then an attempt will be made to look up the key with the diff --git a/fs/fs_parser.c b/fs/fs_parser.c index a4d6ca0b8971..24727ec34e5a 100644 --- a/fs/fs_parser.c +++ b/fs/fs_parser.c @@ -308,6 +308,40 @@ int fs_param_is_fd(struct p_log *log, const struct fs_parameter_spec *p, } EXPORT_SYMBOL(fs_param_is_fd); +int fs_param_is_uid(struct p_log *log, const struct fs_parameter_spec *p, + struct fs_parameter *param, struct fs_parse_result *result) +{ + kuid_t uid; + + if (fs_param_is_u32(log, p, param, result) != 0) + return fs_param_bad_value(log, param); + + uid = make_kuid(current_user_ns(), result->uint_32); + if (!uid_valid(uid)) + return inval_plog(log, "Invalid uid '%s'", param->string); + + result->uid = uid; + return 0; +} +EXPORT_SYMBOL(fs_param_is_uid); + +int fs_param_is_gid(struct p_log *log, const struct fs_parameter_spec *p, + struct fs_parameter *param, struct fs_parse_result *result) +{ + kgid_t gid; + + if (fs_param_is_u32(log, p, param, result) != 0) + return fs_param_bad_value(log, param); + + gid = make_kgid(current_user_ns(), result->uint_32); + if (!gid_valid(gid)) + return inval_plog(log, "Invalid gid '%s'", param->string); + + result->gid = gid; + return 0; +} +EXPORT_SYMBOL(fs_param_is_gid); + int fs_param_is_blockdev(struct p_log *log, const struct fs_parameter_spec *p, struct fs_parameter *param, struct fs_parse_result *result) { diff --git a/include/linux/fs_parser.h b/include/linux/fs_parser.h index d3350979115f..6cf713a7e6c6 100644 --- a/include/linux/fs_parser.h +++ b/include/linux/fs_parser.h @@ -28,7 +28,7 @@ typedef int fs_param_type(struct p_log *, */ fs_param_type fs_param_is_bool, fs_param_is_u32, fs_param_is_s32, fs_param_is_u64, fs_param_is_enum, fs_param_is_string, fs_param_is_blob, fs_param_is_blockdev, - fs_param_is_path, fs_param_is_fd; + fs_param_is_path, fs_param_is_fd, fs_param_is_uid, fs_param_is_gid; /* * Specification of the type of value a parameter wants. @@ -57,6 +57,8 @@ struct fs_parse_result { int int_32; /* For spec_s32/spec_enum */ unsigned int uint_32; /* For spec_u32{,_octal,_hex}/spec_enum */ u64 uint_64; /* For spec_u64 */ + kuid_t uid; + kgid_t gid; }; }; @@ -131,6 +133,8 @@ static inline bool fs_validate_description(const char *name, #define fsparam_bdev(NAME, OPT) __fsparam(fs_param_is_blockdev, NAME, OPT, 0, NULL) #define fsparam_path(NAME, OPT) __fsparam(fs_param_is_path, NAME, OPT, 0, NULL) #define fsparam_fd(NAME, OPT) __fsparam(fs_param_is_fd, NAME, OPT, 0, NULL) +#define fsparam_uid(NAME, OPT) __fsparam(fs_param_is_uid, NAME, OPT, 0, NULL) +#define fsparam_gid(NAME, OPT) __fsparam(fs_param_is_gid, NAME, OPT, 0, NULL) /* String parameter that allows empty argument */ #define fsparam_string_empty(NAME, OPT) \ From patchwork Fri Jun 28 00:40:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 13715335 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D1664687 for ; Fri, 28 Jun 2024 00:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719535249; cv=none; b=ROUULHn37dGOhAST1L/qzrELZG87Eo+x8xlwYUZnWCvh4NhptHJOyabf7wXCsXfHtHYMkm+USsLhNJKEm26e2LinifNXlyNzDLYxu6YRvn7LK7hDUTaGKSRjoY8D6YvfHnLrhK+qVjvtzwOtqVkb4kH0DVxtgxomv6/MEXNDsAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719535249; c=relaxed/simple; bh=Xv8gun3l3UQeFDGlNKxjbcBxzvE7uW/YCpmcLt2vJf4=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=FnGUy29N2XZYBXBrGDOboWr7BxZlYphtxaQSBaYOC6yzvNXzLujoASpvJDPfHaXGzGGi1mQTHcfey5raLpUjE5m9Y4MnInoXsuYeGk3Vogscgvxs7AHPWGktmhDqrGcVfEzeAMrA1ytWWT08nJWA/Torg7wNMJBf1OK2TUhbiZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FisaPZHb; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FisaPZHb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719535247; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0Unk1vGLR1Be3cNBuySBujecQ1IeVxttlaXhutd1cek=; b=FisaPZHbP09EdRhZsv003O3rvExgad1VXMS63QLaXlyh+kWBLauA4er41NI8vfAJiz6gW/ 2H2D6WV4k3xTizYMinPFrrUkZhD+TxniWVqo9rOVkrWToj3gGebtN4RImH4pPMdIpADD8B +8DtHTiw3/B5vK71wa0pioVlC8AilT8= Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-270-XXQvMnZLPSuCgEfhAsekdA-1; Thu, 27 Jun 2024 20:40:46 -0400 X-MC-Unique: XXQvMnZLPSuCgEfhAsekdA-1 Received: by mail-il1-f199.google.com with SMTP id e9e14a558f8ab-3765604de70so1268025ab.1 for ; Thu, 27 Jun 2024 17:40:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719535245; x=1720140045; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0Unk1vGLR1Be3cNBuySBujecQ1IeVxttlaXhutd1cek=; b=KPQyqeDlSco05Y48MX9E2+KznENTYXgqY/OBdTNKYCQC50SsVRAFzz9D1BmHqBqf1j pedMwABQ0oL7a0f8OqCLGeqy2W9RklifvxFM99k2m+tq9PDifDZ0oexL7v4OFi5vpknw dSb1dXDIMTIHTUysnPhrwCgrCHZ7mK5GPs0lABDxHxffZ1HSTSMZ2ft50rTv48UmG3fI 8AGIzpIUTnN90NrPi0vKP3yhILgZJF4KKmijubGJjk0uOX30htD5VPr4+MDeklk68CNO cwoEP7+YT5R4lj+sDo9MaCyKxV127OOccUz0fn9X3Ni1MgneQvlaq7QUhtHy8gV0wYhw 4XLQ== X-Gm-Message-State: AOJu0YwbckDCQ7VzNWblWTKO2T7sXVWxzNf0T7F7Bqk9lZfowOAXmxww kT0VkhDApm1tDFMgnFNKGeIRu2PpegAVSLyTw0xZzEYpWBf722lCGsnc7a++qKWsL0t8/dcgLCH Rya+H43WvauShkZdtpY0/qKi9sdU9KizCeIUCl2TKRM3c4ftZPLfgc7hZs6ho/a7cpyrdYWFol3 fqCA== X-Received: by 2002:a92:c56a:0:b0:375:b381:9acb with SMTP id e9e14a558f8ab-3763b34fe73mr188912105ab.30.1719535245142; Thu, 27 Jun 2024 17:40:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFh9UG4ASP/yXk4fz3eeE0HY6mTqWEdaPkoaUz2MCu4nPDeuH3H/jqqW6WuJ5Q6wUHkbfa/OQ== X-Received: by 2002:a92:c56a:0:b0:375:b381:9acb with SMTP id e9e14a558f8ab-3763b34fe73mr188911955ab.30.1719535244811; Thu, 27 Jun 2024 17:40:44 -0700 (PDT) Received: from [10.0.0.71] (sandeen.net. [63.231.237.45]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-37ad2f41329sm1773545ab.50.2024.06.27.17.40.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Jun 2024 17:40:44 -0700 (PDT) Message-ID: <6c9b0b16-e61b-4dfc-852d-e2eb5bb11b82@redhat.com> Date: Thu, 27 Jun 2024 19:40:44 -0500 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 13/14] tracefs: Convert to new uid/gid option parsing helpers From: Eric Sandeen To: linux-fsdevel@vger.kernel.org, Christian Brauner Cc: linux-trace-kernel@vger.kernel.org References: <8dca3c11-99f4-446d-a291-35c50ed2dc14@redhat.com> In-Reply-To: <8dca3c11-99f4-446d-a291-35c50ed2dc14@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Convert to new uid/gid option parsing helpers Signed-off-by: Eric Sandeen Acked-by: Steven Rostedt (Google) --- fs/tracefs/inode.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 7c29f4afc23d..1028ab6d9a74 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -296,9 +296,9 @@ enum { }; static const struct fs_parameter_spec tracefs_param_specs[] = { - fsparam_u32 ("gid", Opt_gid), + fsparam_gid ("gid", Opt_gid), fsparam_u32oct ("mode", Opt_mode), - fsparam_u32 ("uid", Opt_uid), + fsparam_uid ("uid", Opt_uid), {} }; @@ -306,8 +306,6 @@ static int tracefs_parse_param(struct fs_context *fc, struct fs_parameter *param { struct tracefs_fs_info *opts = fc->s_fs_info; struct fs_parse_result result; - kuid_t uid; - kgid_t gid; int opt; opt = fs_parse(fc, tracefs_param_specs, param, &result); @@ -316,16 +314,10 @@ static int tracefs_parse_param(struct fs_context *fc, struct fs_parameter *param switch (opt) { case Opt_uid: - uid = make_kuid(current_user_ns(), result.uint_32); - if (!uid_valid(uid)) - return invalf(fc, "Unknown uid"); - opts->uid = uid; + opts->uid = result.uid; break; case Opt_gid: - gid = make_kgid(current_user_ns(), result.uint_32); - if (!gid_valid(gid)) - return invalf(fc, "Unknown gid"); - opts->gid = gid; + opts->gid = result.gid; break; case Opt_mode: opts->mode = result.uint_32 & S_IALLUGO;