Re: [apparmor] [PATCH v2 3/8] autofs: set ctime as well when mtime changes on a dir

2023-06-13 Thread Ian Kent

On 12/6/23 18:45, Jeff Layton wrote:

When adding entries to a directory, POSIX generally requires that the
ctime also be updated alongside the mtime.

Signed-off-by: Jeff Layton 


Acked-by: Ian Kent 



---
  fs/autofs/root.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/autofs/root.c b/fs/autofs/root.c
index 6baf90b08e0e..93046c9dc461 100644
--- a/fs/autofs/root.c
+++ b/fs/autofs/root.c
@@ -600,7 +600,7 @@ static int autofs_dir_symlink(struct mnt_idmap *idmap,
p_ino = autofs_dentry_ino(dentry->d_parent);
p_ino->count++;
  
-	dir->i_mtime = current_time(dir);

+   dir->i_mtime = dir->i_ctime = current_time(dir);
  
  	return 0;

  }
@@ -633,7 +633,7 @@ static int autofs_dir_unlink(struct inode *dir, struct 
dentry *dentry)
d_inode(dentry)->i_size = 0;
clear_nlink(d_inode(dentry));
  
-	dir->i_mtime = current_time(dir);

+   dir->i_mtime = dir->i_ctime = current_time(dir);
  
  	spin_lock(>lookup_lock);

__autofs_add_expiring(dentry);
@@ -749,7 +749,7 @@ static int autofs_dir_mkdir(struct mnt_idmap *idmap,
p_ino = autofs_dentry_ino(dentry->d_parent);
p_ino->count++;
inc_nlink(dir);
-   dir->i_mtime = current_time(dir);
+   dir->i_mtime = dir->i_ctime = current_time(dir);
  
  	return 0;

  }




Re: [apparmor] [PATCH v2 8/8] cifs: update the ctime on a partial page write

2023-06-13 Thread Tom Talpey

On 6/12/2023 6:45 AM, Jeff Layton wrote:

POSIX says:

 "Upon successful completion, where nbyte is greater than 0, write()
  shall mark for update the last data modification and last file status
  change timestamps of the file..."

Add the missing ctime update.

Signed-off-by: Jeff Layton 
---
  fs/smb/client/file.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index df88b8c04d03..a00038a326cf 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -2596,7 +2596,7 @@ static int cifs_partialpagewrite(struct page *page, 
unsigned from, unsigned to)
   write_data, to - from, );
cifsFileInfo_put(open_file);
/* Does mm or vfs already set times? */
-   inode->i_atime = inode->i_mtime = current_time(inode);
+   inode->i_atime = inode->i_mtime = inode->i_ctime = 
current_time(inode);


Question. It appears that roughly half the filesystems in this series
don't touch the i_atime in this case. And the other half do. Which is
correct? Did they incorrectly set i_atime instead of i_ctime?

Tom.


if ((bytes_written > 0) && (offset))
rc = 0;
else if (bytes_written < 0)




[apparmor] [PATCH v2 5/8] efivarfs: update ctime when mtime changes on a write

2023-06-13 Thread Jeff Layton
POSIX says:

"Upon successful completion, where nbyte is greater than 0, write()
 shall mark for update the last data modification and last file status
 change timestamps of the file..."

Add the missing ctime update.

Signed-off-by: Jeff Layton 
---
 fs/efivarfs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/efivarfs/file.c b/fs/efivarfs/file.c
index d57ee15874f9..375576111dc3 100644
--- a/fs/efivarfs/file.c
+++ b/fs/efivarfs/file.c
@@ -51,7 +51,7 @@ static ssize_t efivarfs_file_write(struct file *file,
} else {
inode_lock(inode);
i_size_write(inode, datasize + sizeof(attributes));
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
inode_unlock(inode);
}
 
-- 
2.40.1




[apparmor] [PATCH v2 6/8] exfat: ensure that ctime is updated whenever the mtime is

2023-06-13 Thread Jeff Layton
When removing entries from a directory, the ctime must also be updated
alongside the mtime.

Signed-off-by: Jeff Layton 
---
 fs/exfat/namei.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index e0ff9d156f6f..d9b46fa36bff 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -817,7 +817,7 @@ static int exfat_unlink(struct inode *dir, struct dentry 
*dentry)
ei->dir.dir = DIR_DELETED;
 
