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

[Backport 5.2] cql: fix hang during certain SELECT statements #18716

Draft
wants to merge 1 commit into
base: branch-5.2
Choose a base branch
from

Conversation

mergify[bot]
Copy link

@mergify mergify bot commented May 16, 2024

The function intersection(r1,r2) in statement_restrictions.cc is used when several WHERE restrictions were applied to the same column. For example, for "WHERE b<1 AND b<2" the intersection of the two ranges is calculated to be b<1.

As noted in issue #18690, Scylla is inconsistent in where it allows or doesn't allow these intersecting restrictions. But where they are allowed they must be implemented correctly. And it turns out the function intersection() had a bug that caused it to sometimes enter an infinite loop - when the intent was only to call itself once with swapped parameters.

This patch includes a test reproducing this bug, and a fix for the bug. The test hangs before the fix, and passes after the fix.

While at it, I carefully reviewed the entire code used to implement the intersection() function to try to make sure that the bug we found was the only one. I also added a few more comments where I thought they were needed to understand complicated logic of the code.

The bug, the fix and the test were originally discovered by Michał Chojnowski.

Fixes #18688
Refs #18690

This patch should be backported to all extant branches: It is a bug that affected an actual user; The hang is a serious problem (in some sense it's even worse than a crash because we can't recover from it, while after a crash we restart Scylla), and this bug can even be used to DoS-attack Scylla by sending a CQL request with a maliciously-crafted set of restrictions.

(cherry picked from commit 2f6cd04)

Refs #18694

The function intersection(r1,r2) in statement_restrictions.cc is used
when several WHERE restrictions were applied to the same column.
For example, for "WHERE b<1 AND b<2" the intersection of the two ranges
is calculated to be b<1.

As noted in issue #18690, Scylla is inconsistent in where it allows or
doesn't allow these intersecting restrictions. But where they are
allowed they must be implemented correctly. And it turns out the
function intersection() had a bug that caused it to sometimes enter
an infinite loop - when the intent was only to call itself once with
swapped parameters.

This patch includes a test reproducing this bug, and a fix for the
bug. The test hangs before the fix, and passes after the fix.

While at it, I carefully reviewed the entire code used to implement
the intersection() function to try to make sure that the bug we found
was the only one. I also added a few more comments where I thought they
were needed to understand complicated logic of the code.

The bug, the fix and the test were originally discovered by
Michał Chojnowski.

Fixes #18688
Refs #18690

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
(cherry picked from commit 2f6cd04)

# Conflicts:
#	test/cql-pytest/test_restrictions.py
@mergify mergify bot requested a review from nyh as a code owner May 16, 2024 20:19
@mergify mergify bot added the conflicts label May 16, 2024
@mergify mergify bot assigned nyh May 16, 2024
Copy link
Author

mergify bot commented May 16, 2024

Cherry-pick of 2f6cd04 has failed:

On branch mergify/copy/branch-5.2/pr-18694
Your branch is up to date with 'origin/branch-5.2'.

You are currently cherry-picking commit 2f6cd043f0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   cql3/restrictions/statement_restrictions.cc

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   test/cql-pytest/test_restrictions.py

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@mergify mergify bot marked this pull request as draft May 16, 2024 20:20
@mykaul
Copy link
Contributor

mykaul commented May 26, 2024

@nyh - please resolve conflicts (unsure if we need this for 5.2 or not, btw).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants