All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Heinz <creatix@hipac.org>
To: Anders Fugmann <afu@fugmann.dhs.org>
Cc: Laszlo Valko <valko@linux.karinthy.hu>,
	netfilter-devel@lists.netfilter.org
Subject: Re: Comments about IPT_ALIGN
Date: Sun, 26 Jan 2003 14:58:02 +0100	[thread overview]
Message-ID: <3E33E96A.5080903@hipac.org> (raw)
In-Reply-To: 3E33C665.9080106@fugmann.dhs.org

Hi Anders

You wrote:
> Does this not pose an interresting problem?
> What happens if userspace is 32bit, and kernel space is 64bit, when the 
> elements of the structure changes size doe to conversion?
> Eg:
> struct x {
>   int a;
>   long int b;
>   int c;
> }
> 
> In 32bit userspace, x->a would have offset 0, x->b would have offset 4 
> and x->c would have offset 8. But in 64bit kernel space, the long in 
> would be 64 bit, and so the offset changes: offset x->a = 0, offset x->b 
>  = 4, offset x->c = 12. 

As member b of struct x must be 8 byte aligned we have
offsetof(struct x, b) = 8 (which implies offsetof(struct x, c) = 16).

In general the alignment requirement for a type is inherited by the
struct members (recursively). Of course there may be architectures
where there are no alignment requirements at all, i.e.
__alignof__(x) == 1.

> The structure would then need a special 
> conversion from 32 bit userspace to 64 bit kernel space in order for 
> values in the struct to be accessed correctly. If this is true, then we 
> must only use type with welldifined sizes, that is sizes that does not 
> changes from userspace to kernel space.

Actually this is not true for some existing targets and matches, e.g.:

     - ULOG: struct ipt_ulog_info {
                     unsigned int nl_group;
                     size_t copy_range;
                     size_t qthreshold;
                     char prefix[ULOG_PREFIX_LEN];
             };
     - MARK: struct ipt_mark_info {
                     unsigned long mark, mask;
                     u_int8_t invert;
             };
     - limit: struct ipt_rateinfo {
                      u_int32_t avg;    /* Average secs between packets 
* scale */
                      u_int32_t burst;  /* Period multiplier for upper 
limit. */
                     /* Used internally by the kernel */
                     unsigned long prev;
                     u_int32_t credit;
                     u_int32_t credit_cap, cost;

                     /* Ugly, ugly fucker. */
                     struct ipt_rateinfo *master;
              };

       The unsigned long prev in the middle does not hurt because it
       is automatically 8 byte aligned by avg and burst. Because
       the pointer (master) is at the end of the struct it does not
       cause any problems except that the whole struct must be
       aligned correctly.

Since I assume that ULOG and MARK work perfectly on sparc64 I must
be missing something that makes the internal memory layout of the
structs (i.e. the member offsets) equal in user and kernel space
(or my assumption is wrong ;-).

It would be kind if someone could fix my brainbug :)

BTW, pointers and arrays of pointers within target or match
structs can be forced to have the 8 byte alignment requirement
(on sparc64 and parisc64) by simply putting them into a
union: union {void *p; __u64 pad;}


Regards,

Thomas

  reply	other threads:[~2003-01-26 13:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-26  3:57 Comments about IPT_ALIGN Thomas Heinz
2003-01-26 11:01 ` Laszlo Valko
2003-01-26 11:28   ` Anders Fugmann
2003-01-26 13:58     ` Thomas Heinz [this message]
2003-01-26 14:26       ` Laszlo Valko
2003-01-26 16:50         ` Thomas Heinz
2003-01-26 19:31           ` Laszlo Valko
2003-01-31 11:51       ` Harald Welte
2003-01-26 14:22     ` Laszlo Valko
2003-01-26 18:05       ` Thomas Heinz
2003-01-26 19:43         ` Laszlo Valko
2003-01-26 23:09           ` Thomas Heinz
2003-01-27  0:43             ` Laszlo Valko
2003-01-27 10:33               ` Thomas Heinz
2003-01-31 11:57                 ` Harald Welte
2003-01-26 19:48         ` Thomas Heinz
2003-01-31 11:55       ` Harald Welte
2003-01-31 23:37         ` Laszlo Valko
2003-01-26 17:06   ` Thomas Heinz

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=3E33E96A.5080903@hipac.org \
    --to=creatix@hipac.org \
    --cc=afu@fugmann.dhs.org \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=valko@linux.karinthy.hu \
    /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.