b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven.eckelmann@gmx.de>
To: b.a.t.m.a.n@open-mesh.net
Subject: [B.A.T.M.A.N.] [PATCH 3/3] [batman] Word-Align char buffer which are later casted to larger data types
Date: Thu, 28 May 2009 13:36:59 +0200	[thread overview]
Message-ID: <1243510619-10749-2-git-send-email-sven.eckelmann@gmx.de> (raw)
In-Reply-To: <4313f3060905190727x279f2d0boc4e74e4df6e821bc@mail.gmail.com>

Buffers of char must not be special aligned on all architecture, but
if the compiler will not know about missing alignment of the larger
data type it generate unsafe instructions as it assumes that they
are word aligned.

Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 batman/batman.h       |    1 +
 batman/linux/route.c  |    6 +++---
 batman/posix/tunnel.c |    2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/batman/batman.h b/batman/batman.h
index 1cc5896..d6b00cf 100644
--- a/batman/batman.h
+++ b/batman/batman.h
@@ -152,6 +152,7 @@
 
 
 #define BATMANUNUSED(x) (x)__attribute__((unused))
+#define ALIGN_WORD __attribute__ ((aligned(sizeof(TYPE_OF_WORD))))
 
 
 
diff --git a/batman/linux/route.c b/batman/linux/route.c
index 4d46955..0c7b932 100644
--- a/batman/linux/route.c
+++ b/batman/linux/route.c
@@ -185,7 +185,7 @@ void add_del_route(uint32_t dest, uint8_t netmask, uint32_t router, uint32_t src
 		struct rtmsg rtm;
 		char buff[4 * (sizeof(struct rtattr) + 4)];
 	} *req;
-	char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
+	char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
 
 	iov.iov_base = buf;
 	iov.iov_len  = sizeof(buf);
@@ -369,7 +369,7 @@ void add_del_rule(uint32_t network, uint8_t netmask, int8_t rt_table, uint32_t p
 		struct rtmsg rtm;
 		char buff[2 * (sizeof(struct rtattr) + 4)];
 	} *req;
-	char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
+	char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
 
 	iov.iov_base = buf;
 	iov.iov_len  = sizeof(buf);
@@ -634,7 +634,7 @@ int flush_routes_rules(int8_t is_rule)
 	struct req_s {
 		struct rtmsg rtm;
 	} *req;
-	char req_buf[NLMSG_LENGTH(sizeof(struct req_s))];
+	char req_buf[NLMSG_LENGTH(sizeof(struct req_s))] ALIGN_WORD;
 
 	struct rtattr *rtap;
 
diff --git a/batman/posix/tunnel.c b/batman/posix/tunnel.c
index 4263794..1cfb501 100644
--- a/batman/posix/tunnel.c
+++ b/batman/posix/tunnel.c
@@ -567,7 +567,7 @@ void *gw_listen(void *BATMANUNUSED(arg)) {
 	unsigned char buff[1501];
 	int32_t res, max_sock, buff_len, tun_fd, tun_ifi;
 	uint32_t addr_len, client_timeout, current_time;
-	uint8_t my_tun_ip[4], next_free_ip[4];
+	uint8_t my_tun_ip[4] ALIGN_WORD, next_free_ip[4] ALIGN_WORD;
 	struct hashtable_t *wip_hash, *vip_hash;
 	struct list_head_first free_ip_list;
 	fd_set wait_sockets, tmp_wait_sockets;
-- 
1.6.3.1


      parent reply	other threads:[~2009-05-28 11:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-19 14:27 [B.A.T.M.A.N.] Kernel crashes with batgat installed Nathan Wharton
2009-05-19 19:21 ` Sven Eckelmann
2009-05-19 20:38   ` Nathan Wharton
2009-05-20  1:30     ` Marek Lindner
2009-05-20 14:34       ` Nathan Wharton
2009-05-20 16:10         ` Marek Lindner
2009-05-20 17:01           ` Nathan Wharton
2009-05-20 19:02             ` Marek Lindner
2009-05-20 19:39               ` Nathan Wharton
2009-05-28 10:40 ` [B.A.T.M.A.N.] [PATCH] [batman] Add padding around allocation debugger structures Sven Eckelmann
2009-05-29  7:02   ` Marek Lindner
2009-05-29 14:00     ` Nathan Wharton
2009-06-01 16:44       ` Sven Eckelmann
2009-06-01 18:03         ` Nathan Wharton
2009-06-01 19:35           ` Sven Eckelmann
2009-06-01 21:50             ` Nathan Wharton
2009-06-02  4:36             ` Marek Lindner
2009-06-02 17:50               ` [B.A.T.M.A.N.] " Sven Eckelmann
2009-06-02 17:56                 ` [B.A.T.M.A.N.] [PATCH] [batman] Align pointers in hna list elements Sven Eckelmann
2009-06-02 18:56                   ` Nathan Wharton
2009-06-03 10:39                   ` [B.A.T.M.A.N.] [PATCHv2] " Sven Eckelmann
2009-06-03 11:16                     ` Marek Lindner
2009-05-28 11:36 ` [B.A.T.M.A.N.] [PATCH 2/3] [batman] Make TYPE_OF_WORD the largest integral type Sven Eckelmann
2009-05-28 11:36 ` Sven Eckelmann [this message]

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=1243510619-10749-2-git-send-email-sven.eckelmann@gmx.de \
    --to=sven.eckelmann@gmx.de \
    --cc=b.a.t.m.a.n@open-mesh.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 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).