Skip to contentSkip to conversation

ipv4: ensure rcu_read_lock() in cipso_v4_error()

PATCH In review Matteo Croce 3 participants 3 messages Feb 21, 2020 – Feb 23, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4: ensure rcu_read_lock() in cipso_v4_error()

Similarly to commit c543cb4a5f07 ("ipv4: ensure rcu_read_lock() in ipv4_link_failure()"), __ip_options_compile() must be called under rcu protection.

Fixes 3da1ed7ac398 ("net: avoid use IPCB in cipso_v4_error")
---
 net/ipv4/cipso_ipv4.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/ipv4/cipso_ipv4.c +6 -1
index 376882215919..0bd10a1f477f 100644
@@ -1724,6 +1724,7 @@ void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway)
 {
 	unsigned char optbuf[sizeof(struct ip_options) + 40];
 	struct ip_options *opt = (struct ip_options *)optbuf;
+	int res;
 
 	if (ip_hdr(skb)->protocol == IPPROTO_ICMP || error != -EACCES)
 		return;
@@ -1735,7 +1736,11 @@ void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway)
 
 	memset(opt, 0, sizeof(struct ip_options));
 	opt->optlen = ip_hdr(skb)->ihl*4 - sizeof(struct iphdr);
-	if (__ip_options_compile(dev_net(skb->dev), opt, skb, NULL))
+	rcu_read_lock();
+	res = __ip_options_compile(dev_net(skb->dev), opt, skb, NULL);
+	rcu_read_unlock();
+
+	if (res)
 		return;
 
 	if (gateway)
Signature · 1 line
2.24.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Matteo Croce

Similarly to commit c543cb4a5f07 ("ipv4: ensure rcu_read_lock() in ipv4_link_failure()"), __ip_options_compile() must be called under rcu protection.

Fixes 3da1ed7ac398 ("net: avoid use IPCB in cipso_v4_error")
---
 net/ipv4/cipso_ipv4.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

This seems consistent with the ipv4_link_failure() fix, even though ipv4_link_failure() has changed a bit since the fix.

Quoted 27 lines
net/ipv4/cipso_ipv4.c +6 -2
index 376882215919..0bd10a1f477f 100644
@@ -1724,6 +1724,7 @@ void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway)
 {
        unsigned char optbuf[sizeof(struct ip_options) + 40];
        struct ip_options *opt = (struct ip_options *)optbuf;
+       int res;
 
        if (ip_hdr(skb)->protocol == IPPROTO_ICMP || error != -EACCES)
                return;
@@ -1735,7 +1736,11 @@ void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway)
 
        memset(opt, 0, sizeof(struct ip_options));
        opt->optlen = ip_hdr(skb)->ihl*4 - sizeof(struct iphdr);
-       if (__ip_options_compile(dev_net(skb->dev), opt, skb, NULL))
+       rcu_read_lock();
+       res = __ip_options_compile(dev_net(skb->dev), opt, skb, NULL);
+       rcu_read_unlock();
+
+       if (res)
                return;
 
        if (gateway)
--

2.24.1

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#2 lore raw
In reply to Matteo Croce

From: Matteo Croce <[email protected]>
Date: Fri, 21 Feb 2020 12:28:38 +0100

Quoted 7 lines

Similarly to commit c543cb4a5f07 ("ipv4: ensure rcu_read_lock() in ipv4_link_failure()"), __ip_options_compile() must be called under rcu protection.

Fixes 3da1ed7ac398 ("net: avoid use IPCB in cipso_v4_error")

Applied and queued up for -stable, thanks.