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 230E3D68BC8 for ; Fri, 15 Nov 2024 16:00:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8594D6B00B7; Fri, 15 Nov 2024 11:00:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 807926B00B8; Fri, 15 Nov 2024 11:00:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A7336B00B9; Fri, 15 Nov 2024 11:00:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4A09A6B00B7 for ; Fri, 15 Nov 2024 11:00:11 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ED148ABE95 for ; Fri, 15 Nov 2024 16:00:10 +0000 (UTC) X-FDA: 82788787830.20.12E4CC7 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by imf05.hostedemail.com (Postfix) with ESMTP id ECCA2100011 for ; Fri, 15 Nov 2024 15:58:42 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=alu4SfUz; spf=pass (imf05.hostedemail.com: domain of amir73il@gmail.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=amir73il@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731686232; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mQTg092nV/nli9mWafZup54AbTt4EJwVfug160hVSro=; b=tvYBydo4RZrqO5MFSm12E7Gzc1zruzmsaWTN4d4pWTYHjcOQ27rPVJgsJO58yJihnC5B6W J13vozNhSiyFY6pG6FSH+YOYxxeT4iJU+KmGZ7HwIbrbFNX9IKqCOfV7aN1DCmCYMqhg7q GKKBpuchjQFhzxrPIyeB8+eksaRvHuc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=alu4SfUz; spf=pass (imf05.hostedemail.com: domain of amir73il@gmail.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=amir73il@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731686232; a=rsa-sha256; cv=none; b=8a1LRrmES8fshXX26mgoH3EI/gUZn+ll7xI6p3dr8WSxerNX+WVscwOVae5x58yW7l7p75 8yq3fzWhV0vloMT01xYsd1XpJlTDeQrKwl5sm18PeXdLUWlcGqBO2Cv/5VJRdpqktEyXZZ FuPwykxKyxQauKz24igmn9whrGflSEw= Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5ceb03aadb1so1153922a12.0 for ; Fri, 15 Nov 2024 08:00:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731686407; x=1732291207; darn=kvack.org; 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=mQTg092nV/nli9mWafZup54AbTt4EJwVfug160hVSro=; b=alu4SfUzyPU0qFZC3UD7mHK1PjegYeebJ/ouTvenTgNaRm6qrfDdqS0DvujRPRhIFy q9sP3S/y8FhSh9eFu6tQGUua+4jq6YbRx3Tn83+2J6x/y50zho3oiLE5ewBtjbLaqFZX T1HDuY5Jv4p5VskQTw6HJkaucoSYTSGlCoBZ002+FC5viUWpzofZlgdCDAzrEDbngDcx VApTdqsXmUpK2baYEGsBjnD3JQUcASEw3w9kNTH0uoeRMvuTKohW075Jkf6uEhKmvbf6 c6SyGLLa3fKI5fY/bOJr1t3QWnJsAyw0kIg1E46mQQ1AVfxgqYstYuk/LXIkhX+juo2L xAOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731686407; x=1732291207; 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=mQTg092nV/nli9mWafZup54AbTt4EJwVfug160hVSro=; b=w2jUZAMb72mRQS5TB3qD6M8jrhHDATp2TrVZy/zii9tv7jrZiy5tzwlU49ZyySpcyT PKtTA1ef0rIZdomvViRlbxK01tDV6XdgfZdLJLeNa526EnFyuWiiLxFWIxmGLsSNw9QJ 7xgWHIEREoPNW2ZRFp5VjqHaLDib2XAv7k946Fv5gJsWxFfP54HYiND99PYqfnV/EbIT YBcKFBNXl59uiaULrq/r/yDNqLCJRmVmoCNPyhQG9v8Penh4op76lTWkUNgxXc9yOolV GcF8PSVbnxbVFCDJ3XKJ+C6zlPi+yJdTeGmxSGNb1d4mkuExmmFBPaGONo9MhItY+XFZ 0ymQ== X-Forwarded-Encrypted: i=1; AJvYcCXHnGqngauaQvB0cPWZCuICwmSY1cBBK6vhdH9AQ+E6RxPc3giyFxdOU9DhZwyG0dDMTjMGOLNntw==@kvack.org X-Gm-Message-State: AOJu0Yw8ujAdibAwfMT5bWmlHTNyHLuu4PFh0kXi8Jli0xjCALMk0IYM YkJAutef2UQ4DtwMbCBHraTjrHiOOGpXw7y38456E02jSQ3uKLLs41+3lPtTHec3vzfSRAkQFDC hnra2nJsoHnUyZPHadGtBPe75JcQ= X-Google-Smtp-Source: AGHT+IFkc9XByZYF5KJMTd1KEIU44FpOQRgPj6OoU3IacaF+bG0JSx+iOQAZKu2HAAEQm873FjTeMetbhlknnkMZr0w= X-Received: by 2002:a17:907:6eaa:b0:a9a:1bb4:800c with SMTP id a640c23a62f3a-aa4833e9eb8mr266512266b.4.1731686406476; Fri, 15 Nov 2024 08:00:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amir Goldstein Date: Fri, 15 Nov 2024 16:59:55 +0100 Message-ID: Subject: Re: [PATCH v8 10/19] fanotify: introduce FAN_PRE_ACCESS permission event To: Josef Bacik Cc: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, brauner@kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: ECCA2100011 X-Stat-Signature: 9z8tygzon6gj1k4e7zgueeqqbqnpqdie X-Rspam-User: X-HE-Tag: 1731686322-188498 X-HE-Meta: U2FsdGVkX19r2bbX7pj9cudpds6/WdSVoWiRMElMeo5A54lzZYxmBAv6yHkEfKOsueh1iPihp6u75iPDHfw/l2TeK2mV5sdRvGbw6Vn12cVrIhqwqHyOR3YjVfvUIVLG0DYt/kCj4qIttOuAGYuahGVYAm6h2QwKfQwYXypPDZOY5Mf/C+r641n0cKRd7bhhQu8ATUcHP7QYS7UhlaP1/uu0kATsT74Z9/yrVqiznJO2NLvgxZH1mQA9pCsIjUrVgCBYk1AREUt7Y0omWXLTjhWBSo+XJUuOhEfbNsDZ9PZY5BZAY6XSCgvchGDL5zHhIjUWpNUJX7tY6dXB36O7i5wwVGXggKdYCfsQmz/VdVLCaeGEvSZpPfhNbClb2lQwobuoNgoNAoRrfTGWTV19hNoeNrS8H2FgX3GDBMJNLEnQ5YRehRUyHQIvHvdOmbZjzk8yXw6L5s868vGeo7GJhQ3BojIgyz562eNfjSetoXXpGLDUim1HY2Cd27CsqAvPQRbyNQ9VK+Tt0LOCqctFKWQHW56HYWL3NLNLsne7zdXgDA1t+Dxk7q662TCz6zUSCUIlRmqG489sBJoFKSTdPPWmaasf/ba2116KYDftWe2d+yGdpbxE7K9+CpaUOlhVy14W3aPubzMSOKi/OfGEPhkY/aXJbj2sMilxLTM/ebfpu41pH0X6s16bd0cAN5IygebvmIyNH2BuKEtisjMttZl4iYvZr28kG1mR3GJNlJ8ByNzukDRoRQdCuf8XAznKh/64TOZklvBYDQakyppSkR4uq+9nKF8YLOthj0lRxoSwHfn8j/myxDcWtnYqn52kZYbdaSU0ObKP87rr68OkL7Vp4XjLtFOTUO6GvS89xVGrYbA+P+1Yv1GDvtiXSaU4+5gTPr5gM3Hnw9Fzf6/ezSxd/NK1HGYa1bxBMMDLDduIqpY5XXiI5VIlu62c2M6SNuZ4QuC1jTD37l6ZkWm 5rYZbi9K WlnurqrIqrvYcelCMdxYr+K/KTg/VPJ3WTVIfZioJ9sPNSevyLSXzJPjEEWCbA6/iZStsx16yRcs2EepIB5OLTCCX0Tj0FjuLrNrWUsdPzqvbCUPPZsylMaOOGEy8gH26Eg3tp8447XsrN0lwQGaRRBYKuQNyVhY1/kv+oFl4VRpxLVRbX9btrroZOinTFvLkUvy73WNd8dqz3cNafH9IgsUSxIrVqJFOcPX/MsenVBTI3kDlxdefs6FhgZJrnzrr+gTJ5VIGJBXBDelH3U9Al8ZrZDl1AkRQE6tv9rUa2QQXC6ySUO/Jwao96iRMQYlL/eJCW6vkRc2SO36BCGbOcPf8+NkaOvOsVbMIdfuFWhzXDY4yrVhxJ8R/H3hoHJPojjf3QyQTGsIV7y3GRMS/2M2ZffZ/CsdX4KW6AVCCw0KPugl7nMREabaGqd8L46Tka0My X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Nov 15, 2024 at 4:31=E2=80=AFPM Josef Bacik = wrote: > > From: Amir Goldstein > > Similar to FAN_ACCESS_PERM permission event, but it is only allowed with > class FAN_CLASS_PRE_CONTENT and only allowed on regular files and dirs. > > Unlike FAN_ACCESS_PERM, it is safe to write to the file being accessed > in the context of the event handler. > > This pre-content event is meant to be used by hierarchical storage > managers that want to fill the content of files on first read access. > > Signed-off-by: Amir Goldstein > --- > fs/notify/fanotify/fanotify.c | 3 ++- > fs/notify/fanotify/fanotify_user.c | 22 +++++++++++++++++++--- > include/linux/fanotify.h | 14 ++++++++++---- > include/uapi/linux/fanotify.h | 2 ++ > 4 files changed, 33 insertions(+), 8 deletions(-) > > diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.= c > index 2e6ba94ec405..da6c3c1c7edf 100644 > --- a/fs/notify/fanotify/fanotify.c > +++ b/fs/notify/fanotify/fanotify.c > @@ -916,8 +916,9 @@ static int fanotify_handle_event(struct fsnotify_grou= p *group, u32 mask, > BUILD_BUG_ON(FAN_OPEN_EXEC_PERM !=3D FS_OPEN_EXEC_PERM); > BUILD_BUG_ON(FAN_FS_ERROR !=3D FS_ERROR); > BUILD_BUG_ON(FAN_RENAME !=3D FS_RENAME); > + BUILD_BUG_ON(FAN_PRE_ACCESS !=3D FS_PRE_ACCESS); > > - BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) !=3D 21); > + BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) !=3D 22); > > mask =3D fanotify_group_event_mask(group, iter_info, &match_mask, > mask, data, data_type, dir); > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fano= tify_user.c > index 456cc3e92c88..5ea447e9e5a8 100644 > --- a/fs/notify/fanotify/fanotify_user.c > +++ b/fs/notify/fanotify/fanotify_user.c > @@ -1640,11 +1640,23 @@ static int fanotify_events_supported(struct fsnot= ify_group *group, > unsigned int flags) > { > unsigned int mark_type =3D flags & FANOTIFY_MARK_TYPE_BITS; > + bool is_dir =3D d_is_dir(path->dentry); > /* Strict validation of events in non-dir inode mask with v5.17+ = APIs */ > bool strict_dir_events =3D FAN_GROUP_FLAG(group, FAN_REPORT_TARGE= T_FID) || > (mask & FAN_RENAME) || > (flags & FAN_MARK_IGNORE); > > + /* > + * Filesystems need to opt-into pre-content evnets (a.k.a HSM) > + * and they are only supported on regular files and directories. > + */ > + if (mask & FANOTIFY_PRE_CONTENT_EVENTS) { > + if (!(path->mnt->mnt_sb->s_iflags & SB_I_ALLOW_HSM)) > + return -EINVAL; You missed my latest push of this change. no worries, for final version want: return -EOPNOTSUPP; > + if (!is_dir && !d_is_reg(path->dentry)) > + return -EINVAL; > + } > + > /* > * Some filesystems such as 'proc' acquire unusual locks when ope= ning > * files. For them fanotify permission events have high chances o= f > @@ -1677,7 +1689,7 @@ static int fanotify_events_supported(struct fsnotif= y_group *group, > * but because we always allowed it, error only when using new AP= Is. > */ > if (strict_dir_events && mark_type =3D=3D FAN_MARK_INODE && > - !d_is_dir(path->dentry) && (mask & FANOTIFY_DIRONLY_EVENT_BIT= S)) > + !is_dir && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) > return -ENOTDIR; > > return 0; > @@ -1778,10 +1790,14 @@ static int do_fanotify_mark(int fanotify_fd, unsi= gned int flags, __u64 mask, > return -EPERM; > > /* > - * Permission events require minimum priority FAN_CLASS_CONTENT. > + * Permission events are not allowed for FAN_CLASS_NOTIF. > + * Pre-content permission events are not allowed for FAN_CLASS_CO= NTENT. > */ > if (mask & FANOTIFY_PERM_EVENTS && > - group->priority < FSNOTIFY_PRIO_CONTENT) > + group->priority =3D=3D FSNOTIFY_PRIO_NORMAL) > + return -EINVAL; > + else if (mask & FANOTIFY_PRE_CONTENT_EVENTS && > + group->priority =3D=3D FSNOTIFY_PRIO_CONTENT) > return -EINVAL; > > if (mask & FAN_FS_ERROR && > diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h > index 89ff45bd6f01..c747af064d2c 100644 > --- a/include/linux/fanotify.h > +++ b/include/linux/fanotify.h > @@ -89,6 +89,16 @@ > #define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE | \ > FAN_RENAME) > > +/* Content events can be used to inspect file content */ > +#define FANOTIFY_CONTENT_PERM_EVENTS (FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM= | \ > + FAN_ACCESS_PERM) > +/* Pre-content events can be used to fill file content */ > +#define FANOTIFY_PRE_CONTENT_EVENTS (FAN_PRE_ACCESS) > + > +/* Events that require a permission response from user */ > +#define FANOTIFY_PERM_EVENTS (FANOTIFY_CONTENT_PERM_EVENTS | \ > + FANOTIFY_PRE_CONTENT_EVENTS) > + > /* Events that can be reported with event->fd */ > #define FANOTIFY_FD_EVENTS (FANOTIFY_PATH_EVENTS | FANOTIFY_PERM_EVENTS) > > @@ -104,10 +114,6 @@ > FANOTIFY_INODE_EVENTS | \ > FANOTIFY_ERROR_EVENTS) > > -/* Events that require a permission response from user */ > -#define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM | \ > - FAN_OPEN_EXEC_PERM) > - > /* Extra flags that may be reported with event or control handling of ev= ents */ > #define FANOTIFY_EVENT_FLAGS (FAN_EVENT_ON_CHILD | FAN_ONDIR) > > diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.= h > index 79072b6894f2..7596168c80eb 100644 > --- a/include/uapi/linux/fanotify.h > +++ b/include/uapi/linux/fanotify.h > @@ -27,6 +27,8 @@ > #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm= check */ > /* #define FAN_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) = */ > > +#define FAN_PRE_ACCESS 0x00100000 /* Pre-content access hoo= k */ > + > #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child ev= ents */ > > #define FAN_RENAME 0x10000000 /* File was renamed */ > -- > 2.43.0 >