inode_inc_iversion(dir);
-   dir->i_mtime = dir->i_atime = current_time(dir);
+   dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir);
exfat_truncate_atime(>i_atime);
if (IS_DIRSYNC(dir))
exfat_sync_inode(dir);
@@ -825,7 +825,7 @@ static int exfat_unlink(struct inode *dir, struct dentry 
*dentry)
mark_inode_dirty(dir);
 
clear_nlink(inode);
-   inode->i_mtime = inode->i_atime = current_time(inode);
+   inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
exfat_truncate_atime(>i_atime);
exfat_unhash_inode(inode);
exfat_d_version_set(dentry, inode_query_iversion(dir));
@@ -979,7 +979,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry 
*dentry)
ei->dir.dir = DIR_DELETED;
 
inode_inc_iversion(dir);
-   dir->i_mtime = dir->i_atime = current_time(dir);
+   dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir);
exfat_truncate_atime(>i_atime);
if (IS_DIRSYNC(dir))
exfat_sync_inode(dir);
@@ -988,7 +988,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry 
*dentry)
drop_nlink(dir);
 
clear_nlink(inode);
-   inode->i_mtime = inode->i_atime = current_time(inode);
+   inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
exfat_truncate_atime(>i_atime);
exfat_unhash_inode(inode);
exfat_d_version_set(dentry, inode_query_iversion(dir));
-- 
2.40.1




[apparmor] [PATCH v2 7/8] apparmor: update ctime whenever the mtime changes on an inode

2023-06-13 Thread Jeff Layton
In general, when updating the mtime on an inode, one must also update
the ctime. Add the missing ctime updates.

Signed-off-by: Jeff Layton 
---
 security/apparmor/apparmorfs.c|  7 +--
 security/apparmor/policy_unpack.c | 11 +++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index db7a51acf9db..c06053718836 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -1554,8 +1554,11 @@ void __aafs_profile_migrate_dents(struct aa_profile *old,
 
for (i = 0; i < AAFS_PROF_SIZEOF; i++) {
new->dents[i] = old->dents[i];
-   if (new->dents[i])
-   new->dents[i]->d_inode->i_mtime = 
current_time(new->dents[i]->d_inode);
+   if (new->dents[i]) {
+   struct inode *inode = d_inode(new->dents[i]);
+
+   inode->i_mtime = inode->i_ctime = current_time(inode);
+   }
old->dents[i] = NULL;
}
 }
diff --git a/security/apparmor/policy_unpack.c 
b/security/apparmor/policy_unpack.c
index cf2ceec40b28..48a97c1800b9 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -86,10 +86,13 @@ void __aa_loaddata_update(struct aa_loaddata *data, long 
revision)
 
data->revision = revision;
if ((data->dents[AAFS_LOADDATA_REVISION])) {
-   d_inode(data->dents[AAFS_LOADDATA_DIR])->i_mtime =
-   current_time(d_inode(data->dents[AAFS_LOADDATA_DIR]));
-   d_inode(data->dents[AAFS_LOADDATA_REVISION])->i_mtime =
-   
current_time(d_inode(data->dents[AAFS_LOADDATA_REVISION]));
+   struct inode *inode;
+
+   inode = d_inode(data->dents[AAFS_LOADDATA_DIR]);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
+
+   inode = d_inode(data->dents[AAFS_LOADDATA_REVISION]);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
}
 }
 
-- 
2.40.1




[apparmor] [PATCH v2 2/8] usb: update the ctime as well when updating mtime after an ioctl

2023-06-13 Thread Jeff Layton
In general, POSIX requires that when the mtime is updated that the ctime
be updated as well. Add the missing timestamp updates to the usb ioctls.

