UPSTREAM: futex: futex_wake_op, do not fail on invalid op [chromiumos/third_party/kernel : chromeos-4.4]

24 views
Skip to first unread message

linux-patches-robot (Gerrit)

unread,
Apr 7, 2020, 12:57:42 PM4/7/20
to chromium-...@chromium.org

linux-patches-robot has uploaded this change for review.

View Change

UPSTREAM: futex: futex_wake_op, do not fail on invalid op

In commit 30d6e0a4190d ("futex: Remove duplicated code and fix undefined
behaviour"), I let FUTEX_WAKE_OP to fail on invalid op. Namely when op
should be considered as shift and the shift is out of range (< 0 or > 31).

But strace's test suite does this madness:

futex(0x7fabd78bcffc, 0x5, 0xfacefeed, 0xb, 0x7fabd78bcffc, 0xa0caffee);
futex(0x7fabd78bcffc, 0x5, 0xfacefeed, 0xb, 0x7fabd78bcffc, 0xbadfaced);
futex(0x7fabd78bcffc, 0x5, 0xfacefeed, 0xb, 0x7fabd78bcffc, 0xffffffff);

When I pick the first 0xa0caffee, it decodes as:

0x80000000 & 0xa0caffee: oparg is shift
0x70000000 & 0xa0caffee: op is FUTEX_OP_OR
0x0f000000 & 0xa0caffee: cmp is FUTEX_OP_CMP_EQ
0x00fff000 & 0xa0caffee: oparg is sign-extended 0xcaf = -849
0x00000fff & 0xa0caffee: cmparg is sign-extended 0xfee = -18

That means the op tries to do this:

(futex |= (1 << (-849))) == -18

which is completely bogus. The new check of op in the code is:

if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) {
if (oparg < 0 || oparg > 31)
return -EINVAL;
oparg = 1 << oparg;
}

which results obviously in the "Invalid argument" errno:

FAIL: futex
===========

futex(0x7fabd78bcffc, 0x5, 0xfacefeed, 0xb, 0x7fabd78bcffc, 0xa0caffee) = -1: Invalid argument
futex.test: failed test: ../futex failed with code 1

So let us soften the failure to print only a (ratelimited) message, crop
the value and continue as if it were right. When userspace keeps up, we
can switch this to return -EINVAL again.

[v2] Do not return 0 immediatelly, proceed with the cropped value.

Fixes: 30d6e0a4190d ("futex: Remove duplicated code and fix undefined behaviour")
Signed-off-by: Jiri Slaby <jsl...@suse.cz>
Cc: Ingo Molnar <mi...@redhat.com>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Darren Hart <dvh...@infradead.org>
Signed-off-by: Linus Torvalds <torv...@linux-foundation.org>

(cherry picked from commit e78c38f6bdd900b2ad9ac9df8eff58b745dc5b3c)

BUG=None
TEST=None

Signed-off-by: Linux Patches Robot <linux-pat...@chromeos-missing-patches.google.com.iam.gserviceaccount.com>
Change-Id: I2db9d236387a5b7e7a5c30981c0268ac27d11b9e
---
M kernel/futex.c
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 1cac470..bb0f5a9 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -1479,8 +1479,16 @@
int oldval, ret;

if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) {
- if (oparg < 0 || oparg > 31)
- return -EINVAL;
+ if (oparg < 0 || oparg > 31) {
+ char comm[sizeof(current->comm)];
+ /*
+ * kill this print and return -EINVAL when userspace
+ * is sane again
+ */
+ pr_info_ratelimited("futex_wake_op: %s tries to shift op by %d; fix this program\n",
+ get_task_comm(comm, current), oparg);
+ oparg &= 31;
+ }
oparg = 1 << oparg;
}


To view, visit change 2140311. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: chromiumos/third_party/kernel
Gerrit-Branch: chromeos-4.4
Gerrit-Change-Id: I2db9d236387a5b7e7a5c30981c0268ac27d11b9e
Gerrit-Change-Number: 2140311
Gerrit-PatchSet: 1
Gerrit-MessageType: newchange

Guenter Roeck (Gerrit)

unread,
Apr 7, 2020, 6:08:03 PM4/7/20
to linux-patches-robot, Sean Paul

Patch set 1:Commit-Queue +1

View Change

    To view, visit change 2140311. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: chromiumos/third_party/kernel
    Gerrit-Branch: chromeos-4.4
    Gerrit-Change-Id: I2db9d236387a5b7e7a5c30981c0268ac27d11b9e
    Gerrit-Change-Number: 2140311
    Gerrit-PatchSet: 1
    Gerrit-Reviewer: Guenter Roeck <gro...@chromium.org>
    Gerrit-Reviewer: Sean Paul <sean...@chromium.org>
    Gerrit-Comment-Date: Tue, 07 Apr 2020 22:07:58 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Guenter Roeck (Gerrit)

    unread,
    Apr 8, 2020, 12:18:35 PM4/8/20
    to linux-patches-robot, Sean Paul

    cryptohome build (?) failure

    View Change

      To view, visit change 2140311. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: chromiumos/third_party/kernel
      Gerrit-Branch: chromeos-4.4
      Gerrit-Change-Id: I2db9d236387a5b7e7a5c30981c0268ac27d11b9e
      Gerrit-Change-Number: 2140311
      Gerrit-PatchSet: 1
      Gerrit-Reviewer: Guenter Roeck <gro...@chromium.org>
      Gerrit-Reviewer: Sean Paul <sean...@chromium.org>
      Gerrit-CC: Commit Bot <commi...@chromium.org>
      Gerrit-Comment-Date: Wed, 08 Apr 2020 16:18:26 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: No
      Gerrit-MessageType: comment

      Guenter Roeck (Gerrit)

      unread,
      Apr 8, 2020, 12:41:47 PM4/8/20
      to linux-patches-robot, Sean Paul

      Patch set 1:Commit-Queue +1

      View Change

        To view, visit change 2140311. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: chromiumos/third_party/kernel
        Gerrit-Branch: chromeos-4.4
        Gerrit-Change-Id: I2db9d236387a5b7e7a5c30981c0268ac27d11b9e
        Gerrit-Change-Number: 2140311
        Gerrit-PatchSet: 1
        Gerrit-Reviewer: Guenter Roeck <gro...@chromium.org>
        Gerrit-Reviewer: Sean Paul <sean...@chromium.org>
        Gerrit-CC: Commit Bot <commi...@chromium.org>
        Gerrit-Comment-Date: Wed, 08 Apr 2020 16:41:41 +0000
        Reply all
        Reply to author
        Forward
        0 new messages