From patchwork Fri Jun 21 10:51:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 1120126 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.b="OqQ2nFK/"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Vb8W5yLlz9s00 for ; Fri, 21 Jun 2019 20:51:23 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8B5E13EAEBA for ; Fri, 21 Jun 2019 12:51:20 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 6E9DC3EA20C for ; Fri, 21 Jun 2019 12:51:18 +0200 (CEST) Received: from m12-11.163.com (m12-11.163.com [220.181.12.11]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id B9BD8601CEA for ; Fri, 21 Jun 2019 12:51:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=Btx7jz/aggn1xeBIFC F+9nqIcjPhrHcB9XvLYcV6TKA=; b=OqQ2nFK/9epbCCFp0G/dHJjWyhbhlhi1xD rhbFHwn+ao9l+N6sRtsxwa9d8M13vR7vyUr2bNAQnWwtAfgcjpZTQW8TgfdhmncI 7+O+2Ii10aJn3z5Sp4CGkqXFSc0qJv3KwyWE5cvW+gKzSwA4HyxFPro159nIf1vj 4eYheqzKQ= Received: from RHEL7U5GA_Intel64.localdomain (unknown [112.25.212.39]) by smtp7 (Coremail) with SMTP id C8CowAAnFeaitgxdoPNCBA--.13123S3; Fri, 21 Jun 2019 18:51:14 +0800 (CST) From: Xiao Yang To: ltp@lists.linux.it Date: Fri, 21 Jun 2019 18:51:11 +0800 Message-Id: <1561114271-8351-2-git-send-email-ice_yangxiao@163.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561114271-8351-1-git-send-email-ice_yangxiao@163.com> References: <1561114271-8351-1-git-send-email-ice_yangxiao@163.com> X-CM-TRANSID: C8CowAAnFeaitgxdoPNCBA--.13123S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxXrW5Wr4fGFW7XrW3tw47urg_yoWrAr13pr Z7Xa1DAw48tF1xG3y3G3W7Za18Jw1rJr4fG34ayw43CFs3JFWDtF4qqFy5tr12qrW7GFW3 GF4kXrsaga9xZ3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UhNVkUUUUU= X-Originating-IP: [112.25.212.39] X-CM-SenderInfo: 5lfhs5xdqj5xldr6il2tof0z/1tbiqALaXlc7I6OLWwAAsS X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/2] syscalls/futex_cmp_requeue02.c: Add new test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check various errnos for futex(FUTEX_CMP_REQUEUE). It's also a regression test for CVE-2018-6927: fbe0e839d1e2 ("futex: Prevent overflow by strengthen input validation") Signed-off-by: Xiao Yang --- runtest/syscalls | 1 + testcases/kernel/syscalls/futex/.gitignore | 1 + testcases/kernel/syscalls/futex/Makefile | 1 + .../kernel/syscalls/futex/futex_cmp_requeue02.c | 76 ++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 testcases/kernel/syscalls/futex/futex_cmp_requeue02.c diff --git a/runtest/syscalls b/runtest/syscalls index af5eda5..ff3e20e 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1550,6 +1550,7 @@ perf_event_open01 perf_event_open01 perf_event_open02 perf_event_open02 futex_cmp_requeue01 futex_cmp_requeue01 +futex_cmp_requeue02 futex_cmp_requeue02 futex_wait01 futex_wait01 futex_wait02 futex_wait02 futex_wait03 futex_wait03 diff --git a/testcases/kernel/syscalls/futex/.gitignore b/testcases/kernel/syscalls/futex/.gitignore index 4666a2c..68bc202 100644 --- a/testcases/kernel/syscalls/futex/.gitignore +++ b/testcases/kernel/syscalls/futex/.gitignore @@ -1,4 +1,5 @@ /futex_cmp_requeue01 +/futex_cmp_requeue02 /futex_wait01 /futex_wait02 /futex_wait03 diff --git a/testcases/kernel/syscalls/futex/Makefile b/testcases/kernel/syscalls/futex/Makefile index c4d5033..1a0c008 100644 --- a/testcases/kernel/syscalls/futex/Makefile +++ b/testcases/kernel/syscalls/futex/Makefile @@ -19,6 +19,7 @@ top_srcdir ?= ../../../.. futex_cmp_requeue01: LDLIBS+=-lrt +futex_cmp_requeue02: LDLIBS+=-lrt futex_wait02: LDLIBS+=-lrt futex_wake03: LDLIBS+=-lrt futex_wait03: CFLAGS+=-pthread diff --git a/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c b/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c new file mode 100644 index 0000000..3ea1942 --- /dev/null +++ b/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2019 Xiao Yang + * + * Description: + * Check various errnos for futex(FUTEX_CMP_REQUEUE). + * 1) futex(FUTEX_CMP_REQUEUE) with invalid val returns EINVAL. + * 2) futex(FUTEX_CMP_REQUEUE) with invalid val2 returns EINVAL. + * 3) futex(FUTEX_CMP_REQUEUE) with mismatched val3 returns EAGAIN. + * + * It's also a regression test for CVE-2018-6927: + * fbe0e839d1e2 ("futex: Prevent overflow by strengthen input validation") + */ + +#include +#include +#include + +#include "tst_test.h" +#include "futextest.h" + +static futex_t *futexes; + +static struct tcase { + int set_wakes; + int set_requeues; + int exp_val; + int exp_errno; +} tcases[] = { + {1, -1, FUTEX_INITIALIZER, EINVAL}, + {-1, 1, FUTEX_INITIALIZER, EINVAL}, + {1, 1, FUTEX_INITIALIZER + 1, EAGAIN}, +}; + +static void verify_futex_cmp_requeue(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + + TEST(futex_cmp_requeue(&futexes[0], tc->exp_val, &futexes[1], + tc->set_wakes, tc->set_requeues, 0)); + if (TST_RET != -1) { + tst_res(TFAIL, "futex_cmp_requeue() succeeded unexpectedly"); + return; + } + + if (TST_ERR != tc->exp_errno) { + tst_res(TFAIL | TTERRNO, + "futex_cmp_requeue() failed unexpectedly, expected %s", + tst_strerrno(tc->exp_errno)); + return; + } + + tst_res(TPASS | TTERRNO, "futex_cmp_requeue() failed as expected"); +} + +static void setup(void) +{ + futexes = SAFE_MMAP(NULL, sizeof(futex_t) * 2, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + + futexes[0] = FUTEX_INITIALIZER; + futexes[1] = FUTEX_INITIALIZER + 1; +} + +static void cleanup(void) +{ + if (futexes) + SAFE_MUNMAP((void *)futexes, sizeof(futex_t) * 2); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test = verify_futex_cmp_requeue, + .tcnt = ARRAY_SIZE(tcases), +};