From patchwork Tue Nov 12 17:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872733 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 2E3BFD42BBA for ; Tue, 12 Nov 2024 17:56:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A40116B0102; Tue, 12 Nov 2024 12:56:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F12C6B0103; Tue, 12 Nov 2024 12:56:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81B7E6B0105; Tue, 12 Nov 2024 12:56:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 58EBC6B0102 for ; Tue, 12 Nov 2024 12:56:42 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 104C1A0395 for ; Tue, 12 Nov 2024 17:56:42 +0000 (UTC) X-FDA: 82778196480.27.47D6207 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf28.hostedemail.com (Postfix) with ESMTP id 7E057C000D for ; Tue, 12 Nov 2024 17:55:57 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ySOdZJoM; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.181) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434026; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=f/zk511lAvWJc9DDqLFXDlls0KrGnQ6iorjj31bM1x8=; b=fUKQIc0GnWnjepgqKqn248akohWVTVZ35BFzI4viAvZWnBW1L3FjgaSLXIZNXiwW9se8sq PlQ5iLLvxvXasA42kw0iI4FJE0Lu12fiVT0upfKzqx/Vx+3bdAby26MQFt1BYKXk9wJiZi 6FcU3I3NBk94KH8BIml5zz2mNoCPnDc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ySOdZJoM; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.181) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434026; a=rsa-sha256; cv=none; b=WoAuxsOQreDHVu4yiy596o49TkFtnpap459EH+6j9IsG8F15WxEpZh1N/gTAGg915q063C SZQ5DADzgAfGWk5gSq2f/pZnyuQVCWFpEFH43c7u1/FDuN9VDZc8Y463NfOB5lOITeUgr+ YIu9++fhiDjoBvuTWz0NDJbFtO9NVqE= Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-6e5cec98cceso46848727b3.2 for ; Tue, 12 Nov 2024 09:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434199; x=1732038999; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=f/zk511lAvWJc9DDqLFXDlls0KrGnQ6iorjj31bM1x8=; b=ySOdZJoMjXWhObSUJ47f2jAl/0XAQr39uEcsb/zkumyFw+xwOKIVCcZ+z7XnQaZ1DN WOG6eBu1v/VQ2hoz2wrnD3hNPLdLJ6lP9u72kZapgrIqu4kYDvvRD75Cqogq5zQT5PSs ImlYYpPNGo+8Mtyj6midqyNi0s3RzpUb8+WbRyFWhDGQUHUynmEcRnKQdmEc+uLLR25t TkJlAGijSXdiAKCnZ+l/AlnuT2Pn8uncbypAs+flmYWseHVNgjJkAWPYBe0j8yiQo1xm EEoFNAD5eaGOqsM27aRTtUYITH5DGNo5Bp5pUEfS6Me/5Q2onxdtuiJEkMde560la5EO cZFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434199; x=1732038999; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f/zk511lAvWJc9DDqLFXDlls0KrGnQ6iorjj31bM1x8=; b=iPgJnStRx6nSfwKaHNSCUeJLsafqgA+NPBf4bfWU7eJKHCi5YbiLr7L5e4hik6NRJ9 g6uWp0WL71ezH3gUWSc/DXpfbQ5mo8kDV9AB4wosjw/mh8r1ZgepPjVlFAFCuCwoL0iJ 8KlNyFTJGp8nbMADM0qRLvBXUc0RAAZjEHIVsB4I4RiqS7gJCwv5q+7NP2S09uqqaTq3 g1jViA+onYfffrjoPDrnrqVpDPc1KuAEoqftY4AbanBciZ9uYqDeN2xPNHaUVDR9edPa g616u4BVxLiYOE/opdKdryGEghJHWbELxkPeXh5TLl5Y/PWCZg1G/pwt+S7Q1f9qPlOy ZvVQ== X-Forwarded-Encrypted: i=1; AJvYcCWelD+v6xuAyB9tfifgxQdpRiIRjyl0N+8EHYtO/fCdOVH1B/iCj/KHNydqYu/GGV+nt7Zl1tKP0Q==@kvack.org X-Gm-Message-State: AOJu0YwEh/VL0q5tS88eYrkYO+rocFn3JjUFuvbtJW3RN/jvyG/FDauu 5/KNik2tJhLV8IAo1XN+sYpyXFcyVqYPoBEvm6f56yjA3x+G0o59iwvtrxHZrTo= X-Google-Smtp-Source: AGHT+IF3UHQJ040IIKGHttfPGwPkHcoNpKCF3umoPrbhTPK8Z7j1Ql7aKyWKk9X3oelY5giKEXNyJQ== X-Received: by 2002:a05:690c:314:b0:6e5:bca9:cb8f with SMTP id 00721157ae682-6eaddfa3b62mr164950927b3.38.1731434199260; Tue, 12 Nov 2024 09:56:39 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8d5133sm26365837b3.12.2024.11.12.09.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:38 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 07/18] fsnotify: generate pre-content permission event on open Date: Tue, 12 Nov 2024 12:55:22 -0500 Message-ID: <60a2309da948dc81e4c66b9e5fe3f1e2faa2010e.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7E057C000D X-Stat-Signature: t7t77zi6655wra5m4wyzh3zu94t5fgns X-Rspam-User: X-HE-Tag: 1731434157-288606 X-HE-Meta: U2FsdGVkX18oFGITe8FfHeVLPDt4W8QWWI+vULxMssvrTv56brc1x31QAYXCikgAZF4Kpji1vFuDwC1Xyv1/jypzmlUsCqkTTMRW0g4pM9d+zGCFZxhMOcvYgiF7D2EOzv2dKpuF/RBU24470nyUpoHkm6z1MYcGYabHz7PMHa1VdqCgg+k/Kbxwn7gqhAqaLLzkaoOJH8ZePPvkwQ92fZ5+XsKgafLbUyxJU6cEyumxd4IT68Nvq0xYcAZ5PH/yR2AG+x2JZr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-Bogosity: Ham, tests=bogofilter, spamicity=0.000564, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Generate pre-content event on open in addition to FS_OPEN_PERM, but without sb_writers held and after file was truncated in case file was opened with O_CREAT and/or O_TRUNC. The event will have a range info of [0..0] to provide an opportunity to fill entire file content on open. Signed-off-by: Amir Goldstein --- fs/namei.c | 10 +++++++++- include/linux/fsnotify.h | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 9d30c7aa9aa6..a1a5b10893f6 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3836,7 +3836,15 @@ static int do_open(struct nameidata *nd, } if (do_truncate) mnt_drop_write(nd->path.mnt); - return error; + if (error) + return error; + + /* + * This permission hook is different than fsnotify_open_perm() hook. + * This is a pre-content hook that is called without sb_writers held + * and after the file was truncated. + */ + return fsnotify_file_area_perm(file, MAY_OPEN, &file->f_pos, 0); } /** diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 7110bc2f5aa7..2d1c13df112c 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -193,6 +193,8 @@ static inline int fsnotify_pre_content(const struct file *file, /* * fsnotify_file_area_perm - permission hook before access of file range + * + * Called post open with access range [0..0]. */ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, const loff_t *ppos, size_t count) @@ -207,7 +209,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, /* * read()/write and other types of access generate pre-content events. */ - if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS)) { + if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS | MAY_OPEN)) { int ret = fsnotify_pre_content(file, ppos, count); if (ret)