Skip to contentSkip to conversation

inotify: add the monitor for the event source

PATCH In review Yi Yang 2 participants 8 messages Mar 8, 2006 – Mar 10, 2006

Subsystems (2)
lore
Share & tools
lore

Yi Yang

author
#0 lore raw

PATCH 1/1 inotify: add the monitor for the event source

Current inotify implementation only focus on change of file system, but it doesn't
know who results in this change, this patch adds three fields to struct inotify_event, tgid, uid and gid, they will save process ID, user ID and user group ID of the process which leads to change in the file system, such software as anti-virus can make use
of this feature to monitor who is modifying a specific file.

include/linux/inotify.h renamed from include/linux/inotify.h.orig +3 -0
@@ -19,6 +19,9 @@ struct inotify_event {
 	__s32		wd;		/* watch descriptor */
 	__u32		mask;		/* watch mask */
 	__u32		cookie;		/* cookie to synchronize two events */
+	__u32		tgid;		/* process ID of the event source */
+	__u32		uid;		/* user ID of the responding process */
+	__u32		gid;		/* group ID of the responding process */
 	__u32		len;		/* length (including nulls) of name */
 	char		name[0];	/* stub for possible name */
 };
fs/inotify.c renamed from fs/inotify.c.orig +3 -0
@@ -219,6 +219,9 @@ static struct inotify_kernel_event * ker
 	kevent->event.wd = wd;
 	kevent->event.mask = mask;
 	kevent->event.cookie = cookie;
+	kevent->event.tgid = current->tgid;
+	kevent->event.uid = current->uid;
+	kevent->event.gid = current->gid;
 
 	INIT_LIST_HEAD(&kevent->list);
 
#1 lore raw
Quoted 5 lines · Yi Yang

Current inotify implementation only focus on change of file system, but it doesn't
know who results in this change, this patch adds three fields to struct inotify_event, tgid, uid and gid, they will save process ID, user ID and user group ID of the process which leads to change in the file system, such software as anti-virus can make use
of this feature to monitor who is modifying a specific file.

this patch appears to change the ABI! That is bad bad bad. Also, how can you guarantee that "current" is valid and meaningful at the place you use it to get the user id ??
Also the process ID part is really bogus, after all the process may have exited by the time the inotify client gets to it, and the PID may even already have been reused.

author
#2 lore raw
Quoted 10 lines · Arjan van de Ven
Quoted 6 lines · Yi Yang

Current inotify implementation only focus on change of file system, but it doesn't
know who results in this change, this patch adds three fields to struct inotify_event, tgid, uid and gid, they will save process ID, user ID and user group ID of the process which leads to change in the file system, such software as anti-virus can make use
of this feature to monitor who is modifying a specific file.

Quoted 2 lines

this patch appears to change the ABI! That is bad bad bad.

a change of struct inotify_event can't change ABI, can you describe it more clear?

Quoted 3 lines

Also, how can you guarantee that "current" is valid and meaningful at the place you use it to get the user id ??

Of course, current process/thread never disappears before fsnotify_* returns.

Quoted 5 lines

Also the process ID part is really bogus, after all the process may have exited by the time the inotify client gets to it, and the PID may even already have been reused.

Your concern is correct, but uid and git can give out some hints, I ever considered to save the name of current process, however that needs a bigger and length-variable inotify_event struct, moreover, to get the full path name of current process/thread in kernel will have a big overhead, so I must select a comprise way. In fact, the case you said is very few.

#3 lore raw
Quoted 11 lines · Yi Yang
Quoted 10 lines · Arjan van de Ven
Quoted 6 lines · Yi Yang

Current inotify implementation only focus on change of file system, but it doesn't
know who results in this change, this patch adds three fields to struct inotify_event, tgid, uid and gid, they will save process ID, user ID and user group ID of the process which leads to change in the file system, such software as anti-virus can make use
of this feature to monitor who is modifying a specific file.

Quoted 4 lines
Quoted 2 lines

this patch appears to change the ABI! That is bad bad bad.

a change of struct inotify_event can't change ABI, can you describe it more clear?

it breaks ABI because this structure is communicated to userspace, and you change both the layout and the size of it. What else would ABI mean??

Quoted 5 lines
Quoted 3 lines

Also, how can you guarantee that "current" is valid and meaningful at the place you use it to get the user id ??

Of course, current process/thread never disappears before fsnotify_* returns.

but... what makes you think it's not a kernel thread such as kjournald? (which have basically meaningless current)

Quoted 5 lines
Quoted 5 lines

Also the process ID part is really bogus, after all the process may have exited by the time the inotify client gets to it, and the PID may even already have been reused.

Quoted 7 lines

Your concern is correct, but uid and git can give out some hints, I ever considered to
save the name of current process, however that needs a bigger and length-variable
inotify_event struct, moreover, to get the full path name of current process/thread
in kernel will have a big overhead, so I must select a comprise way.

there is no "full path name" concept in linux like that. And even worse, many processes will not have *any* path because they have been deleted, especially the viruses will use this ;)

author
#4 lore raw
Quoted 17 lines · Arjan van de Ven
Quoted 15 lines · Yi Yang
Quoted 13 lines · Arjan van de Ven
Quoted 7 lines · Yi Yang

Current inotify implementation only focus on change of file system, but it doesn't
know who results in this change, this patch adds three fields to struct inotify_event, tgid, uid and gid, they will save process ID, user ID and user group ID of the process which leads to change in the file system, such software as anti-virus can make use
of this feature to monitor who is modifying a specific file.

this patch appears to change the ABI! That is bad bad bad.

Quoted 7 lines
Quoted 2 lines

a change of struct inotify_event can't change ABI, can you describe it more clear?

it breaks ABI because this structure is communicated to userspace, and you change both the layout and the size of it. What else would ABI mean??

Many structures exported to user space in kernel are undergoing some change, A good application shouldn't count on invariability forever, My test application hasn't any problem before change and after change.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Also, how can you guarantee that "current" is valid and meaningful at the place you use it to get the user id ??

Quoted 6 lines
Quoted 2 lines

Of course, current process/thread never disappears before fsnotify_* returns.

but... what makes you think it's not a kernel thread such as kjournald? (which have basically meaningless current)

you can get values of these fields without any problem for kernel thread although they are useless.

Quoted 14 lines
Quoted 8 lines
Quoted 8 lines

Also the process ID part is really bogus, after all the process may have exited by the time the inotify client gets to it, and the PID may even already have been reused.

Quoted 5 lines

Your concern is correct, but uid and git can give out some hints, I ever considered to save the name of current process, however that needs a bigger and length-variable inotify_event struct, moreover, to get the full path name of current process/thread in kernel will have a big overhead, so I must select a comprise way.

Quoted 4 lines

there is no "full path name" concept in linux like that. And even worse, many processes will not have *any* path because they have been deleted, especially the viruses will use this ;)

For this case you said, this patch has now way really, do you have a good way to handle this case?

Quoted 3 lines
#5 lore raw
Quoted 9 lines
Quoted 6 lines

it breaks ABI because this structure is communicated to userspace, and you change both the layout and the size of it. What else would ABI mean??

Many structures exported to user space in kernel are undergoing some change, A good application shouldn't count on invariability forever, My test application hasn't any problem before change and after change.

this is absolutely incorrect. This is an ABI that cannot change in any incompatible way.

Quoted 6 lines
Quoted 4 lines

but... what makes you think it's not a kernel thread such as kjournald? (which have basically meaningless current)

you can get values of these fields without any problem for kernel thread although they are useless.

exactly

Quoted 7 lines
Quoted 5 lines

there is no "full path name" concept in linux like that. And even worse, many processes will not have *any* path because they have been deleted, especially the viruses will use this ;)

For this case you said, this patch has now way really, do you have a good way to handle this case?

it sounds that what you want to achieve is broken in the first place... (or should use audit etc)

author
#6 lore raw
Quoted 28 lines · Arjan van de Ven
Quoted 8 lines
Quoted 5 lines

it breaks ABI because this structure is communicated to userspace, and you change both the layout and the size of it. What else would ABI mean??

Many structures exported to user space in kernel are undergoing some change, A good application shouldn't count on invariability forever, My test application hasn't any problem before change and after change.

this is absolutely incorrect. This is an ABI that cannot change in any incompatible way.

Quoted 6 lines
Quoted 4 lines

but... what makes you think it's not a kernel thread such as kjournald? (which have basically meaningless current)

you can get values of these fields without any problem for kernel thread although they are useless.

exactly

Quoted 5 lines
Quoted 5 lines

there is no "full path name" concept in linux like that. And even worse, many processes will not have *any* path because they have been deleted, especially the viruses will use this ;)

Quoted 6 lines
Quoted 2 lines

For this case you said, this patch has now way really, do you have a good way to handle this case?

it sounds that what you want to achieve is broken in the first place... (or should use audit etc)

As I known, BSD process audit only can be done inside a process, and audit result is just visible after termination of this process, if an application wants to monitor all the processes, it has no way. My patch provides such a way bases on inotify with minimal work, it should be an good extension for inotify although it can't cover all the cases.

Quoted 2 lines
#7 lore raw
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

For this case you said, this patch has now way really, do you have a good way to handle this case?

it sounds that what you want to achieve is broken in the first place... (or should use audit etc)

As I known, BSD process audit only

I'm not talking about BSD audit but about the CAPP security audit framework.