Skip to content

Commit

Permalink
netfilter: xtables: fix build failure from COMPAT_XT_ALIGN outside CO…
Browse files Browse the repository at this point in the history
…NFIG_COMPAT

The patch in the Fixes references COMPAT_XT_ALIGN in the definition
of XT_DATA_TO_USER, outside an #ifdef CONFIG_COMPAT block.

Split XT_DATA_TO_USER into separate compat and non compat variants and
define the first inside an CONFIG_COMPAT block.

This simplifies both variants by removing branches inside the macro.

Fixes: 324318f ("netfilter: xtables: zero padding in data_to_user")
Reported-by: Stephen Rothwell <[email protected]>
Signed-off-by: Willem de Bruijn <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
wdebruij authored and ummakynes committed May 18, 2017
1 parent c953d63 commit 751a9c7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions net/netfilter/x_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,25 @@ int xt_data_to_user(void __user *dst, const void *src,
}
EXPORT_SYMBOL_GPL(xt_data_to_user);

#define XT_DATA_TO_USER(U, K, TYPE, C_SIZE) \
#define XT_DATA_TO_USER(U, K, TYPE) \
xt_data_to_user(U->data, K->data, \
K->u.kernel.TYPE->usersize, \
C_SIZE ? : K->u.kernel.TYPE->TYPE##size, \
C_SIZE ? COMPAT_XT_ALIGN(C_SIZE) : \
XT_ALIGN(K->u.kernel.TYPE->TYPE##size))
K->u.kernel.TYPE->TYPE##size, \
XT_ALIGN(K->u.kernel.TYPE->TYPE##size))

int xt_match_to_user(const struct xt_entry_match *m,
struct xt_entry_match __user *u)
{
return XT_OBJ_TO_USER(u, m, match, 0) ||
XT_DATA_TO_USER(u, m, match, 0);
XT_DATA_TO_USER(u, m, match);
}
EXPORT_SYMBOL_GPL(xt_match_to_user);

int xt_target_to_user(const struct xt_entry_target *t,
struct xt_entry_target __user *u)
{
return XT_OBJ_TO_USER(u, t, target, 0) ||
XT_DATA_TO_USER(u, t, target, 0);
XT_DATA_TO_USER(u, t, target);
}
EXPORT_SYMBOL_GPL(xt_target_to_user);

Expand Down Expand Up @@ -614,6 +613,12 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
}
EXPORT_SYMBOL_GPL(xt_compat_match_from_user);

#define COMPAT_XT_DATA_TO_USER(U, K, TYPE, C_SIZE) \
xt_data_to_user(U->data, K->data, \
K->u.kernel.TYPE->usersize, \
C_SIZE, \
COMPAT_XT_ALIGN(C_SIZE))

int xt_compat_match_to_user(const struct xt_entry_match *m,
void __user **dstptr, unsigned int *size)
{
Expand All @@ -629,7 +634,7 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
if (match->compat_to_user((void __user *)cm->data, m->data))
return -EFAULT;
} else {
if (XT_DATA_TO_USER(cm, m, match, msize - sizeof(*cm)))
if (COMPAT_XT_DATA_TO_USER(cm, m, match, msize - sizeof(*cm)))
return -EFAULT;
}

Expand Down Expand Up @@ -975,7 +980,7 @@ int xt_compat_target_to_user(const struct xt_entry_target *t,
if (target->compat_to_user((void __user *)ct->data, t->data))
return -EFAULT;
} else {
if (XT_DATA_TO_USER(ct, t, target, tsize - sizeof(*ct)))
if (COMPAT_XT_DATA_TO_USER(ct, t, target, tsize - sizeof(*ct)))
return -EFAULT;
}

Expand Down

0 comments on commit 751a9c7

Please sign in to comment.