From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Jan Engelhardt <jengelh@medozas.de>
Cc: Pierre Chifflier <chifflier@edenwall.com>,
netfilter-devel@vger.kernel.org, eleblond@edenwall.com
Subject: libnetfilter_conntrack alignment issue [was Re: [PATCH 1/2] Add new input plugin UNIXSOCK]
Date: Fri, 05 Mar 2010 11:25:05 +0100 [thread overview]
Message-ID: <4B90DC01.3050306@netfilter.org> (raw)
In-Reply-To: <alpine.LSU.2.01.1003031841130.23267@obet.zrqbmnf.qr>
[-- Attachment #1: Type: text/plain, Size: 1310 bytes --]
Jan Engelhardt wrote:
> On Monday 2010-03-01 20:33, Pablo Neira Ayuso wrote:
>
>>>>>>> +#define ALIGN_SIZE 8
>>>>>> Minor question: why align this to 64 bits?
>>>>> I originally used an alignment to 32 bits, but Jan noticed it would
>>>>> break if using options/values on 64 bits (and a test confirmed that). I
>>>>> took 64 bits as the biggest allowed value for integers.
>>>> I would need to look into this in more detail, not sure where the
>>>> problem is. I think that you can use something like `struct nlattr' (see
>>>> include/linux/netlink.h) and then nla_put() to add attributes in the TLV
>>>> format (see lib/nlattr.c). Those are align-safe. I'm using something
>>>> similar for conntrackd for the synchronization messages (src/build.c and
>>>> src/parse.c).
>
> If they are align-safe, what's this? :-)
Could you tell me where did I say that libnetfilter_conntrack is using
those functions that I recommended?
> 18:41 ares:/home/jengelh # conntrack -L
> Bus error
> 18:41 ares:/home/jengelh # file `which conntrack`
> /usr/sbin/conntrack: ELF 32-bit MSB executable, SPARC32PLUS, V8+ Required,
> version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.4,
> not stripped
The following patch should fix the problem that you are reporting. Let
me know if you have more issues.
[-- Attachment #2: fix.patch --]
[-- Type: text/x-patch, Size: 2264 bytes --]
parse: fix access to u64 attributes in netlink messages
From: Pablo Neira Ayuso <pablo@netfilter.org>
This patch fixes parsing of 64 bits attributes (that are unaligned)
in ctnetlink. It would be better to add nfnl_get_uX() functions
similar to those in include/net/netlink.h to libnfnetlink to avoid
this sort of errors.
Reported-by: Jan Engelhardt <jengelh@medozas.es>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/conntrack/parse.c | 30 +++++++++++++++++++-----------
1 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/conntrack/parse.c b/src/conntrack/parse.c
index 0e0cd58..60dabe4 100644
--- a/src/conntrack/parse.c
+++ b/src/conntrack/parse.c
@@ -276,9 +276,11 @@ static void __parse_protoinfo_dccp(const struct nfattr *attr,
set_bit(ATTR_DCCP_ROLE, ct->set);
}
if (tb[CTA_PROTOINFO_DCCP_SEQ-1]) {
- ct->protoinfo.dccp.handshake_seq =
- __be64_to_cpu(*(u_int64_t *)
- NFA_DATA(tb[CTA_PROTOINFO_DCCP_SEQ-1]));
+ u_int64_t tmp;
+ memcpy(&tmp,
+ NFA_DATA(tb[CTA_PROTOINFO_DCCP_SEQ-1]),
+ sizeof(tmp));
+ ct->protoinfo.dccp.handshake_seq = __be64_to_cpu(tmp);
set_bit(ATTR_DCCP_HANDSHAKE_SEQ, ct->set);
}
}
@@ -314,10 +316,13 @@ static void __parse_counters(const struct nfattr *attr,
= ntohl(*(u_int32_t *)
NFA_DATA(tb[CTA_COUNTERS32_PACKETS-1]));
- if (tb[CTA_COUNTERS_PACKETS-1])
- ct->counters[dir].packets
- = __be64_to_cpu(*(u_int64_t *)
- NFA_DATA(tb[CTA_COUNTERS_PACKETS-1]));
+ if (tb[CTA_COUNTERS_PACKETS-1]) {
+ u_int64_t tmp;
+ memcpy(&tmp,
+ NFA_DATA(tb[CTA_COUNTERS_PACKETS-1]),
+ sizeof(tmp));
+ ct->counters[dir].packets = __be64_to_cpu(tmp);
+ }
switch(dir) {
case __DIR_ORIG:
@@ -335,10 +340,13 @@ static void __parse_counters(const struct nfattr *attr,
= ntohl(*(u_int32_t *)
NFA_DATA(tb[CTA_COUNTERS32_BYTES-1]));
- if (tb[CTA_COUNTERS_BYTES-1])
- ct->counters[dir].bytes
- = __be64_to_cpu(*(u_int64_t *)
- NFA_DATA(tb[CTA_COUNTERS_BYTES-1]));
+ if (tb[CTA_COUNTERS_BYTES-1]) {
+ u_int64_t tmp;
+ memcpy(&tmp,
+ NFA_DATA(tb[CTA_COUNTERS_BYTES-1]),
+ sizeof(tmp));
+ ct->counters[dir].bytes = __be64_to_cpu(tmp);
+ }
switch(dir) {
case __DIR_ORIG:
next prev parent reply other threads:[~2010-03-05 10:25 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-26 20:54 [ULOGD2] UNIXSOCK plugin (v5) Pierre Chifflier
2010-02-26 20:54 ` [PATCH 1/2] Add new input plugin UNIXSOCK Pierre Chifflier
2010-02-27 13:55 ` Pablo Neira Ayuso
2010-02-28 14:06 ` Pierre Chifflier
2010-02-28 16:28 ` Pablo Neira Ayuso
2010-02-28 17:29 ` Jan Engelhardt
2010-02-28 18:05 ` Pierre Chifflier
2010-03-01 19:33 ` Pablo Neira Ayuso
2010-03-01 22:16 ` [ULOGD2] UNIXSOCK plugin (v6) Pierre Chifflier
2010-03-01 22:16 ` [PATCH 1/2] Add new input plugin UNIXSOCK Pierre Chifflier
2010-03-01 22:16 ` [PATCH 2/2] Add helper script pcap2ulog Pierre Chifflier
2010-03-03 17:42 ` [PATCH 1/2] Add new input plugin UNIXSOCK Jan Engelhardt
2010-03-03 18:14 ` Jan Engelhardt
2010-03-05 10:25 ` Pablo Neira Ayuso [this message]
2010-03-07 19:30 ` libnetfilter_conntrack alignment issue [was Re: [PATCH 1/2] Add new input plugin UNIXSOCK] Jan Engelhardt
2010-03-05 11:15 ` [PATCH 1/2] Add new input plugin UNIXSOCK Patrick McHardy
2010-03-05 17:10 ` Pablo Neira Ayuso
2010-03-08 11:13 ` Patrick McHardy
2010-02-26 20:54 ` [PATCH 2/2] Add helper script pcap2ulog Pierre Chifflier
2010-02-27 10:46 ` [ULOGD2] UNIXSOCK plugin (v5) Eric Leblond
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=4B90DC01.3050306@netfilter.org \
--to=pablo@netfilter.org \
--cc=chifflier@edenwall.com \
--cc=eleblond@edenwall.com \
--cc=jengelh@medozas.de \
--cc=netfilter-devel@vger.kernel.org \
/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).