Signed-off-by: Jeff Layton 
---
 drivers/usb/core/devio.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index fcf68818e999..1268d313a8df 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -2640,21 +2640,21 @@ static long usbdev_do_ioctl(struct file *file, unsigned 
int cmd,
snoop(>dev, "%s: CONTROL\n", __func__);
ret = proc_control(ps, p);
if (ret >= 0)
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
break;
 
case USBDEVFS_BULK:
snoop(>dev, "%s: BULK\n", __func__);
ret = proc_bulk(ps, p);
if (ret >= 0)
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
break;
 
case USBDEVFS_RESETEP:
snoop(>dev, "%s: RESETEP\n", __func__);
ret = proc_resetep(ps, p);
if (ret >= 0)
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
break;
 
case USBDEVFS_RESET:
@@ -2666,7 +2666,7 @@ static long usbdev_do_ioctl(struct file *file, unsigned 
int cmd,
snoop(>dev, "%s: CLEAR_HALT\n", __func__);
ret = proc_clearhalt(ps, p);
if (ret >= 0)
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
break;
 
case USBDEVFS_GETDRIVER:
@@ -2693,7 +2693,7 @@ static long usbdev_do_ioctl(struct file *file, unsigned 
int cmd,
snoop(>dev, "%s: SUBMITURB\n", __func__);
ret = proc_submiturb(ps, p);
if (ret >= 0)
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
break;
 
 #ifdef CONFIG_COMPAT
@@ -2701,14 +2701,14 @@ static long usbdev_do_ioctl(struct file *file, unsigned 
int cmd,
snoop(>dev, "%s: CONTROL32\n", __func__);
ret = proc_control_compat(ps, p);
if (ret >= 0)
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
break;
 
case USBDEVFS_BULK32:
snoop(>dev, "%s: BULK32\n", __func__);
ret = proc_bulk_compat(ps, p);
if (ret >= 0)
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
break;
 
case USBDEVFS_DISCSIGNAL32:
@@ -2720,7 +2720,7 @@ static long usbdev_do_ioctl(struct file *file, unsigned 
int cmd,
snoop(>dev, "%s: SUBMITURB32\n", __func__);
ret = proc_submiturb_compat(ps, p);
if (ret >= 0)
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
break;
 
case USBDEVFS_IOCTL32:
-- 
2.40.1




[apparmor] [PATCH v2 1/8] ibmvmc: update ctime in conjunction with mtime on write

2023-06-13 Thread Jeff Layton
POSIX says:

"Upon successful completion, where nbyte is greater than 0, write()
 shall mark for update the last data modification and last file status
 change timestamps of the file..."

Signed-off-by: Jeff Layton 
---
 drivers/misc/ibmvmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/ibmvmc.c b/drivers/misc/ibmvmc.c
index cbaf6d35e854..d7c7f0305257 100644
--- a/drivers/misc/ibmvmc.c
+++ b/drivers/misc/ibmvmc.c
@@ -1124,7 +1124,7 @@ static ssize_t ibmvmc_write(struct file *file, const char 
*buffer,
goto out;
 
inode = file_inode(file);
-   inode->i_mtime = current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
mark_inode_dirty(inode);
 
dev_dbg(adapter->dev, "write: file = 0x%lx, count = 0x%lx\n",
-- 
2.40.1




Re: [apparmor] [PATCH 7/9] gfs2: update ctime when quota is updated

2023-06-13 Thread Jeff Layton
On Fri, 2023-06-09 at 18:44 +0200, Andreas Gruenbacher wrote:
> Jeff,
> 
> On Fri, Jun 9, 2023 at 2:50 PM Jeff Layton  wrote:
> > Signed-off-by: Jeff Layton 
> > ---
> >  fs/gfs2/quota.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
> > index 1ed17226d9ed..6d283e071b90 100644
> > --- a/fs/gfs2/quota.c
> > +++ b/fs/gfs2/quota.c
> > @@ -869,7 +869,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, 
> > loff_t loc,
> > size = loc + sizeof(struct gfs2_quota);
> > if (size > inode->i_size)
> > i_size_write(inode, size);
> > -   inode->i_mtime = inode->i_atime = current_time(inode);
> > +   inode->i_mtime = inode->i_atime = inode->i_ctime = 
> > current_time(inode);
> 
> I don't think we need to worry about the ctime of the quota inode as
> that inode is internal to the filesystem only.
> 

Thanks Andreas.  I'll plan to drop this patch from the series for now.

Does updating the mtime and atime here serve any purpose, or should
those also be removed? If you plan to keep the a/mtime updates then I'd
still suggest updating the ctime for consistency's sake. It shouldn't
cost anything extra to do so since you're dirtying the inode below
anyway.

Thanks!

> > mark_inode_dirty(inode);
> > set_bit(QDF_REFRESH, >qd_flags);
> > }
> > --
> > 2.40.1
> > 
> 
> Thanks,
> Andreas
> 

-- 
Jeff Layton 



[apparmor] [PATCH v2 8/8] cifs: update the ctime on a partial page write

2023-06-13 Thread Jeff Layton
POSIX says:

"Upon successful completion, where nbyte is greater than 0, write()
 shall mark for update the last data modification and last file status
 change timestamps of the file..."

Add the missing ctime update.

Signed-off-by: Jeff Layton 
---
 fs/smb/client/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index df88b8c04d03..a00038a326cf 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -2596,7 +2596,7 @@ static int cifs_partialpagewrite(struct page *page, 
unsigned from, unsigned to)
   write_data, to - from, );
cifsFileInfo_put(open_file);
/* Does mm or vfs already set times? */
-   inode->i_atime = inode->i_mtime = current_time(inode);
+   inode->i_atime = inode->i_mtime = inode->i_ctime = 
current_time(inode);
if ((bytes_written > 0) && (offset))
rc = 0;
else if (bytes_written < 0)
-- 
2.40.1




Re: [apparmor] [PATCH v2 8/8] cifs: update the ctime on a partial page write

2023-06-13 Thread Jeff Layton
On Mon, 2023-06-12 at 09:41 -0400, Tom Talpey wrote:
> On 6/12/2023 6:45 AM, Jeff Layton wrote:
> > POSIX says:
> > 
> >  "Upon successful completion, where nbyte is greater than 0, write()
> >   shall mark for update the last data modification and last file status
> >   change timestamps of the file..."
> > 
> > Add the missing ctime update.
> > 
> > Signed-off-by: Jeff Layton 
> > ---
> >   fs/smb/client/file.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
> > index df88b8c04d03..a00038a326cf 100644
> > --- a/fs/smb/client/file.c
> > +++ b/fs/smb/client/file.c
> > @@ -2596,7 +2596,7 @@ static int cifs_partialpagewrite(struct page *page, 
> > unsigned from, unsigned to)
> >write_data, to - from, );
> > cifsFileInfo_put(open_file);
> > /* Does mm or vfs already set times? */
> > -   inode->i_atime = inode->i_mtime = current_time(inode);
> > +   inode->i_atime = inode->i_mtime = inode->i_ctime = 
> > current_time(inode);
> 
> Question. It appears that roughly half the filesystems in this series
> don't touch the i_atime in this case. And the other half do. Which is
> correct? Did they incorrectly set i_atime instead of i_ctime?
> 

I noticed that too, and with this set, I decided to not make any atime
changes since I wasn't sure.

I think the answer to your question is "it depends". atime is supposed
to be updated on reads, not writes, but sometimes a write requires a RMW
cycle of some flavor so one can imagine that in some cases we'd need to
update all three.

In this case, I'm not sure that updating any of these times is the right
thing to do. This is called from ->launder_folio, so the syscall that
issued the write is long gone and we're in writeback here.

With NFS, we generally leave timestamp updates to the server. Should any
of these timestamps be updated by the (SMB1) client here?
-- 
Jeff Layton 



[apparmor] [PATCH v2 4/8] bfs: update ctime in addition to mtime when adding entries

2023-06-13 Thread Jeff Layton
When adding entries to a directory, POSIX generally requires that the
ctime be updated alongside the mtime.

Signed-off-by: Jeff Layton 
---
 fs/bfs/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c
index 040d5140e426..d2e8a2a56b05 100644
--- a/fs/bfs/dir.c
+++ b/fs/bfs/dir.c
@@ -294,7 +294,7 @@ static int bfs_add_entry(struct inode *dir, const struct 
qstr *child, int ino)
dir->i_size += BFS_DIRENT_SIZE;
dir->i_ctime = current_time(dir);
}
-   dir->i_mtime = current_time(dir);
+   dir->i_mtime = dir->i_ctime = current_time(dir);
mark_inode_dirty(dir);
de->ino = cpu_to_le16((u16)ino);
for (i = 0; i < BFS_NAMELEN; i++)
-- 
2.40.1




[apparmor] [PATCH v2 0/8] fs: add some missing ctime updates

2023-06-13 Thread Jeff Layton
v2:
- drop gfs2 patch as it involved (hidden) quota inode
- clarify patch descriptions to satisfy checkpatch.pl

While working on a patch series to change how we handle the ctime, I
found a number of places that update the mtime without a corresponding
ctime update.

While it's not spelled out explicitly in the POSIX spec, all of the
operations that update the mtime must also update the ctime. I've not
been able to find any counterexamples, in any case. Some of these
patches involve operations not covered by POSIX, but it's still a good
idea to update the ctime when updating the mtime.

Note that these are largely untested other than for compilation, so
please review carefully. These are a preliminary set for the upcoming
rework of how we handle the ctime.

None of these seem to be very crucial, but it would be nice if various
maintainers could pick these up for v6.5. Please let me know if you do,
or would rather I shepherd the patch upstream.

Jeff Layton (8):
  ibmvmc: update ctime in conjunction with mtime on write
  usb: update the ctime as well when updating mtime after an ioctl
  autofs: set ctime as well when mtime changes on a dir
  bfs: update ctime in addition to mtime when adding entries
  efivarfs: update ctime when mtime changes on a write
  exfat: ensure that ctime is updated whenever the mtime is
  apparmor: update ctime whenever the mtime changes on an inode
  cifs: update the ctime on a partial page write

 drivers/misc/ibmvmc.c |  2 +-
 drivers/usb/core/devio.c  | 16 
 fs/autofs/root.c  |  6 +++---
 fs/bfs/dir.c  |  2 +-
 fs/efivarfs/file.c|  2 +-
 fs/exfat/namei.c  |  8 
 fs/smb/client/file.c  |  2 +-
 security/apparmor/apparmorfs.c|  7 +--
 security/apparmor/policy_unpack.c | 11 +++
 9 files changed, 31 insertions(+), 25 deletions(-)

-- 
2.40.1




[apparmor] [PATCH v2 3/8] autofs: set ctime as well when mtime changes on a dir

2023-06-13 Thread Jeff Layton
When adding entries to a directory, POSIX generally requires that the
ctime also be updated alongside the mtime.

Signed-off-by: Jeff Layton 
---
 fs/autofs/root.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/autofs/root.c b/fs/autofs/root.c
index 6baf90b08e0e..93046c9dc461 100644
--- a/fs/autofs/root.c
+++ b/fs/autofs/root.c
@@ -600,7 +600,7 @@ static int autofs_dir_symlink(struct mnt_idmap *idmap,
p_ino = autofs_dentry_ino(dentry->d_parent);
p_ino->count++;
 
-   dir->i_mtime = current_time(dir);
+   dir->i_mtime = dir->i_ctime = current_time(dir);
 
return 0;
 }
@@ -633,7 +633,7 @@ static int autofs_dir_unlink(struct inode *dir, struct 
dentry *dentry)
d_inode(dentry)->i_size = 0;
clear_nlink(d_inode(dentry));
 
-   dir->i_mtime = current_time(dir);
+   dir->i_mtime = dir->i_ctime = current_time(dir);
 
spin_lock(>lookup_lock);
__autofs_add_expiring(dentry);
@@ -749,7 +749,7 @@ static int autofs_dir_mkdir(struct mnt_idmap *idmap,
p_ino = autofs_dentry_ino(dentry->d_parent);
p_ino->count++;
inc_nlink(dir);
-   dir->i_mtime = current_time(dir);
+   dir->i_mtime = dir->i_ctime = current_time(dir);
 
return 0;
 }
-- 
2.40.1




Re: [apparmor] [PATCH v2 0/8] fs: add some missing ctime updates

2023-06-13 Thread Tigran Aivazian
Hi Jeff and all,

On Mon, 12 Jun 2023 at 11:45, Jeff Layton  wrote:

> None of these seem to be very crucial, but it would be nice if various
> maintainers could pick these up for v6.5. Please let me know if you do,
> or would rather I shepherd the patch upstream.
>

Yes, if you could shepherd the patch upstream, that would be great, as it's
been a very long time since I did any kernel hacking, and the patch
submission procedures must have changed in a decade or two :) Thank you!

Kind regards,
Tigran