All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Harald Welte <laforge@netfilter.org>
Cc: Pablo Neira <pablo@eurodev.net>,
	Netfilter Development Mailinglist
	<netfilter-devel@lists.netfilter.org>
Subject: Re: [PATCH] CTA_PROTO_NUM is u_int8_t not u_int16_t (was Re: CTA_PROTO_NUM u_int8_t or u_int16_t)
Date: Fri, 25 Nov 2005 00:33:27 +0100	[thread overview]
Message-ID: <43864DC7.6060109@trash.net> (raw)
In-Reply-To: <20051124202125.GX31478@sunbeam.de.gnumonks.org>

Harald Welte wrote:
> Sorry, forget that other patch.
> 
> The only way how we can thoroughly solve (and avoid) this problem, also
> for future cases, is to behave like 'real' TLV parsers (e.g. ASN1).
> 
> That is, for any kind of numeric values, we don't make an assumption
> that the attribute has a certain fixed size.  Instead, we derive the
> (u8/u16/u32/u64) size from the length of the attribute, i.e.
> NFA_PAYLOAD() is 1/2/4/8 bytes long.
> 
> This is a quick and dirty patch to demonstrate what I mean:
> 
> =====
> 
> diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c
> --- a/net/ipv4/netfilter/ip_conntrack_netlink.c
> +++ b/net/ipv4/netfilter/ip_conntrack_netlink.c
> @@ -502,12 +502,13 @@ ctnetlink_parse_tuple_ip(struct nfattr *
>  }
>  
>  static const size_t cta_min_proto[CTA_PROTO_MAX] = {
> -	[CTA_PROTO_NUM-1]	= sizeof(u_int16_t),
> +	[CTA_PROTO_NUM-1]	= sizeof(u_int8_t),
>  	[CTA_PROTO_SRC_PORT-1]	= sizeof(u_int16_t),
>  	[CTA_PROTO_DST_PORT-1]	= sizeof(u_int16_t),
>  	[CTA_PROTO_ICMP_TYPE-1]	= sizeof(u_int8_t),
>  	[CTA_PROTO_ICMP_CODE-1]	= sizeof(u_int8_t),
>  	[CTA_PROTO_ICMP_ID-1]	= sizeof(u_int16_t),
> +	[CTA_PROTO-1]		= sizeof(u_int8_t),
>  };
>  
>  static inline int
> @@ -527,7 +528,18 @@ ctnetlink_parse_tuple_proto(struct nfatt
>  
>  	if (!tb[CTA_PROTO_NUM-1])
>  		return -EINVAL;
> -	tuple->dst.protonum = *(u_int16_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
> +
> +	switch (NFA_PAYLOAD(tb[CTA_PROTO_NUM-1]))
> +	case sizeof(u_int8_t):
> +		tuple->dst.protonum = 
> +				*(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
> +		break;
> +	case sizeof(u_int16_t):
> +		tuple->dst.protonum = 
> +				*(u_int16_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]);
> +	default:
> +		return -EINVAL;
> +	}
>  
>  	proto = ip_conntrack_proto_find_get(tuple->dst.protonum);
> 
> =====
> 
> Obviously, this needs to be moved into a nfnetlink core funciton,
> something like a function nfattr_parse_number() that would then be
> called from all places that parse a number.
> 
> Userspace parsers (libnetfilter_conntrack) would have to introduce the
> same semantics.

That won't work for this case since usually u_int16_t's are encoded
in network byte order but in this case its always host byte order.

> It might be a bit too much overhead, I'm not really decided yet.  But in
> the end, if everybody plays according to that rule, we don't have any
> such issues in the future.
> 
> Comments?

I think just the first patch is fine. I really hope we don't find
more of these.

  parent reply	other threads:[~2005-11-24 23:33 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-21 14:40 CTA_PROTO_NUM u_int8_t or u_int16_t Krzysztof Oledzki
2005-11-21 14:53 ` Pablo Neira
2005-11-21 17:03   ` Patrick McHardy
2005-11-21 17:48     ` Pablo Neira
2005-11-21 21:26       ` Krzysztof Oledzki
2005-11-22  4:42       ` Patrick McHardy
2005-11-22 19:04         ` [PATCH] CTA_PROTO_NUM is u_int8_t not u_int16_t (was Re: CTA_PROTO_NUM u_int8_t or u_int16_t) Pablo Neira
2005-11-22 20:29           ` Krzysztof Oledzki
2005-11-22 22:06             ` Harald Welte
2005-11-23  1:06               ` Patrick McHardy
2005-11-23  1:15               ` Pablo Neira
2005-11-23  9:47                 ` Patrick McHardy
2005-11-23 10:31                   ` Krzysztof Oledzki
2005-11-24 20:07                     ` Harald Welte
2005-11-24 20:21                       ` Harald Welte
2005-11-24 23:24                         ` Krzysztof Oledzki
2005-11-24 23:33                         ` Patrick McHardy [this message]
2005-11-24 23:54                           ` Krzysztof Oledzki
2005-11-25  0:11                             ` Patrick McHardy
2005-11-25  0:22                               ` Pablo Neira
2005-11-25  0:26                                 ` Krzysztof Oledzki
2005-11-25  0:28                               ` Krzysztof Oledzki
2005-11-25  8:44                             ` Harald Welte
2005-11-25  9:23                               ` Krzysztof Oledzki
2005-11-25 11:09                                 ` Harald Welte
2005-11-25 13:25                                 ` Patrick McHardy
2005-11-26  0:16                                   ` Pablo Neira Ayuso
2005-11-27 22:28                                     ` Krzysztof Oledzki
2005-11-29  4:09                                       ` Harald Welte
2005-11-29 23:07                                         ` Patrick McHardy
2005-12-04  3:31                                           ` Pablo Neira Ayuso
2005-12-04 16:05                                             ` Patrick McHardy
2005-12-04 16:35                                               ` Patrick McHardy
2005-12-04 19:48                                               ` [PATCH] CTA_PROTO_NUM is u_int8_t not u_int16_t David S. Miller
2005-12-04 20:02                                                 ` Patrick McHardy
2005-12-04 20:20                                                   ` David S. Miller
2005-12-13  9:56                                           ` [PATCH] CTA_PROTO_NUM is u_int8_t not u_int16_t (was Re: CTA_PROTO_NUM u_int8_t or u_int16_t) Krzysztof Oledzki
2005-12-13 11:22                                             ` Patrick McHardy
2005-12-13 11:32                                               ` Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2005-12-13 11:26 [PATCH] CTA_PROTO_NUM is u_int8_t not u_int16_t (was Re: CTA_PROTO_NUM u_int8_t or u_int16_t)] Patrick McHardy
2005-12-13 11:51 ` Krzysztof Oledzki

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=43864DC7.6060109@trash.net \
    --to=kaber@trash.net \
    --cc=laforge@netfilter.org \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=pablo@eurodev.net \
    /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 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.