DriverDev-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Stefan Wahren <wahrenst@gmx.net>
To: Marcelo Diop-Gonzalez <marcgonzalez@google.com>,
	gregkh@linuxfoundation.org, eric@anholt.net, wahrenst@gmx.net
Cc: devel@driverdev.osuosl.org, Phil Elwell <phil@raspberrypi.org>,
	linux-rpi-kernel@lists.infradead.org
Subject: Re: [PATCH 0/3] staging: vchiq: Fix vchiq_read return value in case of error
Date: Thu, 21 Nov 2019 11:42:37 +0100
Message-ID: <f2f8b72e-3d56-e9e5-f381-5b80a09490dc@gmx.net> (raw)
In-Reply-To: <cover.1574253964.git.marcgonzalez@google.com>

Hi Marcelo,

[add Nicolas and Phil]

Am 20.11.19 um 16:36 schrieb Marcelo Diop-Gonzalez:
> This is a proposed fix of an issue regarding the handling of positive
> return values from copy_to_user() in vchiq_read(). It looks like the
> struct dump_context passed to the vchiq_dump() function keeps track
> of the number of bytes written in the context->actual field. When
> copy_to_user() returns a positive value, this is set to -EFAULT. The
> problem is that this is never returned to the user, and instead the function
> continues, adding the number of bytes that should have been copied
> to context->actual.
>
> Running the following program:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <errno.h>
>
> int main(int argc, char **argv) {
> 	int fd = open("/dev/vchiq", 0);
> 	if (fd < 0)
> 		exit(-1);
> 	sbrk(getpagesize());
> 	char *bad_buf = sbrk(0)-100;
> 	int x = read(fd, bad_buf, 2000);
> 	printf("%d %d\n", x, errno);
> 	puts(bad_buf);
> }
>
> gives this output:
>
> -1 1
> State 0: CONNECTED
>   tx_po
>
>
>   Remote: slots 2-32 tx_pos=578 recycle=1f
>     Slots claimed:
>
> Note the mangled output and incorrect errno value. Messing with the
> constants in that toy program changes the results. Sometimes read()
> returns with no error, sometimes it returns with a wrong error code,
> sometimes with the right one. But it seems that it only ever returns an
> error at all accidentally, due to the fact that the comparison between
> context->actual and context->space in vchiq_dump() is unsigned, so that
> that function won't do anything else if it ever sets context->actual
> to a negative value.
>
> After this patchset, the above program prints this:
>
> -1 14
> State 0: CONNECTED
>   tx_pos=b4a218(@165de6b4), rx_pos=ae0668(@f02b54f4)
>   Version: 8 (min 3)
>   Stats
>
> Help with testing would be appreciated. So far I've basically just
> diffed the output of 'cat /dev/vchiq', run the program above with
> a few different values, and run vchiq_test a few times.

i consider this as sufficient, but i'm not the VCHIQ expert.

Thanks
Stefan

>
> These were applied to the staging-next branch of the tree
> at git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
>
> Marcelo Diop-Gonzalez (3):
>   staging: vchiq_dump: Replace min with min_t
>   staging: vchiq: Refactor indentation in vchiq_dump_* functions
>   staging: vchiq: Have vchiq_dump_* functions return an error code
>
>  .../interface/vchiq_arm/vchiq_2835_arm.c      |   5 +-
>  .../interface/vchiq_arm/vchiq_arm.c           | 129 ++++++++++--------
>  .../interface/vchiq_arm/vchiq_core.c          | 104 ++++++++++----
>  .../interface/vchiq_arm/vchiq_core.h          |  12 +-
>  4 files changed, 153 insertions(+), 97 deletions(-)
>
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 15:36 Marcelo Diop-Gonzalez
2019-11-20 15:36 ` [PATCH 1/3] staging: vchiq_dump: Replace min with min_t Marcelo Diop-Gonzalez
2019-11-20 15:46   ` Greg KH
2019-11-20 15:36 ` [PATCH 2/3] staging: vchiq: Refactor indentation in vchiq_dump_* functions Marcelo Diop-Gonzalez
2019-11-20 15:36 ` [PATCH 3/3] staging: vchiq: Have vchiq_dump_* functions return an error code Marcelo Diop-Gonzalez
2019-11-20 18:50   ` Dan Carpenter
2019-11-21 21:25     ` Marcelo Diop-Gonzalez
2019-11-20 20:20 ` [PATCH v2 0/4] staging: vchiq: Fix vchiq_read return value in case of error Marcelo Diop-Gonzalez
2019-11-20 20:20   ` [PATCH v2 1/4] staging: vchiq: Fix block comment format in vchiq_dump() Marcelo Diop-Gonzalez
2019-11-20 20:21   ` [PATCH v2 2/4] staging: vchiq_dump: Replace min with min_t Marcelo Diop-Gonzalez
2019-11-20 20:21   ` [PATCH v2 3/4] staging: vchiq: Refactor indentation in vchiq_dump_* functions Marcelo Diop-Gonzalez
2019-11-20 20:21   ` [PATCH v2 4/4] staging: vchiq: Have vchiq_dump_* functions return an error code Marcelo Diop-Gonzalez
2019-11-21 19:38   ` [PATCH v2 0/4] staging: vchiq: Fix vchiq_read return value in case of error Nicolas Saenz Julienne
2019-11-21 21:24     ` Marcelo Diop-Gonzalez
2019-11-21 10:42 ` Stefan Wahren [this message]
2019-11-21 19:41   ` [PATCH 0/3] " Nicolas Saenz Julienne

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2f8b72e-3d56-e9e5-f381-5b80a09490dc@gmx.net \
    --to=wahrenst@gmx.net \
    --cc=devel@driverdev.osuosl.org \
    --cc=eric@anholt.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=marcgonzalez@google.com \
    --cc=phil@raspberrypi.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DriverDev-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/driverdev-devel/0 driverdev-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 driverdev-devel driverdev-devel/ https://lore.kernel.org/driverdev-devel \
		driverdev-devel@linuxdriverproject.org devel@driverdev.osuosl.org
	public-inbox-index driverdev-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxdriverproject.driverdev-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git