netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
@ 2020-07-14  8:05 qiang.zhang
  2020-07-14 14:15 ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: qiang.zhang @ 2020-07-14  8:05 UTC (permalink / raw)
  To: jmaloy, davem, kuba, tuong.t.lien, eric.dumazet, ying.xue
  Cc: netdev, tipc-discussion, linux-kernel

From: Zhang Qiang <qiang.zhang@windriver.com>

CPU: 0 PID: 6801 Comm: syz-executor201 Not tainted 5.8.0-rc4-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine,
BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x18f/0x20d lib/dump_stack.c:118
 check_preemption_disabled+0x128/0x130 lib/smp_processor_id.c:48
 tipc_aead_tfm_next net/tipc/crypto.c:402 [inline]
 tipc_aead_encrypt net/tipc/crypto.c:639 [inline]
 tipc_crypto_xmit+0x80a/0x2790 net/tipc/crypto.c:1605
 tipc_bearer_xmit_skb+0x180/0x3f0 net/tipc/bearer.c:523
 tipc_enable_bearer+0xb1d/0xdc0 net/tipc/bearer.c:331
 __tipc_nl_bearer_enable+0x2bf/0x390 net/tipc/bearer.c:995
 __tipc_nl_compat_doit net/tipc/netlink_compat.c:361 [inline]
 tipc_nl_compat_doit+0x440/0x640 net/tipc/netlink_compat.c:383
 tipc_nl_compat_handle net/tipc/netlink_compat.c:1268 [inline]
 tipc_nl_compat_recv+0x4ef/0xb40 net/tipc/netlink_compat.c:1311
 genl_family_rcv_msg_doit net/netlink/genetlink.c:669 [inline]
 genl_family_rcv_msg net/netlink/genetlink.c:714 [inline]
 genl_rcv_msg+0x61d/0x980 net/netlink/genetlink.c:731
 netlink_rcv_skb+0x15a/0x430 net/netlink/af_netlink.c:2469
 genl_rcv+0x24/0x40 net/netlink/genetlink.c:742
 netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
 netlink_unicast+0x533/0x7d0 net/netlink/af_netlink.c:1329
 netlink_sendmsg+0x856/0xd90 net/netlink/af_netlink.c:1918
 sock_sendmsg_nosec net/socket.c:652 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:672
 ____sys_sendmsg+0x6e8/0x810 net/socket.c:2352
 ___sys_sendmsg+0xf3/0x170 net/socket.c:2406
 __sys_sendmsg+0xe5/0x1b0 net/socket.c:2439
 do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:384
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x4476a9
Code: Bad RIP value.
RSP: 002b:00007fff2b6d5168 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 000000000000

Fixes: fc1b6d6de2208 ("tipc: introduce TIPC encryption & authentication")
Reported-by: syzbot+263f8c0d007dc09b2dda@syzkaller.appspotmail.com
Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
---
 v1->v2:
 add fixes tags.

 net/tipc/crypto.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index 8c47ded2edb6..520af0afe1b3 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -399,9 +399,10 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
  */
 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
 {
-	struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
+	struct tipc_tfm **tfm_entry = get_cpu_ptr(aead->tfm_entry);
 
 	*tfm_entry = list_next_entry(*tfm_entry, list);
+	put_cpu_ptr(tfm_entry);
 	return (*tfm_entry)->tfm;
 }
 
-- 
2.24.1


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

