linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ipv4: ensure rcu_read_lock() in cipso_v4_error()
@ 2020-02-21 11:28 Matteo Croce
  2020-02-21 21:18 ` Paul Moore
  2020-02-23  5:47 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Matteo Croce @ 2020-02-21 11:28 UTC (permalink / raw)
  To: netdev, linux-security-module
  Cc: linux-kernel, Paul Moore, David S. Miller, Alexey Kuznetsov,
	Hideaki YOSHIFUJI, Jakub Kicinski, Guillaume Nault, Eric Dumazet

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")
Suggested-by: Guillaume Nault <gnault@redhat.com>
Signed-off-by: Matteo Croce <mcroce@redhat.com>
---
 net/ipv4/cipso_ipv4.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index 376882215919..0bd10a1f477f 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] ipv4: ensure rcu_read_lock() in cipso_v4_error()
  2020-02-21 11:28 [PATCH net] ipv4: ensure rcu_read_lock() in cipso_v4_error() Matteo Croce
@ 2020-02-21 21:18 ` Paul Moore
  2020-02-23  5:47 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Moore @ 2020-02-21 21:18 UTC (permalink / raw)
  To: Matteo Croce
  Cc: netdev, linux-security-module, linux-kernel, David S. Miller,
	Alexey Kuznetsov, Hideaki YOSHIFUJI, Jakub Kicinski,
	Guillaume Nault, Eric Dumazet

On Fri, Feb 21, 2020 at 6:28 AM Matteo Croce <mcroce@redhat.com> wrote:
>
> 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")
> Suggested-by: Guillaume Nault <gnault@redhat.com>
> Signed-off-by: Matteo Croce <mcroce@redhat.com>
> ---
>  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.

Acked-by: Paul Moore <paul@paul-moore.com>

> diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
> index 376882215919..0bd10a1f477f 100644
> --- a/net/ipv4/cipso_ipv4.c
> +++ b/net/ipv4/cipso_ipv4.c
> @@ -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

-- 
paul moore
www.paul-moore.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] ipv4: ensure rcu_read_lock() in cipso_v4_error()
  2020-02-21 11:28 [PATCH net] ipv4: ensure rcu_read_lock() in cipso_v4_error() Matteo Croce
  2020-02-21 21:18 ` Paul Moore
@ 2020-02-23  5:47 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-02-23  5:47 UTC (permalink / raw)
  To: mcroce
  Cc: netdev, linux-security-module, linux-kernel, paul, kuznet,
	yoshfuji, kuba, gnault, eric.dumazet

From: Matteo Croce <mcroce@redhat.com>
Date: Fri, 21 Feb 2020 12:28:38 +0100

> 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")
> Suggested-by: Guillaume Nault <gnault@redhat.com>
> Signed-off-by: Matteo Croce <mcroce@redhat.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-23  5:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-21 11:28 [PATCH net] ipv4: ensure rcu_read_lock() in cipso_v4_error() Matteo Croce
2020-02-21 21:18 ` Paul Moore
2020-02-23  5:47 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).