All of lore.kernel.org
 help / color / mirror / Atom feed
* iptables --log-uid patch for 2.6
@ 2004-11-28 18:55 John Lange
  2004-12-08  4:33 ` Patrick McHardy
  0 siblings, 1 reply; 5+ messages in thread
From: John Lange @ 2004-11-28 18:55 UTC (permalink / raw)
  To: netfilter-develop

[-- Attachment #1: Type: text/plain, Size: 4398 bytes --]

I sent this to the list yesterday but I don't think it made it through.
Apologies if it is a duplicate.

Here are patches against the userspace and the kernel which allows the
logging of the uid that generated the (outgoing) packet.

This patch was originally the work of Martin Josefsson for the 2.4
kernel but was never incorporated into the main code base. My work here
simply ports it to the 2.6 kernel and the current version of netfilter
(iptables).

It is useful for figuring out which users might have had their accounts
compromised by spam relays, IRC bots or other such things.

I've been running this patch on a production server since Oct 30 without
any problems.


--- linux-2.6.9/include/linux/netfilter_ipv4/ipt_LOG.h  2004-10-18 16:55:07.000000000 -0500
+++
linux-2.6.9-jl1/include/linux/netfilter_ipv4/ipt_LOG.h      2004-10-30
16:42:12.000000000 -0500
@@ -4,7 +4,8 @@
 #define IPT_LOG_TCPSEQ         0x01    /* Log TCP sequence numbers */
 #define IPT_LOG_TCPOPT         0x02    /* Log TCP options */
 #define IPT_LOG_IPOPT          0x04    /* Log IP options */
-#define IPT_LOG_MASK           0x07
+#define IPT_LOG_UID            0x08    /* Log UID owning local socket
*/
+#define IPT_LOG_MASK           0x0f
 
 struct ipt_log_info {
        unsigned char level;
--- linux-2.6.9/net/ipv4/netfilter/ipt_LOG.c    2004-10-18
16:55:06.000000000 -0500
+++ linux-2.6.9-jl1/net/ipv4/netfilter/ipt_LOG.c        2004-10-30
19:21:12.000000000 -0500
@@ -384,6 +384,8 @@
        }
 
        dump_packet(loginfo, skb, 0);
+       if ((loginfo->logflags & IPT_LOG_UID) && skb->sk &&
skb->sk->sk_socket && skb->sk->sk_socket->file)
+               printk("UID=%u ", skb->sk->sk_socket->file->f_uid);
        printk("\n");
        spin_unlock_bh(&log_lock);
 }


--- iptables-1.2.11/extensions/libipt_LOG.c     2004-06-14
17:02:16.000000000 -0500
+++ iptables-1.2.11-jl/extensions/libipt_LOG.c  2004-10-30
16:39:16.000000000 -0500
@@ -21,7 +21,8 @@
 " --log-prefix prefix          Prefix log messages with this
prefix.\n\n"
 " --log-tcp-sequence           Log TCP sequence numbers.\n\n"
 " --log-tcp-options            Log TCP options.\n\n"
-" --log-ip-options             Log IP options.\n\n",
+" --log-ip-options             Log IP options.\n\n"
+" --log-uid                    Log UID owning the local socket.\n\n",
 IPTABLES_VERSION);
 }
 
@@ -31,6 +32,7 @@
        { .name = "log-tcp-sequence", .has_arg = 0, .flag = 0, .val =
'1' },
        { .name = "log-tcp-options",  .has_arg = 0, .flag = 0, .val =
'2' },
        { .name = "log-ip-options",   .has_arg = 0, .flag = 0, .val =
'3' },
+       { .name = "log-uid",          .has_arg = 0, .flag = 0, .val =
'4' },
        { .name = 0 }
 };
 
@@ -98,6 +100,7 @@
 #define IPT_LOG_OPT_TCPSEQ 0x04
 #define IPT_LOG_OPT_TCPOPT 0x08
 #define IPT_LOG_OPT_IPOPT 0x10
+#define IPT_LOG_OPT_UID 0x20
 
 /* Function which parses command options; returns true if it
    ate an option */
@@ -168,6 +171,15 @@
                *flags |= IPT_LOG_OPT_IPOPT;
                break;
 
+       case '4':
+               if (*flags & IPT_LOG_OPT_UID)
+                       exit_error(PARAMETER_PROBLEM,
+                                  "Can't specify --log-uid twice");
+
+               loginfo->logflags |= IPT_LOG_UID;
+               *flags |= IPT_LOG_OPT_UID;
+               break;
+
        default:
                return 0;
        }
@@ -211,6 +223,8 @@
                        printf("tcp-options ");
                if (loginfo->logflags & IPT_LOG_IPOPT)
                        printf("ip-options ");
+               if (loginfo->logflags & IPT_LOG_UID)
+                       printf("uid ");
                if (loginfo->logflags & ~(IPT_LOG_MASK))
                        printf("unknown-flags ");
        }
@@ -238,6 +252,8 @@
                printf("--log-tcp-options ");
        if (loginfo->logflags & IPT_LOG_IPOPT)
                printf("--log-ip-options ");
+       if (loginfo->logflags & IPT_LOG_UID)
+               printf("--log-uid ");
 }
 
 static
--- iptables-1.2.11/extensions/libipt_LOG.man   2004-01-22
09:04:24.000000000 -0600
+++ iptables-1.2.11-jl/extensions/libipt_LOG.man        2004-10-30
19:28:09.000000000 -0500
@@ -26,3 +26,6 @@
 .TP
 .B --log-ip-options
 Log options from the IP packet header.
+.TP
+.B --log-uid
+Log the userid of the process which generated the packet.
-- 
John Lange
OpenIT ltd.
(204) 885 0872

[-- Attachment #2: ipt_LOG-uid.patch --]
[-- Type: text/x-patch, Size: 961 bytes --]

--- linux-2.6.9/include/linux/netfilter_ipv4/ipt_LOG.h	2004-10-18 16:55:07.000000000 -0500
+++ linux-2.6.9-jl1/include/linux/netfilter_ipv4/ipt_LOG.h	2004-10-30 16:42:12.000000000 -0500
@@ -4,7 +4,8 @@
 #define IPT_LOG_TCPSEQ		0x01	/* Log TCP sequence numbers */
 #define IPT_LOG_TCPOPT		0x02	/* Log TCP options */
 #define IPT_LOG_IPOPT		0x04	/* Log IP options */
-#define IPT_LOG_MASK		0x07
+#define IPT_LOG_UID		0x08	/* Log UID owning local socket */
+#define IPT_LOG_MASK		0x0f
 
 struct ipt_log_info {
 	unsigned char level;
--- linux-2.6.9/net/ipv4/netfilter/ipt_LOG.c	2004-10-18 16:55:06.000000000 -0500
+++ linux-2.6.9-jl1/net/ipv4/netfilter/ipt_LOG.c	2004-10-30 19:21:12.000000000 -0500
@@ -384,6 +384,8 @@
 	}
 
 	dump_packet(loginfo, skb, 0);
+ 	if ((loginfo->logflags & IPT_LOG_UID) && skb->sk && skb->sk->sk_socket && skb->sk->sk_socket->file)
+ 		printk("UID=%u ", skb->sk->sk_socket->file->f_uid);
 	printk("\n");
 	spin_unlock_bh(&log_lock);
 }

[-- Attachment #3: ipt_LOG-uid.userspace.patch --]
[-- Type: text/x-patch, Size: 2148 bytes --]

--- iptables-1.2.11/extensions/libipt_LOG.c	2004-06-14 17:02:16.000000000 -0500
+++ iptables-1.2.11-jl/extensions/libipt_LOG.c	2004-10-30 16:39:16.000000000 -0500
@@ -21,7 +21,8 @@
 " --log-prefix prefix		Prefix log messages with this prefix.\n\n"
 " --log-tcp-sequence		Log TCP sequence numbers.\n\n"
 " --log-tcp-options		Log TCP options.\n\n"
-" --log-ip-options		Log IP options.\n\n",
+" --log-ip-options		Log IP options.\n\n"
+" --log-uid			Log UID owning the local socket.\n\n",
 IPTABLES_VERSION);
 }
 
@@ -31,6 +32,7 @@
 	{ .name = "log-tcp-sequence", .has_arg = 0, .flag = 0, .val = '1' },
 	{ .name = "log-tcp-options",  .has_arg = 0, .flag = 0, .val = '2' },
 	{ .name = "log-ip-options",   .has_arg = 0, .flag = 0, .val = '3' },
+	{ .name = "log-uid",          .has_arg = 0, .flag = 0, .val = '4' },
 	{ .name = 0 }
 };
 
@@ -98,6 +100,7 @@
 #define IPT_LOG_OPT_TCPSEQ 0x04
 #define IPT_LOG_OPT_TCPOPT 0x08
 #define IPT_LOG_OPT_IPOPT 0x10
+#define IPT_LOG_OPT_UID 0x20
 
 /* Function which parses command options; returns true if it
    ate an option */
@@ -168,6 +171,15 @@
 		*flags |= IPT_LOG_OPT_IPOPT;
 		break;
 
+	case '4':
+		if (*flags & IPT_LOG_OPT_UID)
+			exit_error(PARAMETER_PROBLEM,
+				   "Can't specify --log-uid twice");
+
+		loginfo->logflags |= IPT_LOG_UID;
+		*flags |= IPT_LOG_OPT_UID;
+		break;
+
 	default:
 		return 0;
 	}
@@ -211,6 +223,8 @@
 			printf("tcp-options ");
 		if (loginfo->logflags & IPT_LOG_IPOPT)
 			printf("ip-options ");
+		if (loginfo->logflags & IPT_LOG_UID)
+			printf("uid ");
 		if (loginfo->logflags & ~(IPT_LOG_MASK))
 			printf("unknown-flags ");
 	}
@@ -238,6 +252,8 @@
 		printf("--log-tcp-options ");
 	if (loginfo->logflags & IPT_LOG_IPOPT)
 		printf("--log-ip-options ");
+	if (loginfo->logflags & IPT_LOG_UID)
+		printf("--log-uid ");
 }
 
 static
--- iptables-1.2.11/extensions/libipt_LOG.man	2004-01-22 09:04:24.000000000 -0600
+++ iptables-1.2.11-jl/extensions/libipt_LOG.man	2004-10-30 19:28:09.000000000 -0500
@@ -26,3 +26,6 @@
 .TP
 .B --log-ip-options
 Log options from the IP packet header.
+.TP
+.B --log-uid
+Log the userid of the process which generated the packet.

^ permalink raw reply	[flat|nested] 5+ messages in thread
* iptables --log-uid patch for 2.6
@ 2004-11-27 22:30 John Lange
  0 siblings, 0 replies; 5+ messages in thread
From: John Lange @ 2004-11-27 22:30 UTC (permalink / raw)
  To: netfilter-develop

[-- Attachment #1: Type: text/plain, Size: 4293 bytes --]

Here are patches against the userspace and the kernel which allows the
logging of the uid that generated the (outgoing) packet.

This patch was originally the work of Martin Josefsson for the 2.4
kernel but was never incorporated into the main code base. My work here
simply ports it to the 2.6 kernel and the current version of netfilter
(iptables).

It is useful for figuring out which users might have had their accounts
compromised by spam relays, IRC bots or other such things.

I've been running this patch on a production server since Oct 30 without
any problems.


--- linux-2.6.9/include/linux/netfilter_ipv4/ipt_LOG.h  2004-10-18 16:55:07.000000000 -0500
+++
linux-2.6.9-jl1/include/linux/netfilter_ipv4/ipt_LOG.h      2004-10-30
16:42:12.000000000 -0500
@@ -4,7 +4,8 @@
 #define IPT_LOG_TCPSEQ         0x01    /* Log TCP sequence numbers */
 #define IPT_LOG_TCPOPT         0x02    /* Log TCP options */
 #define IPT_LOG_IPOPT          0x04    /* Log IP options */
-#define IPT_LOG_MASK           0x07
+#define IPT_LOG_UID            0x08    /* Log UID owning local socket
*/
+#define IPT_LOG_MASK           0x0f
 
 struct ipt_log_info {
        unsigned char level;
--- linux-2.6.9/net/ipv4/netfilter/ipt_LOG.c    2004-10-18
16:55:06.000000000 -0500
+++ linux-2.6.9-jl1/net/ipv4/netfilter/ipt_LOG.c        2004-10-30
19:21:12.000000000 -0500
@@ -384,6 +384,8 @@
        }
 
        dump_packet(loginfo, skb, 0);
+       if ((loginfo->logflags & IPT_LOG_UID) && skb->sk &&
skb->sk->sk_socket && skb->sk->sk_socket->file)
+               printk("UID=%u ", skb->sk->sk_socket->file->f_uid);
        printk("\n");
        spin_unlock_bh(&log_lock);
 }


--- iptables-1.2.11/extensions/libipt_LOG.c     2004-06-14
17:02:16.000000000 -0500
+++ iptables-1.2.11-jl/extensions/libipt_LOG.c  2004-10-30
16:39:16.000000000 -0500
@@ -21,7 +21,8 @@
 " --log-prefix prefix          Prefix log messages with this
prefix.\n\n"
 " --log-tcp-sequence           Log TCP sequence numbers.\n\n"
 " --log-tcp-options            Log TCP options.\n\n"
-" --log-ip-options             Log IP options.\n\n",
+" --log-ip-options             Log IP options.\n\n"
+" --log-uid                    Log UID owning the local socket.\n\n",
 IPTABLES_VERSION);
 }
 
@@ -31,6 +32,7 @@
        { .name = "log-tcp-sequence", .has_arg = 0, .flag = 0, .val =
'1' },
        { .name = "log-tcp-options",  .has_arg = 0, .flag = 0, .val =
'2' },
        { .name = "log-ip-options",   .has_arg = 0, .flag = 0, .val =
'3' },
+       { .name = "log-uid",          .has_arg = 0, .flag = 0, .val =
'4' },
        { .name = 0 }
 };
 
@@ -98,6 +100,7 @@
 #define IPT_LOG_OPT_TCPSEQ 0x04
 #define IPT_LOG_OPT_TCPOPT 0x08
 #define IPT_LOG_OPT_IPOPT 0x10
+#define IPT_LOG_OPT_UID 0x20
 
 /* Function which parses command options; returns true if it
    ate an option */
@@ -168,6 +171,15 @@
                *flags |= IPT_LOG_OPT_IPOPT;
                break;
 
+       case '4':
+               if (*flags & IPT_LOG_OPT_UID)
+                       exit_error(PARAMETER_PROBLEM,
+                                  "Can't specify --log-uid twice");
+
+               loginfo->logflags |= IPT_LOG_UID;
+               *flags |= IPT_LOG_OPT_UID;
+               break;
+
        default:
                return 0;
        }
@@ -211,6 +223,8 @@
                        printf("tcp-options ");
                if (loginfo->logflags & IPT_LOG_IPOPT)
                        printf("ip-options ");
+               if (loginfo->logflags & IPT_LOG_UID)
+                       printf("uid ");
                if (loginfo->logflags & ~(IPT_LOG_MASK))
                        printf("unknown-flags ");
        }
@@ -238,6 +252,8 @@
                printf("--log-tcp-options ");
        if (loginfo->logflags & IPT_LOG_IPOPT)
                printf("--log-ip-options ");
+       if (loginfo->logflags & IPT_LOG_UID)
+               printf("--log-uid ");
 }
 
 static
--- iptables-1.2.11/extensions/libipt_LOG.man   2004-01-22
09:04:24.000000000 -0600
+++ iptables-1.2.11-jl/extensions/libipt_LOG.man        2004-10-30
19:28:09.000000000 -0500
@@ -26,3 +26,6 @@
 .TP
 .B --log-ip-options
 Log options from the IP packet header.
+.TP
+.B --log-uid
+Log the userid of the process which generated the packet.
-- 
John Lange
OpenIT ltd.
(204) 885 0872

[-- Attachment #2: ipt_LOG-uid.patch --]
[-- Type: text/x-patch, Size: 961 bytes --]

--- linux-2.6.9/include/linux/netfilter_ipv4/ipt_LOG.h	2004-10-18 16:55:07.000000000 -0500
+++ linux-2.6.9-jl1/include/linux/netfilter_ipv4/ipt_LOG.h	2004-10-30 16:42:12.000000000 -0500
@@ -4,7 +4,8 @@
 #define IPT_LOG_TCPSEQ		0x01	/* Log TCP sequence numbers */
 #define IPT_LOG_TCPOPT		0x02	/* Log TCP options */
 #define IPT_LOG_IPOPT		0x04	/* Log IP options */
-#define IPT_LOG_MASK		0x07
+#define IPT_LOG_UID		0x08	/* Log UID owning local socket */
+#define IPT_LOG_MASK		0x0f
 
 struct ipt_log_info {
 	unsigned char level;
--- linux-2.6.9/net/ipv4/netfilter/ipt_LOG.c	2004-10-18 16:55:06.000000000 -0500
+++ linux-2.6.9-jl1/net/ipv4/netfilter/ipt_LOG.c	2004-10-30 19:21:12.000000000 -0500
@@ -384,6 +384,8 @@
 	}
 
 	dump_packet(loginfo, skb, 0);
+ 	if ((loginfo->logflags & IPT_LOG_UID) && skb->sk && skb->sk->sk_socket && skb->sk->sk_socket->file)
+ 		printk("UID=%u ", skb->sk->sk_socket->file->f_uid);
 	printk("\n");
 	spin_unlock_bh(&log_lock);
 }

[-- Attachment #3: ipt_LOG-uid.userspace.patch --]
[-- Type: text/x-patch, Size: 2148 bytes --]

--- iptables-1.2.11/extensions/libipt_LOG.c	2004-06-14 17:02:16.000000000 -0500
+++ iptables-1.2.11-jl/extensions/libipt_LOG.c	2004-10-30 16:39:16.000000000 -0500
@@ -21,7 +21,8 @@
 " --log-prefix prefix		Prefix log messages with this prefix.\n\n"
 " --log-tcp-sequence		Log TCP sequence numbers.\n\n"
 " --log-tcp-options		Log TCP options.\n\n"
-" --log-ip-options		Log IP options.\n\n",
+" --log-ip-options		Log IP options.\n\n"
+" --log-uid			Log UID owning the local socket.\n\n",
 IPTABLES_VERSION);
 }
 
@@ -31,6 +32,7 @@
 	{ .name = "log-tcp-sequence", .has_arg = 0, .flag = 0, .val = '1' },
 	{ .name = "log-tcp-options",  .has_arg = 0, .flag = 0, .val = '2' },
 	{ .name = "log-ip-options",   .has_arg = 0, .flag = 0, .val = '3' },
+	{ .name = "log-uid",          .has_arg = 0, .flag = 0, .val = '4' },
 	{ .name = 0 }
 };
 
@@ -98,6 +100,7 @@
 #define IPT_LOG_OPT_TCPSEQ 0x04
 #define IPT_LOG_OPT_TCPOPT 0x08
 #define IPT_LOG_OPT_IPOPT 0x10
+#define IPT_LOG_OPT_UID 0x20
 
 /* Function which parses command options; returns true if it
    ate an option */
@@ -168,6 +171,15 @@
 		*flags |= IPT_LOG_OPT_IPOPT;
 		break;
 
+	case '4':
+		if (*flags & IPT_LOG_OPT_UID)
+			exit_error(PARAMETER_PROBLEM,
+				   "Can't specify --log-uid twice");
+
+		loginfo->logflags |= IPT_LOG_UID;
+		*flags |= IPT_LOG_OPT_UID;
+		break;
+
 	default:
 		return 0;
 	}
@@ -211,6 +223,8 @@
 			printf("tcp-options ");
 		if (loginfo->logflags & IPT_LOG_IPOPT)
 			printf("ip-options ");
+		if (loginfo->logflags & IPT_LOG_UID)
+			printf("uid ");
 		if (loginfo->logflags & ~(IPT_LOG_MASK))
 			printf("unknown-flags ");
 	}
@@ -238,6 +252,8 @@
 		printf("--log-tcp-options ");
 	if (loginfo->logflags & IPT_LOG_IPOPT)
 		printf("--log-ip-options ");
+	if (loginfo->logflags & IPT_LOG_UID)
+		printf("--log-uid ");
 }
 
 static
--- iptables-1.2.11/extensions/libipt_LOG.man	2004-01-22 09:04:24.000000000 -0600
+++ iptables-1.2.11-jl/extensions/libipt_LOG.man	2004-10-30 19:28:09.000000000 -0500
@@ -26,3 +26,6 @@
 .TP
 .B --log-ip-options
 Log options from the IP packet header.
+.TP
+.B --log-uid
+Log the userid of the process which generated the packet.

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

end of thread, other threads:[~2004-12-08 17:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-28 18:55 iptables --log-uid patch for 2.6 John Lange
2004-12-08  4:33 ` Patrick McHardy
2004-12-08  6:10   ` John Lange
2004-12-08 17:07     ` Patrick McHardy
  -- strict thread matches above, loose matches on Subject: below --
2004-11-27 22:30 John Lange

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.