Re: [PATCH nf] netfilter: ebtables: compat: un-break 32bit setsockopt when no rules are present

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Francesco Ruggeri <fruggeri@xxxxxxxxxx> wrote:
> > I suspect we should always call xt_compat_init_offsets() and make it
> > handle a 0 size arg, just to rule out a missing call to
> > xt_compat_init_offsets() as a problem source.
> 
> Sorry for not being very helpful, but I am not really familiar with
> this code. I saw this crash once but I have not been able
> to reproduce it.
> A few other modules seem to use xt_compat_init_offsets(). You
> think we should handle a 0 size argument, rather than returning
> -EINVAL, for all of them? How should we handle it, just reset
> number/cur/compat_tab?

What about this?

diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1832,20 +1832,25 @@ static int compat_calc_entry(const struct ebt_entry *e,
 	return 0;
 }
 
+static int ebt_compat_init_offsets(unsigned int number)
+{
+	if (number == 0)
+		number = 1;
+
+	return xt_compat_init_offsets(NFPROTO_BRIDGE, number);
+}
 
 static int compat_table_info(const struct ebt_table_info *info,
 			     struct compat_ebt_replace *newinfo)
 {
 	unsigned int size = info->entries_size;
 	const void *entries = info->entries;
+	int ret;
 
 	newinfo->entries_size = size;
-	if (info->nentries) {
-		int ret = xt_compat_init_offsets(NFPROTO_BRIDGE,
-						 info->nentries);
-		if (ret)
-			return ret;
-	}
+	ret = ebt_compat_init_offsets(info->nentries);
+	if (ret)
+		return ret;
 
 	return EBT_ENTRY_ITERATE(entries, size, compat_calc_entry, info,
 							entries, newinfo);
@@ -2293,11 +2298,9 @@ static int compat_do_replace(struct net *net, void __user *user,
 
 	xt_compat_lock(NFPROTO_BRIDGE);
 
-	if (tmp.nentries) {
-		ret = xt_compat_init_offsets(NFPROTO_BRIDGE, tmp.nentries);
-		if (ret < 0)
-			goto out_unlock;
-	}
+	ret = ebt_compat_init_offsets(tmp.nentries);
+	if (ret < 0)
+		goto out_unlock;
 
 	ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
 	if (ret < 0)



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux