mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net/socket: set socket inode times to current_time
@ 2023-02-01  4:30 Wenhua Zhao
  2023-02-02 20:42 ` Kuniyuki Iwashima
  0 siblings, 1 reply; 2+ messages in thread
From: Wenhua Zhao @ 2023-02-01  4:30 UTC (permalink / raw)
  Cc: Wenhua Zhao, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

Socket creation time are sometimes useful but not available becasue the
socket inode times are not set when initializing the inode.  This patch
sets the socket inode times to current_time().

Before the fix, the socket inode times are at epoch, for example:

    $ stat -L /proc/383/fd/3
      File: /proc/383/fd/3
      Size: 0               Blocks: 0          IO Block: 4096   socket
    Device: 0,8     Inode: 15996       Links: 1
    Access: (0777/srwxrwxrwx)  Uid: ( 1000/    arch)   Gid: ( 1000/    arch)
    Access: 1970-01-01 00:00:00.000000000 +0000
    Modify: 1970-01-01 00:00:00.000000000 +0000
    Change: 1970-01-01 00:00:00.000000000 +0000

After the fix, the inode times are the socket creation time:

    $ stat -L /proc/254/fd/3
      File: /proc/254/fd/3
      Size: 0               Blocks: 0          IO Block: 4096   socket
    Device: 0,7     Inode: 13170       Links: 1
    Access: (0777/srwxrwxrwx)  Uid: ( 1000/    arch)   Gid: ( 1000/    arch)
    Access: 2023-02-01 03:27:50.094731201 +0000
    Modify: 2023-02-01 03:27:50.094731201 +0000
    Change: 2023-02-01 03:27:50.094731201 +0000

Signed-off-by: Wenhua Zhao <whzhao@gmail.com>
---
 net/socket.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/socket.c b/net/socket.c
index 888cd618a968..c656c9599a92 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -635,6 +635,7 @@ struct socket *sock_alloc(void)
 	inode->i_uid = current_fsuid();
 	inode->i_gid = current_fsgid();
 	inode->i_op = &sockfs_inode_ops;
+	inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
 
 	return sock;
 }
-- 
2.39.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-02 20:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-01  4:30 [PATCH] net/socket: set socket inode times to current_time Wenhua Zhao
2023-02-02 20:42 ` Kuniyuki Iwashima

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®