From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kara Subject: Re: [LTP] [Bugme-new] [Bug 15909] New: open("a/", O_NOFOLLOW) fails with ELOOP if "a" is a symbolic link to a directory. Date: Wed, 12 May 2010 17:59:48 +0200 Message-ID: <20100512155948.GD3326@quack.suse.cz> References: <20100506143002.0381501b.akpm@linux-foundation.org> <20100511154850.GC2832@quack.suse.cz> <20100511162452.GD2832@quack.suse.cz> <1273595753.4875.1.camel@subratamodak.linux.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="GID0FwUMdk1T2AWN" Cc: Jan Kara , ltp-list@lists.sourceforge.net, tolzmann@molgen.mpg.de, bugzilla-daemon@bugzilla.kernel.org, Al Viro , bugme-daemon@bugzilla.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Christoph Hellwig , chrubis@suse.cz To: Subrata Modak Return-path: Received: from cantor.suse.de ([195.135.220.2]:46357 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755303Ab0ELP7z (ORCPT ); Wed, 12 May 2010 11:59:55 -0400 Content-Disposition: inline In-Reply-To: <1273595753.4875.1.camel@subratamodak.linux.ibm.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: --GID0FwUMdk1T2AWN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Tue 11-05-10 22:05:52, Subrata Modak wrote: > It would be great if you can shoot it in the form of a patch, mentioning > > 1. The GPL Lincense, > 2. The purpose of the test case, > 3. Exact location it goes, > 4. Which LTPROOT/runtest/ executes it With a help of Cyril I've created the attached patch and verified that the test fails on 2.6.33 but succeeds on 2.6.32... Honza -- Jan Kara SUSE Labs, CR --GID0FwUMdk1T2AWN Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="ltp-open-test.diff" Add O_NOFOLLOW open test with trailing slash In a situation where symlink (say 's') points to a directory, open("s/", O_NOFOLLOW) should succeed. Check for this. Signed-off-by: Jan Kara --- ltp/testcases/kernel/syscalls/open/open07.c.orig 2010-05-12 15:26:03.000000000 +0200 +++ ltp/testcases/kernel/syscalls/open/open07.c 2010-05-12 17:50:54.000000000 +0200 @@ -40,6 +40,9 @@ * 4. Create a symbolic link to a symbolically linked directory, and call * open(O_NOFOLLOW). Check that it returns ELOOP. * + * 5. Create a symbolic link to a directory, and call + * open("link/", O_NOFOLLOW). Check that it succeeds. + * * USAGE: * open07 [-c n] [-e] [-i n] [-I x] [-P x] [-t] * where, -c n : Run n copies concurrently. @@ -70,34 +73,35 @@ void setupfunc_test1(); void setupfunc_test2(); void setupfunc_test3(); void setupfunc_test4(); +void setupfunc_test5(); char *TCID = "open07"; -int TST_TOTAL = 4; +int TST_TOTAL = 5; extern int Tst_count; int fd1, fd2; -char file1[100], file2[100], file3[100]; - int exp_enos[] = {ELOOP, 0}; struct test_case_t { char *desc; - char *filename; + char filename[100]; int flags; int mode; void (*setupfunc)(); int exp_errno; - int fileHandle; + int fileHandle; } TC[] = { - { "Test for ELOOP on f2: f1 -> f2", file2, O_NOFOLLOW, 00700, + { "Test for ELOOP on f2: f1 -> f2", {}, O_NOFOLLOW, 00700, setupfunc_test1, ELOOP, 0}, - { "Test for ELOOP on d2: d1 -> d2", file2, O_NOFOLLOW, 00700, + { "Test for ELOOP on d2: d1 -> d2", {}, O_NOFOLLOW, 00700, setupfunc_test2, ELOOP, 0}, - { "Test for ELOOP on f3: f1 -> f2 -> f3", file3, O_NOFOLLOW, 00700, + { "Test for ELOOP on f3: f1 -> f2 -> f3", {}, O_NOFOLLOW, 00700, setupfunc_test3, ELOOP, 0}, - { "Test for ELOOP on d3: d1 -> d2 -> d3", file3, O_NOFOLLOW, 00700, + { "Test for ELOOP on d3: d1 -> d2 -> d3", {}, O_NOFOLLOW, 00700, setupfunc_test4, ELOOP, 0}, - { NULL, NULL, 0, 0, NULL, 0, 0} + { "Test for success on d2: d1 -> d2", {}, O_NOFOLLOW, 00700, + setupfunc_test5, 0, 0}, + { NULL, {}, 0, 0, NULL, 0, 0} }; int main(int ac, char **av) @@ -132,21 +136,34 @@ int main(int ac, char **av) TEST(open(TC[i].filename, TC[i].flags, TC[i].mode)); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - } - - TEST_ERROR_LOG(TEST_ERRNO); - - if (TEST_ERRNO != TC[i].exp_errno) { - tst_resm(TFAIL, "open returned unexpected " - "errno, expected: %d, got: %d", - TC[i].exp_errno, TEST_ERRNO); + if (TC[i].exp_errno != 0) { + if (TEST_RETURN != -1) { + tst_resm(TFAIL, "open succeeded " + "unexpectedly"); + } + TEST_ERROR_LOG(TEST_ERRNO); + + if (TEST_ERRNO != TC[i].exp_errno) { + tst_resm(TFAIL, "open returned " + "unexpected errno, expected: " + "%d, got: %d", + TC[i].exp_errno, TEST_ERRNO); + } else { + tst_resm(TPASS, "open returned " + "expected ELOOP error"); + } } else { - tst_resm(TPASS, "open returned expected " - "ELOOP error"); + if (TEST_RETURN == -1) { + tst_resm(TFAIL, "open failed " + "unexpectedly with errno %d", + TEST_ERRNO); + } else { + tst_resm(TPASS, "open succeeded as " + "expected"); + } } - close(TC[i].fileHandle); + + close(TC[i].fileHandle); } } cleanup(); @@ -157,6 +174,8 @@ int main(int ac, char **av) void setupfunc_test1() { + char file1[100], file2[100]; + sprintf(file1, "open03.1.%d", getpid()); sprintf(file2, "open03.2.%d", getpid()); if ((fd1 = creat(file1, 00700)) < 0) { @@ -167,11 +186,14 @@ setupfunc_test1() tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); /*NOTREACHED*/ } + strcpy(TC[0].filename, file2); } void setupfunc_test2() { + char file1[100], file2[100]; + sprintf(file1, "open03.3.%d", getpid()); sprintf(file2, "open03.4.%d", getpid()); if (mkdir(file1, 00700) < 0) { @@ -182,11 +204,14 @@ setupfunc_test2() tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); /*NOTREACHED*/ } + strcpy(TC[1].filename, file2); } void setupfunc_test3() { + char file1[100], file2[100], file3[100]; + sprintf(file1, "open03.5.%d", getpid()); sprintf(file2, "open03.6.%d", getpid()); sprintf(file3, "open03.7.%d", getpid()); @@ -202,11 +227,14 @@ setupfunc_test3() tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); /*NOTREACHED*/ } + strcpy(TC[2].filename, file3); } void setupfunc_test4() { + char file1[100], file2[100], file3[100]; + sprintf(file1, "open03.8.%d", getpid()); sprintf(file2, "open03.9.%d", getpid()); sprintf(file3, "open03.10.%d", getpid()); @@ -222,6 +250,26 @@ setupfunc_test4() tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); /*NOTREACHED*/ } + strcpy(TC[3].filename, file3); +} + +void +setupfunc_test5() +{ + char file1[100], file2[100]; + + sprintf(file1, "open11.3.%d", getpid()); + sprintf(file2, "open12.4.%d", getpid()); + if (mkdir(file1, 00700) < 0) { + tst_brkm(TBROK, cleanup, "mkdir(2) failed: errno: %d", errno); + /*NOTREACHED*/ + } + if (symlink(file1, file2) < 0) { + tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno); + /*NOTREACHED*/ + } + strcpy(TC[4].filename, file2); + strcat(TC[4].filename, "/"); } /* --GID0FwUMdk1T2AWN--