batman-adv: compat: fix null pointer exception for kernels < 3.9
PATCH 1/1 batman-adv: compat: fix null pointer exception for kernels < 3.9
The compat code of the new multicast patchset leads to null pointer derefernces for kernels 3.9 in netdev_master_upper_dev_get_rcu(). This is because the initially NULL is assigned to upper, which is equal to dev. dev is dereferenced one line later, though, leading to a crash.
Fixing this by assigning NULL only when we are sure that the according pointer is not going to be dereferenced anymore.
Introduced by: 532cadf26cfbb1099ef31fae9ccafcbbfc37b9b5 ("batman-adv: Multicast Listener Announcements via Translation Table")
--- compat.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
compat.h +6 -4
@@ -162,12 +162,13 @@ static inline int batadv_param_set_copystring(const char *val,#define NET_ADDR_RANDOM 0#define netdev_master_upper_dev_get_rcu (dev) \ - NULL; \ + upper; \ if (dev->br_port ? 1 : 0) { \ rcu_read_unlock(); \ dev_hold(dev); \ return dev; \ - } + } else \ + dev = NULL;#endif /* < KERNEL_VERSION(2, 6, 36) */
@@ -371,12 +372,13 @@ static int __batadv_interface_tx(struct sk_buff *skb, \#ifndef netdev_master_upper_dev_get_rcu#define netdev_master_upper_dev_get_rcu (dev) \ - NULL; \ + upper; \ if (dev->priv_flags & IFF_BRIDGE_PORT) { \ rcu_read_unlock(); \ dev_hold(dev); \ return dev; \ - } + } else \ + dev = NULL;#endif /* netdev_master_upper_dev_get_rcu */
Signature · 1 line
1.7.10.4
Quoted 4 lines · Linus Lüssing
compat.h +0
-0@@ -371,12 +372,13 @@ static int __batadv_interface_tx(struct sk_buff *skb, \#ifndef netdev_master_upper_dev_get_rcu#define netdev_master_upper_dev_get_rcu (dev) \
compat.h static int __batadv_interface_tx(struct sk_buff *skb, \ · line 382
Quoted 10 lines
compat.h +3
-2-NULL ; \ + upper; \if (dev->priv_flags &IFF_BRIDGE_PORT ) { \rcu_read_unlock (); \dev_hold (dev); \return dev; \ - } + }else \ + dev =NULL ;
Following your patch the code in multicast.c will become:
172 do {
173 upper = upper;
if (dev->priv_flags & IFF_BRIDGE_PORT) {
rcu_read_unlock();
dev_hold(dev);
return dev;
} else
dev = NULL;174 } while (upper && !(upper->priv_flags & IFF_EBRIDGE));
am I wrong or this is going to break the while? I think there is a missing '}'.
What about a simplified version like this:
#define netdev_master_upper_dev_get_rcu(dev) \
- NULL; \
- if (dev->priv_flags & IFF_BRIDGE_PORT) { \
+ ({if (dev->priv_flags & IFF_BRIDGE_PORT) { \
rcu_read_unlock(); \
dev_hold(dev); \
return dev; \
- }
+ }\
+ NULL;})
Cheers,
Signature · 1 line
Antonio Quartulli
Quoted 26 lines · Antonio Quartulli
Quoted 4 lines · Linus Lüssing
compat.h +0
-0@@ -371,12 +372,13 @@ static int __batadv_interface_tx(struct sk_buff *skb, \#ifndef netdev_master_upper_dev_get_rcu#define netdev_master_upper_dev_get_rcu (dev) \compat.h static int __batadv_interface_tx(struct sk_buff *skb, \ · line 382
Quoted 10 lines
compat.h +3
-2-NULL ; \ + upper; \if (dev->priv_flags &IFF_BRIDGE_PORT ) { \rcu_read_unlock (); \dev_hold (dev); \return dev; \ - } + }else \ + dev =NULL ;Following your patch the code in
multicast.cwill become:172 do {
173 upper = upper; if (dev->priv_flags & IFF_BRIDGE_PORT) { rcu_read_unlock(); dev_hold(dev); return dev; } else dev = NULL;
Quoted 5 lines
174 } while (upper && !(upper->priv_flags &
IFF_EBRIDGE));am I wrong or this is going to break the while? I think there is a missing '}'.
I was wrong. I just dreamt of a '{' after "else".
Forget about this comment.
Cheers,
Signature · 1 line
Antonio Quartulli
Marek Lindner
AppliedQuoted 8 lines · On Sunday 16 February 2014 13:01:02 Linus Lüssing wrote:
The compat code of the new multicast patchset leads to null pointer derefernces for kernels 3.9 in
netdev_master_upper_dev_get_rcu(). This is because the initially NULL is assigned to upper, which is equal to dev. dev is dereferenced one line later, though, leading to a crash.Fixing this by assigning NULL only when we are sure that the according pointer is not going to be dereferenced anymore.
Quoted 8 lines
Introduced by:
532cadf26cfbb1099ef31fae9ccafcbbfc37b9b5("batman-adv: Multicast Listener Announcements via Translation Table")Reported-by Marek Lindner <[email protected]>Signed-off-by Linus Lüssing <[email protected]>--- compat.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Applied in revision 65d8217.
Thanks,
Marek