mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] console: only bidirectional consoles allow RATP
@ 2017-06-01 18:14 Aleksander Morgado
  2017-06-06  5:39 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Aleksander Morgado @ 2017-06-01 18:14 UTC (permalink / raw)
  To: barebox; +Cc: Aleksander Morgado

If a request to switch to RATP mode is received in an input-only
console, ignore the request.

This actually also avoids segfaulting later on:

    #0  0x0000000000000000 in ?? ()
    #1  0x000000000040b2a4 in console_send (r=<optimized out>, pkt=0x7fffffffd8ec, len=4) at common/ratp.c:102
    #2  0x000000000042ab99 in ratp_behaviour_a (pkt=0x7ffff7298780, ri=0x7ffff72766d0) at lib/ratp.c:530
    #3  ratp_state_machine (pkt=0x7ffff7298780, ri=0x7ffff72766d0) at lib/ratp.c:1384
    #4  ratp_poll (ratp=0x7ffff7277ed8) at lib/ratp.c:1561
    #5  0x000000000042b2ab in ratp_establish (ratp=ratp@entry=0x7ffff7277ed8, active=active@entry=false, timeout_ms=timeout_ms@entry=100) at lib/ratp.c:1645
    #6  0x000000000040b888 in barebox_ratp (cdev=cdev@entry=0x7ffff7212bd0) at common/ratp.c:470
    #7  0x00000000004046c3 in getc_raw () at common/console.c:416
    ...

Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
---

Hey Sascha,

Looks like I may actually need to update the options to allow setting up bidirectional consoles, instead of separate input/output ones. Otherwise I won't be able to use RATP over the FIFO-based console. This patch fixes a segfault happening in barebox sandbox when the input-only console receives a request to switch to RATP mode, it ends up crashing afterwards when the SYN/ACK response is to be sent via the non-existent output path.

Cheers!

---
 common/console.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/console.c b/common/console.c
index f4c799fa5..f8677659e 100644
--- a/common/console.c
+++ b/common/console.c
@@ -412,7 +412,9 @@ static int getc_raw(void)
 			if (cdev->tstc(cdev)) {
 				int ch = cdev->getc(cdev);

-				if (IS_ENABLED(CONFIG_RATP) && ch == 0x01) {
+				if (IS_ENABLED(CONFIG_RATP) &&
+				    ch == 0x01 &&
+				    (cdev->f_active & CONSOLE_STDOUT)) {
 					barebox_ratp(cdev);
 					return -1;
 				}
--
2.13.0

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] console: only bidirectional consoles allow RATP
  2017-06-01 18:14 [PATCH] console: only bidirectional consoles allow RATP Aleksander Morgado
@ 2017-06-06  5:39 ` Sascha Hauer
  2017-06-06 13:52   ` [PATCH] ratp: only allow bidirectional consoles Aleksander Morgado
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2017-06-06  5:39 UTC (permalink / raw)
  To: Aleksander Morgado; +Cc: barebox

Hi Aleksander,

On Thu, Jun 01, 2017 at 08:14:57PM +0200, Aleksander Morgado wrote:
> If a request to switch to RATP mode is received in an input-only
> console, ignore the request.
> 
> This actually also avoids segfaulting later on:
> 
>     #0  0x0000000000000000 in ?? ()
>     #1  0x000000000040b2a4 in console_send (r=<optimized out>, pkt=0x7fffffffd8ec, len=4) at common/ratp.c:102
>     #2  0x000000000042ab99 in ratp_behaviour_a (pkt=0x7ffff7298780, ri=0x7ffff72766d0) at lib/ratp.c:530
>     #3  ratp_state_machine (pkt=0x7ffff7298780, ri=0x7ffff72766d0) at lib/ratp.c:1384
>     #4  ratp_poll (ratp=0x7ffff7277ed8) at lib/ratp.c:1561
>     #5  0x000000000042b2ab in ratp_establish (ratp=ratp@entry=0x7ffff7277ed8, active=active@entry=false, timeout_ms=timeout_ms@entry=100) at lib/ratp.c:1645
>     #6  0x000000000040b888 in barebox_ratp (cdev=cdev@entry=0x7ffff7212bd0) at common/ratp.c:470
>     #7  0x00000000004046c3 in getc_raw () at common/console.c:416
>     ...
> 
> Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
> ---
> 
> Hey Sascha,
> 
> Looks like I may actually need to update the options to allow setting up bidirectional consoles, instead of separate input/output ones. Otherwise I won't be able to use RATP over the FIFO-based console. This patch fixes a segfault happening in barebox sandbox when the input-only console receives a request to switch to RATP mode, it ends up crashing afterwards when the SYN/ACK response is to be sent via the non-existent output path.
> 
> Cheers!
> 
> ---
>  common/console.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/common/console.c b/common/console.c
> index f4c799fa5..f8677659e 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -412,7 +412,9 @@ static int getc_raw(void)
>  			if (cdev->tstc(cdev)) {
>  				int ch = cdev->getc(cdev);
> 
> -				if (IS_ENABLED(CONFIG_RATP) && ch == 0x01) {
> +				if (IS_ENABLED(CONFIG_RATP) &&
> +				    ch == 0x01 &&
> +				    (cdev->f_active & CONSOLE_STDOUT)) {
>  					barebox_ratp(cdev);

Can we add a test for the existence of cdev->getc and cdev->putc in
barebox_ratp() instead? It makes it more explicit that the ratp code
needs this and also works when somebody cally barebox_ratp() directly.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH] ratp: only allow bidirectional consoles
  2017-06-06  5:39 ` Sascha Hauer
@ 2017-06-06 13:52   ` Aleksander Morgado
  2017-06-07  6:03     ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Aleksander Morgado @ 2017-06-06 13:52 UTC (permalink / raw)
  To: barebox; +Cc: Aleksander Morgado

Ignore requests to switch to RATP mode in input-only or output-only
consoles.

This actually also avoids segfaulting later on:

    #0  0x0000000000000000 in ?? ()
    #1  0x000000000040b2a4 in console_send (r=<optimized out>, pkt=0x7fffffffd8ec, len=4) at common/ratp.c:102
    #2  0x000000000042ab99 in ratp_behaviour_a (pkt=0x7ffff7298780, ri=0x7ffff72766d0) at lib/ratp.c:530
    #3  ratp_state_machine (pkt=0x7ffff7298780, ri=0x7ffff72766d0) at lib/ratp.c:1384
    #4  ratp_poll (ratp=0x7ffff7277ed8) at lib/ratp.c:1561
    #5  0x000000000042b2ab in ratp_establish (ratp=ratp@entry=0x7ffff7277ed8, active=active@entry=false, timeout_ms=timeout_ms@entry=100) at lib/ratp.c:1645
    #6  0x000000000040b888 in barebox_ratp (cdev=cdev@entry=0x7ffff7212bd0) at common/ratp.c:470
    #7  0x00000000004046c3 in getc_raw () at common/console.c:416
    ...

Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
---
 common/ratp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/ratp.c b/common/ratp.c
index e879e2b3c..7be86d49a 100644
--- a/common/ratp.c
+++ b/common/ratp.c
@@ -443,6 +443,9 @@ int barebox_ratp(struct console_device *cdev)
 	struct ratp_ctx *ctx;
 	struct ratp *ratp;

+	if (!cdev->getc || !cdev->putc)
+		return -EINVAL;
+
 	if (ratp_command_ctx) {
 		ctx = ratp_command_ctx;
 	} else {
--
2.12.2

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] ratp: only allow bidirectional consoles
  2017-06-06 13:52   ` [PATCH] ratp: only allow bidirectional consoles Aleksander Morgado
@ 2017-06-07  6:03     ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2017-06-07  6:03 UTC (permalink / raw)
  To: Aleksander Morgado; +Cc: barebox

On Tue, Jun 06, 2017 at 03:52:10PM +0200, Aleksander Morgado wrote:
> Ignore requests to switch to RATP mode in input-only or output-only
> consoles.
> 
> This actually also avoids segfaulting later on:
> 
>     #0  0x0000000000000000 in ?? ()
>     #1  0x000000000040b2a4 in console_send (r=<optimized out>, pkt=0x7fffffffd8ec, len=4) at common/ratp.c:102
>     #2  0x000000000042ab99 in ratp_behaviour_a (pkt=0x7ffff7298780, ri=0x7ffff72766d0) at lib/ratp.c:530
>     #3  ratp_state_machine (pkt=0x7ffff7298780, ri=0x7ffff72766d0) at lib/ratp.c:1384
>     #4  ratp_poll (ratp=0x7ffff7277ed8) at lib/ratp.c:1561
>     #5  0x000000000042b2ab in ratp_establish (ratp=ratp@entry=0x7ffff7277ed8, active=active@entry=false, timeout_ms=timeout_ms@entry=100) at lib/ratp.c:1645
>     #6  0x000000000040b888 in barebox_ratp (cdev=cdev@entry=0x7ffff7212bd0) at common/ratp.c:470
>     #7  0x00000000004046c3 in getc_raw () at common/console.c:416
>     ...
> 
> Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
> ---
>  common/ratp.c | 3 +++
>  1 file changed, 3 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/common/ratp.c b/common/ratp.c
> index e879e2b3c..7be86d49a 100644
> --- a/common/ratp.c
> +++ b/common/ratp.c
> @@ -443,6 +443,9 @@ int barebox_ratp(struct console_device *cdev)
>  	struct ratp_ctx *ctx;
>  	struct ratp *ratp;
> 
> +	if (!cdev->getc || !cdev->putc)
> +		return -EINVAL;
> +
>  	if (ratp_command_ctx) {
>  		ctx = ratp_command_ctx;
>  	} else {
> --
> 2.12.2
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2017-06-07  6:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-01 18:14 [PATCH] console: only bidirectional consoles allow RATP Aleksander Morgado
2017-06-06  5:39 ` Sascha Hauer
2017-06-06 13:52   ` [PATCH] ratp: only allow bidirectional consoles Aleksander Morgado
2017-06-07  6:03     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox