List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix segfault found by AFL
@ 2017-02-19 12:44 john
  2017-02-19 12:44 ` [PATCH 1/3] ui-shared: don't print path crumbs without a repo john
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: john @ 2017-02-19 12:44 UTC (permalink / raw)


I set AFL [0] loose on CGit's URL input yesterday and it managed to find
one issue that leads to a segfault via a null dereference.

Either of the first or third patches fixes the segfault, but I much
prefer the first as a solid fix, the third is a bit too subtle as a way
to ensure that the necessary invariant holds.

The second patch also fixes the route that AFL found, but it's possible
to get the same effect using broken out query parameters like
"?p=log&path=foo" but I'm including it because it seems to make sense to
use the value of the final "url" parameter we receive fully rather than
some combination of that and a previous URL.

[0] http://lcamtuf.coredump.cx/afl/

John Keeping (3):
  ui-shared: don't print path crumbs without a repo
  parsing: clear query path before starting
  cgit: don't set vpath unless repo is set

 cgit.c      | 12 ++++++------
 parsing.c   |  2 +-
 ui-shared.c |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

-- 
2.12.0.rc2.230.ga28edc07cd



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

* [PATCH 1/3] ui-shared: don't print path crumbs without a repo
  2017-02-19 12:44 [PATCH 0/3] Fix segfault found by AFL john
@ 2017-02-19 12:44 ` john
  2017-02-19 12:45 ` [PATCH 2/3] parsing: clear query path before starting john
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: john @ 2017-02-19 12:44 UTC (permalink / raw)


cgit_print_path_crumbs() can call repolink() which assumes that ctx.repo
is non-null.  Currently we don't have any commands that set want_vpath
without also setting want_repo so it shouldn't be possible to fail this
test, but the check in cgit.c is in the wrong order so it is possible to
specify a query string like "?p=log&path=foo/bar" to end up here without
a valid repository.

This was found by American fuzzy lop [0].

[0] http://lcamtuf.coredump.cx/afl/

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 ui-shared.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-shared.c b/ui-shared.c
index 2e4fcd9..e5c9a02 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1039,7 +1039,7 @@ void cgit_print_pageheader(void)
 		free(currenturl);
 	}
 	html("</td></tr></table>\n");
-	if (ctx.env.authenticated && ctx.qry.vpath) {
+	if (ctx.env.authenticated && ctx.repo && ctx.qry.vpath) {
 		html("<div class='path'>");
 		html("path: ");
 		cgit_print_path_crumbs(ctx.qry.vpath);
-- 
2.12.0.rc2.230.ga28edc07cd



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

* [PATCH 2/3] parsing: clear query path before starting
  2017-02-19 12:44 [PATCH 0/3] Fix segfault found by AFL john
  2017-02-19 12:44 ` [PATCH 1/3] ui-shared: don't print path crumbs without a repo john
@ 2017-02-19 12:45 ` john
  2017-02-19 12:45 ` [PATCH 3/3] cgit: don't set vpath unless repo is set john
       [not found] ` <CAHmME9r8zY9qOqbg7fwuB1gW76nXVcsqJ-LT2-6sjD3SuoJ-HQ@mail.gmail.com>
  3 siblings, 0 replies; 6+ messages in thread
From: john @ 2017-02-19 12:45 UTC (permalink / raw)


By specifying the "url" query parameter multiple times it is possible to
end up with ctx.qry.vpath set while ctx.repo is null, which triggers an
invalid code path from cgit_print_pageheader() while printing path
crumbs, resulting in a null dereference.

The previous patch fixed this segfault, but it makes no sense for us to
clear ctx.repo while leaving ctx.qry.path set to the previous value, so
let's just clear it here so that the last "url" parameter given takes
full effect rather than partially overriding the effect of the previous
value.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 parsing.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing.c b/parsing.c
index 9dacb16..b8d7f10 100644
--- a/parsing.c
+++ b/parsing.c
@@ -21,6 +21,7 @@ void cgit_parse_url(const char *url)
 	struct cgit_repo *repo;
 
 	ctx.repo = NULL;
+	ctx.qry.page = NULL;
 	if (!url || url[0] == '\0')
 		return;
 
@@ -53,7 +54,6 @@ void cgit_parse_url(const char *url)
 		}
 		if (cmd[1])
 			ctx.qry.page = xstrdup(cmd + 1);
-		return;
 	}
 }
 
-- 
2.12.0.rc2.230.ga28edc07cd



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

* [PATCH 3/3] cgit: don't set vpath unless repo is set
  2017-02-19 12:44 [PATCH 0/3] Fix segfault found by AFL john
  2017-02-19 12:44 ` [PATCH 1/3] ui-shared: don't print path crumbs without a repo john
  2017-02-19 12:45 ` [PATCH 2/3] parsing: clear query path before starting john
@ 2017-02-19 12:45 ` john
       [not found] ` <CAHmME9r8zY9qOqbg7fwuB1gW76nXVcsqJ-LT2-6sjD3SuoJ-HQ@mail.gmail.com>
  3 siblings, 0 replies; 6+ messages in thread
From: john @ 2017-02-19 12:45 UTC (permalink / raw)


After the previous two patches, this can be classified as a tidy up
rather than a bug fix, but I think it makes sense to group all of the
tests together before setting up the environment for the command to
execute.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgit.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/cgit.c b/cgit.c
index 1075753..1dae4b8 100644
--- a/cgit.c
+++ b/cgit.c
@@ -726,18 +726,18 @@ static void process_request(void)
 		return;
 	}
 
-	/* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual"
-	 * in-project path limit to be made available at ctx.qry.vpath.
-	 * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL).
-	 */
-	ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
-
 	if (cmd->want_repo && !ctx.repo) {
 		cgit_print_error_page(400, "Bad request",
 				"No repository selected");
 		return;
 	}
 
+	/* If cmd->want_vpath is set, assume ctx.qry.path contains a "virtual"
+	 * in-project path limit to be made available at ctx.qry.vpath.
+	 * Otherwise, no path limit is in effect (ctx.qry.vpath = NULL).
+	 */
+	ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
+
 	if (ctx.repo && prepare_repo_cmd())
 		return;
 
-- 
2.12.0.rc2.230.ga28edc07cd



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

* [PATCH 0/3] Fix segfault found by AFL
       [not found] ` <CAHmME9r8zY9qOqbg7fwuB1gW76nXVcsqJ-LT2-6sjD3SuoJ-HQ@mail.gmail.com>
