All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xenbus: don't BUG() on user mode induced condition
@ 2016-07-07  7:23 ` Jan Beulich
  0 siblings, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2016-07-07  7:23 UTC (permalink / raw)
  To: david.vrabel, boris.ostrovsky, Juergen Gross; +Cc: xen-devel, linux-kernel

Inability to locate a user mode specified transaction ID should not
lead to a kernel crash. For other than XS_TRANSACTION_START also
don't issue anything to xenbus if the specified ID doesn't match that
of any active transaction.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
 drivers/xen/xenbus/xenbus_dev_frontend.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

--- 4.7-rc6-xen.orig/drivers/xen/xenbus/xenbus_dev_frontend.c
+++ 4.7-rc6-xen/drivers/xen/xenbus/xenbus_dev_frontend.c
@@ -316,11 +316,18 @@ static int xenbus_write_transaction(unsi
 			rc = -ENOMEM;
 			goto out;
 		}
+	} else {
+		list_for_each_entry(trans, &u->transactions, list)
+			if (trans->handle.id == u->u.msg.tx_id)
+				break;
+		if (&trans->list == &u->transactions)
+			return -ESRCH;
 	}
 
 	reply = xenbus_dev_request_and_reply(&u->u.msg);
 	if (IS_ERR(reply)) {
-		kfree(trans);
+		if (msg_type == XS_TRANSACTION_START)
+			kfree(trans);
 		rc = PTR_ERR(reply);
 		goto out;
 	}
@@ -333,12 +340,7 @@ static int xenbus_write_transaction(unsi
 			list_add(&trans->list, &u->transactions);
 		}
 	} else if (u->u.msg.type == XS_TRANSACTION_END) {
-		list_for_each_entry(trans, &u->transactions, list)
-			if (trans->handle.id == u->u.msg.tx_id)
-				break;
-		BUG_ON(&trans->list == &u->transactions);
 		list_del(&trans->list);
-
 		kfree(trans);
 	}
 

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

* [PATCH] xenbus: don't BUG() on user mode induced condition
@ 2016-07-07  7:23 ` Jan Beulich
  0 siblings, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2016-07-07  7:23 UTC (permalink / raw)
  To: david.vrabel, boris.ostrovsky, Juergen Gross; +Cc: xen-devel, linux-kernel

Inability to locate a user mode specified transaction ID should not
lead to a kernel crash. For other than XS_TRANSACTION_START also
don't issue anything to xenbus if the specified ID doesn't match that
of any active transaction.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
 drivers/xen/xenbus/xenbus_dev_frontend.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

--- 4.7-rc6-xen.orig/drivers/xen/xenbus/xenbus_dev_frontend.c
+++ 4.7-rc6-xen/drivers/xen/xenbus/xenbus_dev_frontend.c
@@ -316,11 +316,18 @@ static int xenbus_write_transaction(unsi
 			rc = -ENOMEM;
 			goto out;
 		}
+	} else {
+		list_for_each_entry(trans, &u->transactions, list)
+			if (trans->handle.id == u->u.msg.tx_id)
+				break;
+		if (&trans->list == &u->transactions)
+			return -ESRCH;
 	}
 
 	reply = xenbus_dev_request_and_reply(&u->u.msg);
 	if (IS_ERR(reply)) {
-		kfree(trans);
+		if (msg_type == XS_TRANSACTION_START)
+			kfree(trans);
 		rc = PTR_ERR(reply);
 		goto out;
 	}
@@ -333,12 +340,7 @@ static int xenbus_write_transaction(unsi
 			list_add(&trans->list, &u->transactions);
 		}
 	} else if (u->u.msg.type == XS_TRANSACTION_END) {
-		list_for_each_entry(trans, &u->transactions, list)
-			if (trans->handle.id == u->u.msg.tx_id)
-				break;
-		BUG_ON(&trans->list == &u->transactions);
 		list_del(&trans->list);
-
 		kfree(trans);
 	}
 




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [Xen-devel] [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-07-07  7:23 ` Jan Beulich
  (?)
  (?)
@ 2016-07-07 11:21 ` David Vrabel
  -1 siblings, 0 replies; 12+ messages in thread
From: David Vrabel @ 2016-07-07 11:21 UTC (permalink / raw)
  To: Jan Beulich, david.vrabel, boris.ostrovsky, Juergen Gross
  Cc: xen-devel, linux-kernel

On 07/07/16 08:23, Jan Beulich wrote:
> Inability to locate a user mode specified transaction ID should not
> lead to a kernel crash. For other than XS_TRANSACTION_START also
> don't issue anything to xenbus if the specified ID doesn't match that
> of any active transaction.

Applied to for-linus-4.7b and Cc'd to stable, thanks.

David

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

* Re: [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-07-07  7:23 ` Jan Beulich
  (?)
@ 2016-07-07 11:21 ` David Vrabel
  -1 siblings, 0 replies; 12+ messages in thread
From: David Vrabel @ 2016-07-07 11:21 UTC (permalink / raw)
  To: Jan Beulich, david.vrabel, boris.ostrovsky, Juergen Gross
  Cc: xen-devel, linux-kernel

On 07/07/16 08:23, Jan Beulich wrote:
> Inability to locate a user mode specified transaction ID should not
> lead to a kernel crash. For other than XS_TRANSACTION_START also
> don't issue anything to xenbus if the specified ID doesn't match that
> of any active transaction.

Applied to for-linus-4.7b and Cc'd to stable, thanks.

David

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [Xen-devel] [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-07-07  7:23 ` Jan Beulich
                   ` (3 preceding siblings ...)
  (?)
@ 2016-08-21 19:36 ` Sylvain Munaut
  2016-08-21 20:00   ` Christoph Moench-Tegeder
                     ` (2 more replies)
  -1 siblings, 3 replies; 12+ messages in thread
From: Sylvain Munaut @ 2016-08-21 19:36 UTC (permalink / raw)
  To: Jan Beulich; +Cc: david.vrabel, boris.ostrovsky, Juergen Gross, xen-devel, LKML

Hi,

> --- 4.7-rc6-xen.orig/drivers/xen/xenbus/xenbus_dev_frontend.c
> +++ 4.7-rc6-xen/drivers/xen/xenbus/xenbus_dev_frontend.c
> @@ -316,11 +316,18 @@ static int xenbus_write_transaction(unsi
>                         rc = -ENOMEM;
>                         goto out;
>                 }
> +       } else {
> +               list_for_each_entry(trans, &u->transactions, list)
> +                       if (trans->handle.id == u->u.msg.tx_id)
> +                               break;
> +               if (&trans->list == &u->transactions)
> +                       return -ESRCH;
>         }

Shouldn't there be some tolerance in there in case the tx_id is zero ?
(i.e. no transaction).

I'm trying to find out why just doing "xenstore-ls" doesn't work on my
4.4.20 kernel and when stracing it, I see it doing :

access("/dev/xen/xenbus", F_OK)         = 0
stat("/dev/xen/xenbus", {st_mode=S_IFCHR|0600, st_rdev=makedev(10,
60), ...}) = 0
open("/dev/xen/xenbus", O_RDWR)         = 3
brk(0)                                  = 0x18e4000
brk(0x1905000)                          = 0x1905000
rt_sigaction(SIGPIPE, {SIG_IGN, [], SA_RESTORER, 0x7fe4dd98e0e0},
{SIG_DFL, [], 0}, 8) = 0
write(3, "\1\0\0\0\0\0\0\0\0\0\0\0\2\0\0\0", 16) = 16
write(3, "/\0", 2)                      = -1 ESRCH (No such process)


So either what xenstore-ls does is invalid, or that condition
requiring a transaction is too strict.

Or am I missing something here ?


Cheers,

    Sylvain Munaut

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

* Re: [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-07-07  7:23 ` Jan Beulich
                   ` (2 preceding siblings ...)
  (?)
@ 2016-08-21 19:36 ` Sylvain Munaut
  -1 siblings, 0 replies; 12+ messages in thread
From: Sylvain Munaut @ 2016-08-21 19:36 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Juergen Gross, xen-devel, boris.ostrovsky, david.vrabel, LKML

Hi,

> --- 4.7-rc6-xen.orig/drivers/xen/xenbus/xenbus_dev_frontend.c
> +++ 4.7-rc6-xen/drivers/xen/xenbus/xenbus_dev_frontend.c
> @@ -316,11 +316,18 @@ static int xenbus_write_transaction(unsi
>                         rc = -ENOMEM;
>                         goto out;
>                 }
> +       } else {
> +               list_for_each_entry(trans, &u->transactions, list)
> +                       if (trans->handle.id == u->u.msg.tx_id)
> +                               break;
> +               if (&trans->list == &u->transactions)
> +                       return -ESRCH;
>         }

Shouldn't there be some tolerance in there in case the tx_id is zero ?
(i.e. no transaction).

I'm trying to find out why just doing "xenstore-ls" doesn't work on my
4.4.20 kernel and when stracing it, I see it doing :

access("/dev/xen/xenbus", F_OK)         = 0
stat("/dev/xen/xenbus", {st_mode=S_IFCHR|0600, st_rdev=makedev(10,
60), ...}) = 0
open("/dev/xen/xenbus", O_RDWR)         = 3
brk(0)                                  = 0x18e4000
brk(0x1905000)                          = 0x1905000
rt_sigaction(SIGPIPE, {SIG_IGN, [], SA_RESTORER, 0x7fe4dd98e0e0},
{SIG_DFL, [], 0}, 8) = 0
write(3, "\1\0\0\0\0\0\0\0\0\0\0\0\2\0\0\0", 16) = 16
write(3, "/\0", 2)                      = -1 ESRCH (No such process)


So either what xenstore-ls does is invalid, or that condition
requiring a transaction is too strict.

Or am I missing something here ?


Cheers,

    Sylvain Munaut

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-08-21 19:36 ` [Xen-devel] " Sylvain Munaut
@ 2016-08-21 20:00   ` Christoph Moench-Tegeder
  2016-08-21 21:18     ` Sylvain Munaut
  2016-08-22  6:45   ` [Xen-devel] " Jan Beulich
  2016-08-22  6:45   ` Jan Beulich
  2 siblings, 1 reply; 12+ messages in thread
From: Christoph Moench-Tegeder @ 2016-08-21 20:00 UTC (permalink / raw)
  To: xen-devel

## Sylvain Munaut (s.munaut@whatever-company.com):

> I'm trying to find out why just doing "xenstore-ls" doesn't work on my
> 4.4.20 kernel and when stracing it, I see it doing :

That looks like the same brokeness I reported earlier:
https://lists.xenproject.org/archives/html/xen-devel/2016-08/msg02496.html
Luckily I'm not alone with that :)

Regards,
Christoph

-- 
Spare Space

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-08-21 20:00   ` Christoph Moench-Tegeder
@ 2016-08-21 21:18     ` Sylvain Munaut
  0 siblings, 0 replies; 12+ messages in thread
From: Sylvain Munaut @ 2016-08-21 21:18 UTC (permalink / raw)
  To: Christoph Moench-Tegeder; +Cc: xen-devel

Hi,

>> I'm trying to find out why just doing "xenstore-ls" doesn't work on my
>> 4.4.20 kernel and when stracing it, I see it doing :
>
> That looks like the same brokeness I reported earlier:
> https://lists.xenproject.org/archives/html/xen-devel/2016-08/msg02496.html
> Luckily I'm not alone with that :)

Yes indeed, looks like the same root cause, although my symptoms were
a bit different.
I had googled around a bit before posting but didn't find you post, I
guess my google-fu failed me.

As for the fix, I went with the patch below ... no idea if it's really
correct, but it seemed right to me.
Hopfully someone more knowledgeable will come up with the right fix.


diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c
b/drivers/xen/xenbus/xenbus_dev_frontend.c
index 531e764..a60eec6 100644
--- a/drivers/xen/xenbus/xenbus_dev_frontend.c
+++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
@@ -316,7 +316,7 @@ static int xenbus_write_transaction(unsigned msg_type,
                        rc = -ENOMEM;
                        goto out;
                }
-       } else {
+       } else if (u->u.msg.tx_id || msg_type == XS_TRANSACTION_END) {
                list_for_each_entry(trans, &u->transactions, list)
                        if (trans->handle.id == u->u.msg.tx_id)
                                break;


Cheers,

    Sylvain

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [Xen-devel] [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-08-21 19:36 ` [Xen-devel] " Sylvain Munaut
  2016-08-21 20:00   ` Christoph Moench-Tegeder
@ 2016-08-22  6:45   ` Jan Beulich
  2016-08-22  7:21     ` Sylvain Munaut
  2016-08-22  7:21     ` [Xen-devel] " Sylvain Munaut
  2016-08-22  6:45   ` Jan Beulich
  2 siblings, 2 replies; 12+ messages in thread
From: Jan Beulich @ 2016-08-22  6:45 UTC (permalink / raw)
  To: Sylvain Munaut
  Cc: david.vrabel, xen-devel, boris.ostrovsky, Juergen Gross, LKML

>>> On 21.08.16 at 21:36, <s.munaut@whatever-company.com> wrote:
>> --- 4.7-rc6-xen.orig/drivers/xen/xenbus/xenbus_dev_frontend.c
>> +++ 4.7-rc6-xen/drivers/xen/xenbus/xenbus_dev_frontend.c
>> @@ -316,11 +316,18 @@ static int xenbus_write_transaction(unsi
>>                         rc = -ENOMEM;
>>                         goto out;
>>                 }
>> +       } else {
>> +               list_for_each_entry(trans, &u->transactions, list)
>> +                       if (trans->handle.id == u->u.msg.tx_id)
>> +                               break;
>> +               if (&trans->list == &u->transactions)
>> +                       return -ESRCH;
>>         }
> 
> Shouldn't there be some tolerance in there in case the tx_id is zero ?
> (i.e. no transaction).
> 
> I'm trying to find out why just doing "xenstore-ls" doesn't work on my
> 4.4.20 kernel and when stracing it, I see it doing :
> 
> access("/dev/xen/xenbus", F_OK)         = 0
> stat("/dev/xen/xenbus", {st_mode=S_IFCHR|0600, st_rdev=makedev(10,
> 60), ...}) = 0
> open("/dev/xen/xenbus", O_RDWR)         = 3
> brk(0)                                  = 0x18e4000
> brk(0x1905000)                          = 0x1905000
> rt_sigaction(SIGPIPE, {SIG_IGN, [], SA_RESTORER, 0x7fe4dd98e0e0},
> {SIG_DFL, [], 0}, 8) = 0
> write(3, "\1\0\0\0\0\0\0\0\0\0\0\0\2\0\0\0", 16) = 16
> write(3, "/\0", 2)                      = -1 ESRCH (No such process)
> 
> 
> So either what xenstore-ls does is invalid, or that condition
> requiring a transaction is too strict.
> 
> Or am I missing something here ?

See https://patchwork.kernel.org/patch/9281193/.

Jan

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

* Re: [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-08-21 19:36 ` [Xen-devel] " Sylvain Munaut
  2016-08-21 20:00   ` Christoph Moench-Tegeder
  2016-08-22  6:45   ` [Xen-devel] " Jan Beulich
@ 2016-08-22  6:45   ` Jan Beulich
  2 siblings, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2016-08-22  6:45 UTC (permalink / raw)
  To: Sylvain Munaut
  Cc: Juergen Gross, xen-devel, boris.ostrovsky, david.vrabel, LKML

>>> On 21.08.16 at 21:36, <s.munaut@whatever-company.com> wrote:
>> --- 4.7-rc6-xen.orig/drivers/xen/xenbus/xenbus_dev_frontend.c
>> +++ 4.7-rc6-xen/drivers/xen/xenbus/xenbus_dev_frontend.c
>> @@ -316,11 +316,18 @@ static int xenbus_write_transaction(unsi
>>                         rc = -ENOMEM;
>>                         goto out;
>>                 }
>> +       } else {
>> +               list_for_each_entry(trans, &u->transactions, list)
>> +                       if (trans->handle.id == u->u.msg.tx_id)
>> +                               break;
>> +               if (&trans->list == &u->transactions)
>> +                       return -ESRCH;
>>         }
> 
> Shouldn't there be some tolerance in there in case the tx_id is zero ?
> (i.e. no transaction).
> 
> I'm trying to find out why just doing "xenstore-ls" doesn't work on my
> 4.4.20 kernel and when stracing it, I see it doing :
> 
> access("/dev/xen/xenbus", F_OK)         = 0
> stat("/dev/xen/xenbus", {st_mode=S_IFCHR|0600, st_rdev=makedev(10,
> 60), ...}) = 0
> open("/dev/xen/xenbus", O_RDWR)         = 3
> brk(0)                                  = 0x18e4000
> brk(0x1905000)                          = 0x1905000
> rt_sigaction(SIGPIPE, {SIG_IGN, [], SA_RESTORER, 0x7fe4dd98e0e0},
> {SIG_DFL, [], 0}, 8) = 0
> write(3, "\1\0\0\0\0\0\0\0\0\0\0\0\2\0\0\0", 16) = 16
> write(3, "/\0", 2)                      = -1 ESRCH (No such process)
> 
> 
> So either what xenstore-ls does is invalid, or that condition
> requiring a transaction is too strict.
> 
> Or am I missing something here ?

See https://patchwork.kernel.org/patch/9281193/.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [Xen-devel] [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-08-22  6:45   ` [Xen-devel] " Jan Beulich
  2016-08-22  7:21     ` Sylvain Munaut
@ 2016-08-22  7:21     ` Sylvain Munaut
  1 sibling, 0 replies; 12+ messages in thread
From: Sylvain Munaut @ 2016-08-22  7:21 UTC (permalink / raw)
  To: Jan Beulich; +Cc: david.vrabel, xen-devel, boris.ostrovsky, Juergen Gross, LKML

Hi Jan,

> See https://patchwork.kernel.org/patch/9281193/.

Thanks for the pointer !

I had checked the kernel git tree for a potential fix, but didn't
think of patchwork.


Cheers,

    Sylvain Munaut

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

* Re: [PATCH] xenbus: don't BUG() on user mode induced condition
  2016-08-22  6:45   ` [Xen-devel] " Jan Beulich
@ 2016-08-22  7:21     ` Sylvain Munaut
  2016-08-22  7:21     ` [Xen-devel] " Sylvain Munaut
  1 sibling, 0 replies; 12+ messages in thread
From: Sylvain Munaut @ 2016-08-22  7:21 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Juergen Gross, xen-devel, boris.ostrovsky, david.vrabel, LKML

Hi Jan,

> See https://patchwork.kernel.org/patch/9281193/.

Thanks for the pointer !

I had checked the kernel git tree for a potential fix, but didn't
think of patchwork.


Cheers,

    Sylvain Munaut

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

end of thread, other threads:[~2016-08-22  7:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-07  7:23 [PATCH] xenbus: don't BUG() on user mode induced condition Jan Beulich
2016-07-07  7:23 ` Jan Beulich
2016-07-07 11:21 ` David Vrabel
2016-07-07 11:21 ` [Xen-devel] " David Vrabel
2016-08-21 19:36 ` Sylvain Munaut
2016-08-21 19:36 ` [Xen-devel] " Sylvain Munaut
2016-08-21 20:00   ` Christoph Moench-Tegeder
2016-08-21 21:18     ` Sylvain Munaut
2016-08-22  6:45   ` [Xen-devel] " Jan Beulich
2016-08-22  7:21     ` Sylvain Munaut
2016-08-22  7:21     ` [Xen-devel] " Sylvain Munaut
2016-08-22  6:45   ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.