From patchwork Mon Nov 11 20:17:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13871224 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 CA0B1D3ABF4 for ; Mon, 11 Nov 2024 20:19:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5ABB88D0002; Mon, 11 Nov 2024 15:19:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BF088D0001; Mon, 11 Nov 2024 15:19:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3119A8D0002; Mon, 11 Nov 2024 15:19:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0A0978D0001 for ; Mon, 11 Nov 2024 15:19:21 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B26061C7960 for ; Mon, 11 Nov 2024 20:19:20 +0000 (UTC) X-FDA: 82774926066.20.07DAD95 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by imf15.hostedemail.com (Postfix) with ESMTP id 3A4C7A0005 for ; Mon, 11 Nov 2024 20:18:37 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=QjGBJA2I; spf=none (imf15.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.174) 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=1731356127; 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=Gc+ksxaIwBOBmlko1WTmjrx90HfK/kHGON+QNx8apDo=; b=FmZ24W4YWmx9fEe0mSWs5Mr7bKdHhPROUtg3yn2/zfYnnKC+jYJsRUaPuXyiNXLgyj4miT MkQQhNFQAikbvpGx1aQyLZVWwIHyX+zTiRq1zYYHtbetsgeHtwzpnikp7Ila/S2es8dizu 795RECSAVK3w3X2hV6L4CgOLHAslHpM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=QjGBJA2I; spf=none (imf15.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.174) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731356127; a=rsa-sha256; cv=none; b=fFA1Bvh/hqY9MXjvDt+ZRXqzEkdTNSo4ea+T/qlCCAyS2cXEylZTDroRFLc0cq+CoOsdP6 ewmTxIhCibgwtsjMe/74AR6vMxhfXA7EKFKlk26aMqsbgIPtyHiUzA9NnOeZymh2uwEDMI Bh4p4R5HAtI3DTuT5rb/V3NZ0+8XxfQ= Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-460a415633fso34513571cf.2 for ; Mon, 11 Nov 2024 12:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731356358; x=1731961158; 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=Gc+ksxaIwBOBmlko1WTmjrx90HfK/kHGON+QNx8apDo=; b=QjGBJA2Imyh8GE+i/wwozhTyID5rDg8uPO2k+cDZHp8Ou4tO5t8JdYr+6tpnFyKwEC cWExKBC9lLXoMTdmcwg7ilV0v+drwLScVYZvJHnKz6sD29JPyjh9av8ruA1FpbI34Z/N 47zRFamZTjg8qiy+4ZGL2AfaTmj+3TtH2shZfMpkV84nbx7NcjPFKhNE/VWPwqxEMC6z gMIoZpee/yL275Yy9vxO4Jtj8588y2HQLWnL7w34OIL66tLfdLy4bnZk+xkwOADyIZ0G 3nyppJFiyVmosTB+naxHZM0BSxmmZrbNLaUu3aa/CO0Sex25zd/5Rn2j2eizZmaKB6oX jUiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731356358; x=1731961158; 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=Gc+ksxaIwBOBmlko1WTmjrx90HfK/kHGON+QNx8apDo=; b=lkjnhVBL5KmfCo5wiYlvquH4DhZV9w4C6U+ovADmCbPvA/gLCn/uzmuY0y7Zw+TSk8 xIjwiDLt00km7pdgsJwMQ5/+LNnqI5MfmyEZZ8scMOu62QZCyWTf8bcncugH2D3Bh03J ZOSwCA5zTdSslCK5UyQVfm8U+jwUZWWej8wlahRLlLoUIgBvORaTYDqDQs7Y+DH5vUYw gUssNSIewLirkQ7MwRTvA9MZmJFcZEdtCZk0nlyMWXXWMIxxaDt920p5ED0hdSvyk5ba AWowsBSDbBH1o+89hnOVjzNvS3bavJ7aPHKcCaEi3yPGQvTy2aJhFea6kwOsASoSw/fB Q2iA== X-Forwarded-Encrypted: i=1; AJvYcCXlEpJrPhhYH3Pxjmqk1hpmELZVbXW/53dgCwEcvV3nO615tLYnEGRY6MevHW2Vxdbq2l5Q6fHp0A==@kvack.org X-Gm-Message-State: AOJu0YzCQxZrkkwHc+m1YVFXNRuLxgJH6ZU7E2BJvwAXkBNfQCLEcpU9 jKkOAyzWouZX24oE4D0GVmnLSAwf3BleWbEfr8DYgBSpHydJPzY4Sxno1SFAKGU= X-Google-Smtp-Source: AGHT+IHqngnO/59yGfndmsDZIAVzuHVhRF3bKyXBU2iniiGLSmmnpck59CK/mpALqfBlBcxTed5EdA== X-Received: by 2002:a05:622a:4d:b0:460:c5b2:58b7 with SMTP id d75a77b69052e-4630942cc70mr178650181cf.51.1731356358100; Mon, 11 Nov 2024 12:19:18 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff5e2385sm66402261cf.88.2024.11.11.12.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:19:17 -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 v6 06/17] fsnotify: generate pre-content permission event on open Date: Mon, 11 Nov 2024 15:17:55 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3A4C7A0005 X-Stat-Signature: e811mcaa374rnqfndd5411mp34tojfsn X-Rspam-User: X-HE-Tag: 1731356317-865576 X-HE-Meta: U2FsdGVkX1+spEJq5QueWvrsl0p08T6Q1nGYmFskQlSSop0nWyAZGtxBadUXDWjfu80/ziPbB/2xv73BAx413QXLtxbZfWzvS6TgjjFdS+Jam92H7XQB+RmIh8jl3Qozk+P1nEBmSmJpAvrUvA3qlqNMPUcCTPy5P8G19eqSX+G5EcM4EtWCBm/0JEdYkAQq978rPTwXZcn9hdAviW99sTfLvO08pUMaOTQDZ5HMcLx+8mr8+FwQP5D1opthoMdUMtKaIS3W3uWtfyJWtUtmZObjAXhazVCKlxJlsLZCOthkodhOEuBu/nz6Iy4gRAbrwxuaoFN0haMXlzevhR8xQ3iJzLMQ4LH/KOgvGz1zXyiuHsoVKt9tyLe7pBhLxcyhwepei18iZaexvGo9GjBFsqtCfWwZNkyBrPrYjmd8rdwreyPwcgqNT3gickJgIQ601lXQUAyajLERBZ7oxWakSO13DSp1n5KPIenCz19Hp8aFNUKbWo7C57W2g/f5h1fc7eObRarCroEA8897IRpFrs7l7+rI7sHZv+ip5VqNeHhk07s3k4U2AmOQDvgifEC+qtaL9su2EXR588pM0IFwYVHyG5wVZ7thWzD1v53omgqi7SFpfsP/4IUo+t+hXiuEJZTII9O9to52DHRG/e8Zgnut0wBLDA/ekBfxiDlb7sTo87MeAF+ysXcBytXIGa8zWG80NGIYKvD7awpt4pxP71eLyNHKOGSOduEjTPtp/W44wRFzTt1lrU4AbnBsWkvW42hH7MAlNfdJcULNc3lYvMQC0R4Bj6jTCcfcaYZ3LVMHBsFmsdBB4NLIBDHuHBmz+MfkAAUQMKz0XWMNmGSd+oC/H4JnYDaGQhASU+UQFv0OYxFLDl9AHY9V8S+oeNtQIl1TZ5FlyO4X+Je+Ns1N3YuFng9zFp+zfVhd7LqM3S3dvcqYXp86C5BaXiW4xdQ1FnRLufp5m0OPrOrCNvF dLcY+3RO q2r5MPElZChxAGp2hI0IZILH07I046TzOmsM3I+hTW289tGhiYUfcPEpqNWcxRnAk3aKcuEdkBYXB8zYPgKny0bvLrqygHSr8bSzKyTqVzMiGruOfN8zGgBbJ5Es+Zx9a2+kdII7Sgx10q4WhntHy81imFnmBaUSt+A2z3bG24KTyM+rTACHtWU2JArKfeBjQeePtR9CRR1DDwnxED2dSW6zABRKAcSUQtgbyEbszss/iq6ZGWiFJDUzvAW0QzW8kp5Hl6YXpvM6rEanTMCxfOLdbleRi976jbLl1BVTdrRgfaZRyd8IicdPC4QNyz0X9x3UCv5ZbGkaVSYssMsuxlQ9/rQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, 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 4a4a22a08ac2..b49fb1f80c0c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3782,7 +3782,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 22150e5797c5..1e87a54b88b6 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -171,6 +171,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) @@ -185,7 +187,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)