@ 2017-02-19 19:04   ` Jason
  2017-02-20  1:48     ` peter
  0 siblings, 1 reply; 6+ messages in thread
From: Jason @ 2017-02-19 19:04 UTC (permalink / raw)


Excellent. Running AFL on cgit is a great idea. I'll merge and review when
I'm back at my desk on Tuesday.

On Feb 19, 2017 12:45, "John Keeping" <john at keeping.me.uk> wrote:

I set AFL [0] loose on CGit's URL input yesterday and it managed to find
one issue that leads to a segfault via a null dereference.

Either of the first or third patches fixes the segfault, but I much
prefer the first as a solid fix, the third is a bit too subtle as a way
to ensure that the necessary invariant holds.

The second patch also fixes the route that AFL found, but it's possible
to get the same effect using broken out query parameters like
"?p=log&path=foo" but I'm including it because it seems to make sense to
use the value of the final "url" parameter we receive fully rather than
some combination of that and a previous URL.

[0] http://lcamtuf.coredump.cx/afl/

John Keeping (3):
  ui-shared: don't print path crumbs without a repo
  parsing: clear query path before starting
  cgit: don't set vpath unless repo is set

 cgit.c      | 12 ++++++------
 parsing.c   |  2 +-
 ui-shared.c |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

--
2.12.0.rc2.230.ga28edc07cd

_______________________________________________
CGit mailing list
CGit at lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20170219/ae91003c/attachment-0001.html>


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

* [PATCH 0/3] Fix segfault found by AFL
  2017-02-19 19:04   ` [PATCH 0/3] Fix segfault found by AFL Jason
@ 2017-02-20  1:48     ` peter
  0 siblings, 0 replies; 6+ messages in thread
From: peter @ 2017-02-20  1:48 UTC (permalink / raw)


Hi Jason,

On Sun, Feb 19, 2017 at 08:04:49PM +0100, Jason A. Donenfeld wrote:
> Excellent. Running AFL on cgit is a great idea. I'll merge and review when
> I'm back at my desk on Tuesday.

Could you release a bugfix v1.1.1 afterwards? Debian is preparing for
the release of stretch and it would be perfect if I could upload a new
upstream version instead of cherry-picking the fixes.

Regards,
Peter


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

end of thread, other threads:[~2017-02-20  1:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-19 12:44 [PATCH 0/3] Fix segfault found by AFL john
2017-02-19 12:44 ` [PATCH 1/3] ui-shared: don't print path crumbs without a repo john
2017-02-19 12:45 ` [PATCH 2/3] parsing: clear query path before starting john
2017-02-19 12:45 ` [PATCH 3/3] cgit: don't set vpath unless repo is set john
     [not found] ` <CAHmME9r8zY9qOqbg7fwuB1gW76nXVcsqJ-LT2-6sjD3SuoJ-HQ@mail.gmail.com>
2017-02-19 19:04   ` [PATCH 0/3] Fix segfault found by AFL Jason
2017-02-20  1:48     ` peter

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