From: Pablo Neira Ayuso <pablo@netfilter.org>
To: valentina.giusti@bmw-carit.de
Cc: netfilter-devel@vger.kernel.org, netdev@vger.kernel.org,
fw@strlen.de, eric.dumazet@gmail.com, tgraf@redhat.com,
jpa@google.com, davem@davemloft.net, daniel.wagner@bmw-carit.de,
Valentina Giusti <valentina.giusti@oss.bmw-carit.de>
Subject: Re: [PATCH v2 1/2] netfilter_queue: enable UID/GID socket info retrieval
Date: Fri, 20 Dec 2013 10:29:26 +0100 [thread overview]
Message-ID: <20131220092926.GA9275@localhost> (raw)
In-Reply-To: <20131220092638.GA9122@localhost>
On Fri, Dec 20, 2013 at 10:26:38AM +0100, Pablo Neira Ayuso wrote:
> Hi,
>
> On Thu, Dec 19, 2013 at 12:03:26PM +0100, valentina.giusti@bmw-carit.de wrote:
> > From: Valentina Giusti <valentina.giusti@oss.bmw-carit.de>
> >
> > Thanks to commits 41063e9 (ipv4: Early TCP socket demux) and 421b388 (udp: ipv4:
> > Add udp early demux) it is now possible to parse UID and GID socket info
> > also for incoming TCP and UDP connections. Having this info available, it
> > is convenient to let NFQUEUE parse it in order to improve and refine the
> > traffic analysis in userspace.
> >
> > Signed-off-by: Valentina Giusti <valentina.giusti@bmw-carit.de>
> > ---
> > include/uapi/linux/netfilter/nfnetlink_queue.h | 5 ++++-
> > net/netfilter/nfnetlink_queue_core.c | 31 ++++++++++++++++++++++++++
> > 2 files changed, 35 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/uapi/linux/netfilter/nfnetlink_queue.h b/include/uapi/linux/netfilter/nfnetlink_queue.h
> > index 0132bad..8dd819e 100644
> > --- a/include/uapi/linux/netfilter/nfnetlink_queue.h
> > +++ b/include/uapi/linux/netfilter/nfnetlink_queue.h
> > @@ -47,6 +47,8 @@ enum nfqnl_attr_type {
> > NFQA_CAP_LEN, /* __u32 length of captured packet */
> > NFQA_SKB_INFO, /* __u32 skb meta information */
> > NFQA_EXP, /* nf_conntrack_netlink.h */
> > + NFQA_UID, /* __u32 sk uid */
> > + NFQA_GID, /* __u32 sk gid */
> >
> > __NFQA_MAX
> > };
> > @@ -99,7 +101,8 @@ enum nfqnl_attr_config {
> > #define NFQA_CFG_F_FAIL_OPEN (1 << 0)
> > #define NFQA_CFG_F_CONNTRACK (1 << 1)
> > #define NFQA_CFG_F_GSO (1 << 2)
> > -#define NFQA_CFG_F_MAX (1 << 3)
> > +#define NFQA_CFG_F_UID_GID (1 << 3)
> > +#define NFQA_CFG_F_MAX (1 << 4)
> >
> > /* flags for NFQA_SKB_INFO */
> > /* packet appears to have wrong checksums, but they are ok */
> > diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
> > index 21258cf..2cdef07 100644
> > --- a/net/netfilter/nfnetlink_queue_core.c
> > +++ b/net/netfilter/nfnetlink_queue_core.c
> > @@ -297,6 +297,29 @@ nfqnl_put_packet_info(struct sk_buff *nlskb, struct sk_buff *packet,
> > return flags ? nla_put_be32(nlskb, NFQA_SKB_INFO, htonl(flags)) : 0;
> > }
> >
> > +static int nfqnl_put_sk_uidgid(struct sk_buff *skb, struct sock *sk)
> > +{
> > + const struct cred *cred;
> > +
> > + if (sk && sk->sk_state != TCP_TIME_WAIT) {
> > + read_lock_bh(&sk->sk_callback_lock);
> > + if (sk->sk_socket && sk->sk_socket->file) {
> > + cred = sk->sk_socket->file->f_cred;
> > + if (nla_put_u32(skb, NFQA_UID, htonl(cred->fsuid)))
>
> I'm hitting this compilation error here:
>
> net/netfilter/nfnetlink_queue_core.c: In function ‘nfqnl_put_sk_uidgid’:
> net/netfilter/nfnetlink_queue_core.c:308:4: error: aggregate value used where an integer was expected
>
> It seems that in recent kernels you have to use:
>
> from_kuid_munged(&init_user_ns, cred->fsuid);
>
> to retrieve the integer that represents the uid.
>
> Please,
sorry, I left this sentence incomplete, I was telling... Please, test
your patches with current git trees :-). Thanks.
next prev parent reply other threads:[~2013-12-20 9:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-19 11:03 [PATCH v2 0/2] Add UID/GID info to NFQUEUE valentina.giusti
2013-12-19 11:03 ` [PATCH v2 1/2] netfilter_queue: enable UID/GID socket info retrieval valentina.giusti
2013-12-19 11:43 ` Florian Westphal
2013-12-20 9:26 ` Pablo Neira Ayuso
2013-12-20 9:29 ` Pablo Neira Ayuso [this message]
2013-12-20 9:45 ` Valentina Giusti
2013-12-20 11:18 ` Valentina Giusti
2013-12-20 12:06 ` Florian Westphal
2013-12-19 11:03 ` [PATCH v2 2/2] libnetfilter_queue: add support for UID/GID socket info valentina.giusti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131220092926.GA9275@localhost \
--to=pablo@netfilter.org \
--cc=daniel.wagner@bmw-carit.de \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=fw@strlen.de \
--cc=jpa@google.com \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=tgraf@redhat.com \
--cc=valentina.giusti@bmw-carit.de \
--cc=valentina.giusti@oss.bmw-carit.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).