From: Omar Sandoval Date: Fri, 6 Apr 2018 16:58:43 +0000 (-0700) Subject: loop: add ioctl lock imbalance regression test X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=140ee15de9f34630cb11f29e505a41fb2d7bec48;p=users%2Fsagi%2Fblktests.git loop: add ioctl lock imbalance regression test Signed-off-by: Omar Sandoval --- diff --git a/src/.gitignore b/src/.gitignore index 3bb6b7f..bdb2585 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,4 +1,5 @@ /loblksize +/loop_get_status_null /openclose -/sg/syzkaller1 /sg/dxfer-from-dev +/sg/syzkaller1 diff --git a/src/Makefile b/src/Makefile index b94fa71..787df37 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,9 @@ -TARGETS := sg/dxfer-from-dev sg/syzkaller1 loblksize openclose +TARGETS := \ + loblksize \ + loop_get_status_null \ + openclose \ + sg/dxfer-from-dev \ + sg/syzkaller1 CFLAGS := -O2 diff --git a/src/loop_get_status_null.c b/src/loop_get_status_null.c new file mode 100644 index 0000000..c233847 --- /dev/null +++ b/src/loop_get_status_null.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void usage(const char *progname) +{ + fprintf(stderr, "usage: %s PATH [64]\n", progname); + exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) +{ + unsigned long cmd; + int ret; + int fd; + + if (argc != 2 && argc != 3) + usage(argv[0]); + + if (argc == 3) { + if (strcmp(argv[2], "64") == 0) + cmd = LOOP_GET_STATUS64; + else + usage(argv[0]); + } else { + cmd = LOOP_GET_STATUS; + } + + fd = open(argv[1], O_RDONLY); + if (fd == -1) { + perror("open"); + return EXIT_FAILURE; + } + + ret = ioctl(fd, cmd, NULL); + if (ret == -1) { + if (errno == EINVAL) { + printf("Got EINVAL\n"); + } else { + perror("ioctl"); + close(fd); + return EXIT_FAILURE; + } + } else { + printf("Did not get EINVAL\n"); + } + + close(fd); + return EXIT_SUCCESS; +} diff --git a/tests/loop/005 b/tests/loop/005 new file mode 100755 index 0000000..41cf5a3 --- /dev/null +++ b/tests/loop/005 @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Test the LOOP_GET_STATUS{,64} error case where the passed argument is NULL. +# Regression test for patch "loop: fix LOOP_GET_STATUS lock imbalance". +# +# Copyright (C) 2018 Omar Sandoval +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +DESCRIPTION="call LOOP_GET_STATUS{,64} with a NULL arg" + +QUICK=1 + +requires() { + _have_src_program loop_get_status_null +} + +test() { + local loop_dev + + echo "Running ${TEST_NAME}" + + truncate -s 1M "$TMPDIR/file" + if ! loop_dev="$(losetup -f --show "$TMPDIR/file")"; then + return 1 + fi + + "$SRCDIR/loop_get_status_null" "$loop_dev" + "$SRCDIR/loop_get_status_null" "$loop_dev" 64 + + losetup -d "$loop_dev" + + echo "Test complete" +} diff --git a/tests/loop/005.out b/tests/loop/005.out new file mode 100644 index 0000000..6354da5 --- /dev/null +++ b/tests/loop/005.out @@ -0,0 +1,4 @@ +Running loop/005 +Got EINVAL +Got EINVAL +Test complete