* Re: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
  2020-07-14  8:05 [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code qiang.zhang
@ 2020-07-14 14:15 ` Eric Dumazet
  2020-07-15  2:12   ` 回复: " Zhang, Qiang
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2020-07-14 14:15 UTC (permalink / raw)
  To: qiang.zhang, jmaloy, davem, kuba, tuong.t.lien, eric.dumazet, ying.xue
  Cc: netdev, tipc-discussion, linux-kernel



On 7/14/20 1:05 AM, qiang.zhang@windriver.com wrote:
> From: Zhang Qiang <qiang.zhang@windriver.com>
> 
> CPU: 0 PID: 6801 Comm: syz-executor201 Not tainted 5.8.0-rc4-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine,
> BIOS Google 01/01/2011
> 
> Fixes: fc1b6d6de2208 ("tipc: introduce TIPC encryption & authentication")
> Reported-by: syzbot+263f8c0d007dc09b2dda@syzkaller.appspotmail.com
> Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
> ---
>  v1->v2:
>  add fixes tags.
> 
>  net/tipc/crypto.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> index 8c47ded2edb6..520af0afe1b3 100644
> --- a/net/tipc/crypto.c
> +++ b/net/tipc/crypto.c
> @@ -399,9 +399,10 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
>   */
>  static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
>  {
> -	struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
> +	struct tipc_tfm **tfm_entry = get_cpu_ptr(aead->tfm_entry);
>  
>  	*tfm_entry = list_next_entry(*tfm_entry, list);
> +	put_cpu_ptr(tfm_entry);
>  	return (*tfm_entry)->tfm;
>  }
>  
> 

You have not explained why this was safe.

This seems to hide a real bug.

Presumably callers of this function should have disable preemption, and maybe interrupts as well.

Right after put_cpu_ptr(tfm_entry), this thread could migrate to another cpu, and still access
data owned by the old cpu.



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

* 回复: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
  2020-07-14 14:15 ` Eric Dumazet
@ 2020-07-15  2:12   ` Zhang, Qiang
  2020-07-15  3:53     ` Tuong Tong Lien
  0 siblings, 1 reply; 7+ messages in thread
From: Zhang, Qiang @ 2020-07-15  2:12 UTC (permalink / raw)
  To: Eric Dumazet, jmaloy, davem, kuba, tuong.t.lien, Xue, Ying
  Cc: netdev, tipc-discussion, linux-kernel



________________________________________
发件人: Eric Dumazet <eric.dumazet@gmail.com>
发送时间: 2020年7月14日 22:15
收件人: Zhang, Qiang; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; tuong.t.lien@dektech.com.au; eric.dumazet@gmail.com; Xue, Ying
抄送: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
主题: Re: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code



On 7/14/20 1:05 AM, qiang.zhang@windriver.com wrote:
> From: Zhang Qiang <qiang.zhang@windriver.com>
>
> CPU: 0 PID: 6801 Comm: syz-executor201 Not tainted 5.8.0-rc4-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine,
> BIOS Google 01/01/2011
>
> Fixes: fc1b6d6de2208 ("tipc: introduce TIPC encryption & authentication")
> Reported-by: syzbot+263f8c0d007dc09b2dda@syzkaller.appspotmail.com
> Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
> ---
>  v1->v2:
>  add fixes tags.
>
>  net/tipc/crypto.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> index 8c47ded2edb6..520af0afe1b3 100644
> --- a/net/tipc/crypto.c
> +++ b/net/tipc/crypto.c
> @@ -399,9 +399,10 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
>   */
>  static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
>  {
> -     struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
> +     struct tipc_tfm **tfm_entry = get_cpu_ptr(aead->tfm_entry);
>
>       *tfm_entry = list_next_entry(*tfm_entry, list);
> +     put_cpu_ptr(tfm_entry);
>       return (*tfm_entry)->tfm;
>  }
>
>

> You have not explained why this was safe.
>
>  This seems to hide a real bug.
>
> Presumably callers of this function should have disable preemption, and maybe > interrupts as well.
>
>Right after put_cpu_ptr(tfm_entry), this thread could migrate to another cpu, >and still access
>data owned by the old cpu.

Thanks for you suggest, I will check code again.



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

* RE: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
  2020-07-15  2:12   ` 回复: " Zhang, Qiang
@ 2020-07-15  3:53     ` Tuong Tong Lien
  2020-07-15  5:27       ` 回复: " Zhang, Qiang
  0 siblings, 1 reply; 7+ messages in thread
From: Tuong Tong Lien @ 2020-07-15  3:53 UTC (permalink / raw)
  To: Zhang, Qiang, Eric Dumazet, jmaloy, davem, kuba, Xue, Ying
  Cc: netdev, tipc-discussion, linux-kernel



> -----Original Message-----
> From: Zhang, Qiang <Qiang.Zhang@windriver.com>
> Sent: Wednesday, July 15, 2020 9:13 AM
> To: Eric Dumazet <eric.dumazet@gmail.com>; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; Tuong Tong Lien
> <tuong.t.lien@dektech.com.au>; Xue, Ying <Ying.Xue@windriver.com>
> Cc: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
> Subject: 回复: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
> 
> 
> 
> ________________________________________
> 发件人: Eric Dumazet <eric.dumazet@gmail.com>
> 发送时间: 2020年7月14日 22:15
> 收件人: Zhang, Qiang; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; tuong.t.lien@dektech.com.au;
> eric.dumazet@gmail.com; Xue, Ying
> 抄送: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
> 主题: Re: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
> 
> 
> 
> On 7/14/20 1:05 AM, qiang.zhang@windriver.com wrote:
> > From: Zhang Qiang <qiang.zhang@windriver.com>
> >
> > CPU: 0 PID: 6801 Comm: syz-executor201 Not tainted 5.8.0-rc4-syzkaller #0
> > Hardware name: Google Google Compute Engine/Google Compute Engine,
> > BIOS Google 01/01/2011
> >
> > Fixes: fc1b6d6de2208 ("tipc: introduce TIPC encryption & authentication")
> > Reported-by: syzbot+263f8c0d007dc09b2dda@syzkaller.appspotmail.com
> > Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
> > ---
> >  v1->v2:
> >  add fixes tags.
> >
> >  net/tipc/crypto.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> > index 8c47ded2edb6..520af0afe1b3 100644
> > --- a/net/tipc/crypto.c
> > +++ b/net/tipc/crypto.c
> > @@ -399,9 +399,10 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
> >   */
> >  static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
> >  {
> > -     struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
> > +     struct tipc_tfm **tfm_entry = get_cpu_ptr(aead->tfm_entry);
> >
> >       *tfm_entry = list_next_entry(*tfm_entry, list);
> > +     put_cpu_ptr(tfm_entry);
> >       return (*tfm_entry)->tfm;
> >  }
> >
> >
> 
> > You have not explained why this was safe.
> >
> >  This seems to hide a real bug.
> >
> > Presumably callers of this function should have disable preemption, and maybe > interrupts as well.
> >
> >Right after put_cpu_ptr(tfm_entry), this thread could migrate to another cpu, >and still access
> >data owned by the old cpu.
> 
> Thanks for you suggest, I will check code again.
> 

Actually, last week I sent a similar patch to tipc-discussion which covers the
case as well (there is also another place causing the same issue...). If you
don't mind, you can take a look at below (just copied/pasted).

BR/Tuong

-----Original Message-----
From: Tuong Tong Lien <tuong.t.lien@dektech.com.au> 
Sent: Friday, July 10, 2020 5:11 PM
To: jmaloy@redhat.com; maloy@donjonn.com; ying.xue@windriver.com; tipc-discussion@lists.sourceforge.net
Cc: tipc-dek <tipc-dek@dektech.com.au>
Subject: [PATCH RFC 1/5] tipc: fix using smp_processor_id() in preemptible

The 'this_cpu_ptr()' is used to obtain the AEAD key' TFM on the current
CPU for encryption, however the execution can be preemptible since it's
actually user-space context, so the 'using smp_processor_id() in
preemptible' has been observed.

We fix the issue by using the 'get/put_cpu_ptr()' API which consists of
a 'preempt_disable()' instead.

Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au>
---
 net/tipc/crypto.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index c8c47fc72653..1827ce4fac5d 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -326,7 +326,8 @@ static void tipc_aead_free(struct rcu_head *rp)
 	if (aead->cloned) {
 		tipc_aead_put(aead->cloned);
 	} else {
-		head = *this_cpu_ptr(aead->tfm_entry);
+		head = *get_cpu_ptr(aead->tfm_entry);
+		put_cpu_ptr(aead->tfm_entry);
 		list_for_each_entry_safe(tfm_entry, tmp, &head->list, list) {
 			crypto_free_aead(tfm_entry->tfm);
 			list_del(&tfm_entry->list);
@@ -399,10 +400,15 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
  */
 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
 {
-	struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
+	struct tipc_tfm **tfm_entry;
+	struct crypto_aead *tfm;
 
+	tfm_entry = get_cpu_ptr(aead->tfm_entry);
 	*tfm_entry = list_next_entry(*tfm_entry, list);
-	return (*tfm_entry)->tfm;
+	tfm = (*tfm_entry)->tfm;
+	put_cpu_ptr(tfm_entry);
+
+	return tfm;
 }
 
 /**
-- 
2.13.7

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

* 回复: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
  2020-07-15  3:53     ` Tuong Tong Lien
@ 2020-07-15  5:27       ` Zhang, Qiang
  2020-07-15  6:05         ` Zhang, Qiang
  0 siblings, 1 reply; 7+ messages in thread
From: Zhang, Qiang @ 2020-07-15  5:27 UTC (permalink / raw)
  To: Tuong Tong Lien, Eric Dumazet, jmaloy, davem, kuba, Xue, Ying
  Cc: netdev, tipc-discussion, linux-kernel



________________________________________
发件人: Tuong Tong Lien <tuong.t.lien@dektech.com.au>
发送时间: 2020年7月15日 11:53
收件人: Zhang, Qiang; Eric Dumazet; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; Xue, Ying
抄送: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
主题: RE: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code



> -----Original Message-----
> From: Zhang, Qiang <Qiang.Zhang@windriver.com>
> Sent: Wednesday, July 15, 2020 9:13 AM
> To: Eric Dumazet <eric.dumazet@gmail.com>; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; Tuong Tong Lien
> <tuong.t.lien@dektech.com.au>; Xue, Ying <Ying.Xue@windriver.com>
> Cc: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
> Subject: 回复: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
>
>
>
> ________________________________________
> 发件人: Eric Dumazet <eric.dumazet@gmail.com>
> 发送时间: 2020年7月14日 22:15
> 收件人: Zhang, Qiang; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; tuong.t.lien@dektech.com.au;
> eric.dumazet@gmail.com; Xue, Ying
> 抄送: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
> 主题: Re: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
>
>
>
> On 7/14/20 1:05 AM, qiang.zhang@windriver.com wrote:
> > From: Zhang Qiang <qiang.zhang@windriver.com>
> >
> > CPU: 0 PID: 6801 Comm: syz-executor201 Not tainted 5.8.0-rc4-syzkaller #0
> > Hardware name: Google Google Compute Engine/Google Compute Engine,
> > BIOS Google 01/01/2011
> >
> > Fixes: fc1b6d6de2208 ("tipc: introduce TIPC encryption & authentication")
> > Reported-by: syzbot+263f8c0d007dc09b2dda@syzkaller.appspotmail.com
> > Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
> > ---
> >  v1->v2:
> >  add fixes tags.
> >
> >  net/tipc/crypto.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> > index 8c47ded2edb6..520af0afe1b3 100644
> > --- a/net/tipc/crypto.c
> > +++ b/net/tipc/crypto.c
> > @@ -399,9 +399,10 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
> >   */
> >  static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
> >  {
> > -     struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
> > +     struct tipc_tfm **tfm_entry = get_cpu_ptr(aead->tfm_entry);
> >
> >       *tfm_entry = list_next_entry(*tfm_entry, list);
> > +     put_cpu_ptr(tfm_entry);
> >       return (*tfm_entry)->tfm;
> >  }
> >
> >
>
> > You have not explained why this was safe.
> >
> >  This seems to hide a real bug.
> >
> > Presumably callers of this function should have disable preemption, and maybe > interrupts as well.
> >
> >Right after put_cpu_ptr(tfm_entry), this thread could migrate to another cpu, >and still access
> >data owned by the old cpu.
>
> Thanks for you suggest, I will check code again.
>

>Actually, last week I sent a similar patch to tipc-discussion which covers the
>case as well (there is also another place causing the same issue...). If you
>don't mind, you can take a look at below (just copied/pasted).

>BR/Tuong


Hi Tuong Tong Lien

The tipc_aead_free is RCU callback, this func is called in softirq context which 
preemption has been banned
so should not add preempt_disable/enable.

thanks
Zhang Qiang


>-----Original Message-----
>From: Tuong Tong Lien <tuong.t.lien@dektech.com.au>
>Sent: Friday, July 10, 2020 5:11 PM
>To: jmaloy@redhat.com; maloy@donjonn.com; ying.xue@windriver.com; tipc-discussion@lists.sourceforge.net
>Cc: tipc-dek <tipc-dek@dektech.com.au>
Subject: [PATCH RFC 1/5] tipc: fix using smp_processor_id() in preemptible
>
>The 'this_cpu_ptr()' is used to obtain the AEAD key' TFM on the current
CPU for encryption, however the execution can be preemptible since it's
actually user-space context, so the 'using smp_processor_id() in
preemptible' has been observed.

We fix the issue by using the 'get/put_cpu_ptr()' API which consists of
a 'preempt_disable()' instead.

Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au>
---
 net/tipc/crypto.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index c8c47fc72653..1827ce4fac5d 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -326,7 +326,8 @@ static void tipc_aead_free(struct rcu_head *rp)
        if (aead->cloned) {
                tipc_aead_put(aead->cloned);
        } else {
-               head = *this_cpu_ptr(aead->tfm_entry);
+               head = *get_cpu_ptr(aead->tfm_entry);
+               put_cpu_ptr(aead->tfm_entry);
                list_for_each_entry_safe(tfm_entry, tmp, &head->list, list) {
                        crypto_free_aead(tfm_entry->tfm);
                        list_del(&tfm_entry->list);
@@ -399,10 +400,15 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
  */
 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
 {
-       struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
+       struct tipc_tfm **tfm_entry;
+       struct crypto_aead *tfm;

+       tfm_entry = get_cpu_ptr(aead->tfm_entry);
        *tfm_entry = list_next_entry(*tfm_entry, list);
-       return (*tfm_entry)->tfm;
+       tfm = (*tfm_entry)->tfm;
+       put_cpu_ptr(tfm_entry);
+
+       return tfm;
 }

 /**
--
2.13.7

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

* 回复: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
  2020-07-15  5:27       ` 回复: " Zhang, Qiang
@ 2020-07-15  6:05         ` Zhang, Qiang
  0 siblings, 0 replies; 7+ messages in thread
From: Zhang, Qiang @ 2020-07-15  6:05 UTC (permalink / raw)
  To: Tuong Tong Lien, Eric Dumazet, jmaloy, davem, kuba, Xue, Ying
  Cc: netdev, tipc-discussion, linux-kernel



________________________________________
发件人: Zhang, Qiang <Qiang.Zhang@windriver.com>
发送时间: 2020年7月15日 13:27
收件人: Tuong Tong Lien; Eric Dumazet; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; Xue, Ying
抄送: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
主题: 回复: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code



________________________________________
发件人: Tuong Tong Lien <tuong.t.lien@dektech.com.au>
发送时间: 2020年7月15日 11:53
收件人: Zhang, Qiang; Eric Dumazet; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; Xue, Ying
抄送: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
主题: RE: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code



> -----Original Message-----
> From: Zhang, Qiang <Qiang.Zhang@windriver.com>
> Sent: Wednesday, July 15, 2020 9:13 AM
> To: Eric Dumazet <eric.dumazet@gmail.com>; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; Tuong Tong Lien
> <tuong.t.lien@dektech.com.au>; Xue, Ying <Ying.Xue@windriver.com>
> Cc: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
> Subject: 回复: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
>
>
>
> ________________________________________
> 发件人: Eric Dumazet <eric.dumazet@gmail.com>
> 发送时间: 2020年7月14日 22:15
> 收件人: Zhang, Qiang; jmaloy@redhat.com; davem@davemloft.net; kuba@kernel.org; tuong.t.lien@dektech.com.au;
> eric.dumazet@gmail.com; Xue, Ying
> 抄送: netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net; linux-kernel@vger.kernel.org
> 主题: Re: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
>
>
>
> On 7/14/20 1:05 AM, qiang.zhang@windriver.com wrote:
> > From: Zhang Qiang <qiang.zhang@windriver.com>
> >
> > CPU: 0 PID: 6801 Comm: syz-executor201 Not tainted 5.8.0-rc4-syzkaller #0
> > Hardware name: Google Google Compute Engine/Google Compute Engine,
> > BIOS Google 01/01/2011
> >
> > Fixes: fc1b6d6de2208 ("tipc: introduce TIPC encryption & authentication")
> > Reported-by: syzbot+263f8c0d007dc09b2dda@syzkaller.appspotmail.com
> > Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
> > ---
> >  v1->v2:
> >  add fixes tags.
> >
> >  net/tipc/crypto.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> > index 8c47ded2edb6..520af0afe1b3 100644
> > --- a/net/tipc/crypto.c
> > +++ b/net/tipc/crypto.c
> > @@ -399,9 +399,10 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
> >   */
> >  static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
> >  {
> > -     struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
> > +     struct tipc_tfm **tfm_entry = get_cpu_ptr(aead->tfm_entry);
> >
> >       *tfm_entry = list_next_entry(*tfm_entry, list);
> > +     put_cpu_ptr(tfm_entry);
> >       return (*tfm_entry)->tfm;
> >  }
> >
> >
>
> > You have not explained why this was safe.
> >
> >  This seems to hide a real bug.
> >
> > Presumably callers of this function should have disable preemption, and maybe > interrupts as well.
> >
> >Right after put_cpu_ptr(tfm_entry), this thread could migrate to another cpu, >and still access
> >data owned by the old cpu.
>
> Thanks for you suggest, I will check code again.
>

>Actually, last week I sent a similar patch to tipc-discussion which covers the
>case as well (there is also another place causing the same issue...). If you
>don't mind, you can take a look at below (just copied/pasted).

>BR/Tuong


>Hi Tuong Tong Lien

>The tipc_aead_free is RCU callback, this func is called in softirq context which
>preemption has been banned
>so should not add preempt_disable/enable.

>thanks
>Zhang Qiang
sorry there are some questions in my reply. the tipc_aead_free function may also be called in the thread context. if enable CONFIG_RCU_BOOST

>-----Original Message-----
>From: Tuong Tong Lien <tuong.t.lien@dektech.com.au>
>Sent: Friday, July 10, 2020 5:11 PM
>To: jmaloy@redhat.com; maloy@donjonn.com; ying.xue@windriver.com; tipc-discussion@lists.sourceforge.net
>Cc: tipc-dek <tipc-dek@dektech.com.au>
Subject: [PATCH RFC 1/5] tipc: fix using smp_processor_id() in preemptible
>
>The 'this_cpu_ptr()' is used to obtain the AEAD key' TFM on the current
CPU for encryption, however the execution can be preemptible since it's
actually user-space context, so the 'using smp_processor_id() in
preemptible' has been observed.

We fix the issue by using the 'get/put_cpu_ptr()' API which consists of
a 'preempt_disable()' instead.

Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au>
---
 net/tipc/crypto.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index c8c47fc72653..1827ce4fac5d 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -326,7 +326,8 @@ static void tipc_aead_free(struct rcu_head *rp)
        if (aead->cloned) {
                tipc_aead_put(aead->cloned);
        } else {
-               head = *this_cpu_ptr(aead->tfm_entry);
+               head = *get_cpu_ptr(aead->tfm_entry);
+               put_cpu_ptr(aead->tfm_entry);
                list_for_each_entry_safe(tfm_entry, tmp, &head->list, list) {
                        crypto_free_aead(tfm_entry->tfm);
                        list_del(&tfm_entry->list);
@@ -399,10 +400,15 @@ static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
  */
 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
 {
-       struct tipc_tfm **tfm_entry = this_cpu_ptr(aead->tfm_entry);
+       struct tipc_tfm **tfm_entry;
+       struct crypto_aead *tfm;

+       tfm_entry = get_cpu_ptr(aead->tfm_entry);
        *tfm_entry = list_next_entry(*tfm_entry, list);
-       return (*tfm_entry)->tfm;
+       tfm = (*tfm_entry)->tfm;
+       put_cpu_ptr(tfm_entry);
+
+       return tfm;
 }

 /**
--
2.13.7

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

* Re: [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code
@ 2020-07-15 18:43 Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2020-07-15 18:43 UTC (permalink / raw)
  To: Zhang Qiang, netdev, tipc-discussion
  Cc: linux-kernel, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Jon Maloy, Tuong Lien, Ying Xue

* I find the patch subject improvable.

* Please add a change description for the desired commit.

Regards,
Markus

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

end of thread, other threads:[~2020-07-15 18:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14  8:05 [PATCH v2] tipc: Don't using smp_processor_id() in preemptible code qiang.zhang
2020-07-14 14:15 ` Eric Dumazet
2020-07-15  2:12   ` 回复: " Zhang, Qiang
2020-07-15  3:53     ` Tuong Tong Lien
2020-07-15  5:27       ` 回复: " Zhang, Qiang
2020-07-15  6:05         ` Zhang, Qiang
2020-07-15 18:43 Markus Elfring

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).