Skip to content

sql/pgwire/hba: add fuzzer#43805

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
madelynnblue:hba-fuzz
Jan 8, 2020
Merged

sql/pgwire/hba: add fuzzer#43805
craig[bot] merged 1 commit intocockroachdb:masterfrom
madelynnblue:hba-fuzz

Conversation

@madelynnblue
Copy link
Copy Markdown
Contributor

Release note: None

@madelynnblue madelynnblue requested a review from knz January 8, 2020 04:54
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@madelynnblue
Copy link
Copy Markdown
Contributor Author

madelynnblue commented Jan 8, 2020

This immediately found lots of bugs. Run it yourself with make fuzz 'PKG=./pkg/sql/pgwire/hba' 'TESTFLAGS=-v' to see. (You will need to go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build if you upgraded to go1.13.) Not even worthwhile to send you the crashes because it's so fast to generate them.

@knz
Copy link
Copy Markdown
Contributor

knz commented Jan 8, 2020

Woah this is absolutely fantastic 💖

I felt both humbled and very excited at the same time. This made my day!

@knz
Copy link
Copy Markdown
Contributor

knz commented Jan 8, 2020

I found this easier to troubleshoot:

func FuzzParseAndNormalize(data []byte) int {
  conf, err := ParseAndNormalize(string(data))
  if err != nil {
    return 0
  }
  s := conf.String()
  conf2, err := ParseAndNormalize(s)
  if err != nil {
    panic(fmt.Errorf(`-- original:
%s
-- parsed:
%# v
-- new:
%s
-- error:
%v`,
      string(data),
      pretty.Formatter(conf),
      s,
      err))
  }
  s2 := conf2.String()
  if s != s2 {
    panic(fmt.Errorf(`reparse mismatch:
-- original:
%s
-- new:
%# v
-- printed:
%s`,
      s,
      pretty.Formatter(conf2),
      s2))
  }
  return 1
}

@knz
Copy link
Copy Markdown
Contributor

knz commented Jan 8, 2020

All the errors so far stem from two limitations (I would not call them bugs):

  • if the conn type or auth method are the quoted empty string "" they are pretty-printed without the quotes and the column appears empty (but that would be rejected upon validation in pgwire).
  • if a column contains a control character that also happens to be whitespace, it is stripped/replaced by spaces upon pretty-printing.

The first one is easy to deal with, the second one I will deal with by rejecting control characters in the input altogether.

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM btw

Release note: None
@madelynnblue
Copy link
Copy Markdown
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request Jan 8, 2020
43805: sql/pgwire/hba: add fuzzer r=mjibson a=mjibson

Release note: None

Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 8, 2020

Build succeeded

@craig craig bot merged commit ef991fc into cockroachdb:master Jan 8, 2020
craig bot pushed a commit that referenced this pull request Jan 8, 2020
43792: batcheval: clean up remaning variable names of `{Reader,ReadWriter}` types r=irfansharif a=irfansharif

Ignore first commit, reviewed in #43764. 

We should be using {reader,readWriter} for
{Reader,ReadWriter} respectively instead. I'd skipped everything under
batcheval when working on #43265, back when I thought it'd be a good
idea to plumb in an engine.Batch throughout replica read codepaths. Due
to perf penalty as seen on #43388, I'm no longer going to be doing that.
This is the remaining work.

Release note: None


43811: hba: stricter parsing and better pretty-printing r=knz a=knz

The following defects were found by @mjibson using
`go-fuzz` (#43805) and are fixed by this patch:

- the code would parse then fail to pretty-print an empty connection
  type and auth method.
- the code would parse then pretty-print incorrectly a connection
  type or auth method containing commas or other special characters.
- the code would accept an empty string as address.
- the code would accept then fail to pretty-print columns containing
  special (control) characters.

Note that the code previously supported tabs (\t) and carriage
returns (\r) inside quoted strings, and this is now rejected. For most
fields, this does not matter, as these special characters were not
valid semantically anyway.

However, for the method options in the last column it is theoretically
possible for a method to wish to use such special characters. This is
not currently the case for the CCL `gss` method already implemented,
so this change is not introducing a regression. A comment is left in
the code to indicate what needs to be changed if a future method needs
this support.

Release note (security): CockroachDB now properly rejects control
characters in the value of the cluster setting
`server.host_based_authentication.configuration`. These characters
were previously accepted and would silently yield rules matching
differently from intended. Deployments careful to strip control
characters from their HBA configuration are not affected.

Co-authored-by: irfan sharif <irfanmahmoudsharif@gmail.com>
Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
@madelynnblue madelynnblue deleted the hba-fuzz branch January 8, 2020 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants