Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure setacl can never set a username which breaks the DB format #2378

Closed
brong opened this issue May 28, 2018 · 14 comments
Closed

Make sure setacl can never set a username which breaks the DB format #2378

brong opened this issue May 28, 2018 · 14 comments
Assignees
Labels
2.5 affects 2.5

Comments

@brong
Copy link
Member

brong commented May 28, 2018

from the mailing list: ouch:

After running setaclmailbox some/mailbox "group:name with spaces" all,
all attempts to access the mailbox in any way either result in an
"Invalid identifier" error message, or can't even find the mailbox.

We shouldn't allow that!

@brong
Copy link
Member Author

brong commented May 28, 2018

Would be good to backport this one to both 3.0 and 2.5.

@elliefm elliefm added 2.5 affects 2.5 3.0 affects 3.0 3.1 affects 3.1 dev releases labels May 29, 2018
@elliefm
Copy link
Contributor

elliefm commented May 29, 2018

I think 3.0 and 3.1 are probably going to crash on this, rather than drop junk into the database. Look at how they handle the identifier:

cyrus-imapd/imap/mboxlist.c

Lines 1986 to 1989 in ad3b3e5

/* round trip identifier to potentially strip domain */
mbname_t *mbname = mbname_from_userid(identifier);
/* XXX - enforce cross domain restrictions */
identifier = mbname_userid(mbname);

Pretty sure that's gonna result in identifier = NULL?

Creating a Cassandane test for this to compare across versions...

@elliefm
Copy link
Contributor

elliefm commented May 29, 2018

#1851 looks related to this

@elliefm
Copy link
Contributor

elliefm commented May 29, 2018

Do we have any documentation or knowledge on how groups with Cyrus are expected to work? OP on the mailing list reckons this wasn't a problem for 2.4

@brong
Copy link
Member Author

brong commented May 29, 2018

Ouch! For a start, that's totally b0rkened in 3.0+, because it doesn't handle groups at all.

Second: in 2.4 it used tabs to separate the ACLs, which I guess is how that worked.

In 2.5, it's a dlist - so it SHOULD be storing correctly, but maybe it's not serialising correctly.

@elliefm
Copy link
Contributor

elliefm commented May 29, 2018

Oh I see -- the lib/acl* code still uses tab delimitations internally, but _write_acl() in imap/mboxlist.c converts those into dlist format.

@elliefm
Copy link
Contributor

elliefm commented May 29, 2018

At this point it's not really clear to me whether it's bad data being written into the mailboxes.db, or good data that's being misparsed later.

If it's the latter, the bug might be in the dlist_parsesax implementation. It's never changed since its initial commit (other than the tabs->spaces), and nothing else uses it, so an edge-case here wouldn't turn up anywhere else that uses dlists.

Really need some data! Will ask OP on the list.

@creshal
Copy link

creshal commented May 29, 2018

cyr_dbtool show spits out the following:

some.mailbox	%(A %(mailbox lrswipkxtecda group:group1 lrswipkxtecdan group:group2 lrswipkxtecda group:group with spaces lrswipkxtecdan) P default M 1527515381)
some.mailbox.Sub	%(A %(mailbox lrswipkxtecda group:group1 lrswipkxtecdan group:group2 lrswipkxtecda group:group with spaces lrswipkxtecdan) P default M 1527515381)
some.mailbox.Sub2	%(A %(mailbox lrswipkxtecda group:group1 lrswipkxtecdan group:group2 lrswipkxtecda group:group with spaces lrswipkxtecdan) P default M 1527515381)
some.mailbox.Sub3	%(A %(mailbox lrswipkxtecda group:group1 lrswipkxtecdan group:group2 lrswipkxtecda group:group with spaces lrswipkxtecdan) P default M 1527515382)
some.mailbox.Sub4	%(A %(mailbox lrswipkxtecda group:group1 lrswipkxtecdan group:group2 lrswipkxtecda group:group with spaces lrswipkxtecdan) P default M 1527515382)
some.mailbox.Sub5	%(A %(mailbox lrswipkxtecda group:group1 lrswipkxtecdan group:group2 lrswipkxtecda group:group with spaces lrswipkxtecdan) P default M 1527515382)

cyrus.header looks like this:

Cyrus mailbox header
"The best thing about this system was that it had lots of goals."
	--Jim Morris on Andrew
	118c711353ba6de0
$Forwarded Junk NonJunk
mailbox	lrswipkxtecda	group:group1	lrswipkxtecdan	group:group2	lrswipkxtecda	group:group with spaces	lrswipkxtecdan	

(In case github eats formatting: Records are separated with \t, spaces in the group name are spaces, and there's a trailing \t at the end of the line)


I managed to redirect incoming mails to a new mailbox, and nobody currently needs the mails in this one, so I'm in no rush to repair it. If you need any other data, just poke me here or via email.

@creshal
Copy link

creshal commented May 29, 2018

OP on the mailing list reckons this wasn't a problem for 2.4

No, I don't think it ever worked in older versions. I can't remember trying, at least.

@karagian
Copy link

No, I don't think it ever worked in older versions. I can't remember trying, at least.

I can confirm that there was no problem with acls regarding groups contains spaces in version 2.4. I had tested it when I reported #1851

@elliefm
Copy link
Contributor

elliefm commented May 30, 2018

some.mailbox %(A %(mailbox lrswipkxtecda group:group1 lrswipkxtecdan group:group2 lrswipkxtecda group:group with spaces lrswipkxtecdan) P default M 1527515381)

Okay, that looks like it's being written badly to the mailboxes db, which surprises me because reading the code, I thought it was tabs in there too. So the deserialisation is breaking because the serialisation was bad. That's progress, thanks! :)

The cyrus.header looks fine to me, but I don't think it gets looked at on this code path.

@elliefm
Copy link
Contributor

elliefm commented May 30, 2018

Okay I've found the cause, 2.5 is currently missing this commit: 0565460

In the dlist for the A entry, the identifier/rights pairs are key/value pairs, but 2.5 dlist_print() doesn't atomise keys (only values), so when the key contains spaces it gets corrupted.

@elliefm
Copy link
Contributor

elliefm commented May 30, 2018

That commit is now backported to the 2.5 branch as 59ee719, and will be in the next 2.5 release. I think it will probably apply cleanly onto 2.5.10 sources in the meantime, but ymmv.

Now to unbork 3.0/master...

@elliefm elliefm removed 3.0 affects 3.0 3.1 affects 3.1 dev releases labels Jun 13, 2018
@elliefm
Copy link
Contributor

elliefm commented Jun 13, 2018

I've added some tests, and verified that 3.0 and master are fine :)

@elliefm elliefm closed this as completed Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.5 affects 2.5
Projects
None yet
Development

No branches or pull requests

4 participants