mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Doug Chapman <doug.chapman@hp.com>
To: linux-kernel@vger.kernel.org, bfields@citi.umich.edu,
	hch@infradead.org, doug.chapman@hp.com
Subject: post 2.6.21 regression in F_GETLK
Date: Thu, 10 May 2007 14:56:15 -0400	[thread overview]
Message-ID: <1178823375.7247.11.camel@dchapman.boston.redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]

A recent regression (introduced after 2.6.21) was caught by the LTP test
fcntl11.  It appears that F_GETLK is not properly checking for existing
F_RDLCK and allows taking out a write lock.

This can be demonstrated by either running fcntl11 from the LTP suite or
I have hacked up a much shorter version which demonstrates the issue and
am attaching it.

Using git bisect I came up with this commit as the one that introduced
the issue.  I briefly tried to back this out from the current tree but
appears a lot has change since then so I will need to try that manually.


commit c2fa1b8a6c059dd08a802545fed3badc8df2adc1
Author: J. Bruce Fields <bfields@citi.umich.edu>
Date:   Tue Feb 20 16:10:11 2007 -0500

    locks: create posix-to-flock helper functions

    Factor out a bit of messy code by creating posix-to-flock counterparts
    to the existing flock-to-posix helper functions.

    Cc: Christoph Hellwig <hch@infradead.org>
    Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>




- Doug


[-- Attachment #2: simple_fcntl_test.c --]
[-- Type: text/x-csrc, Size: 2113 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#define PATH_MAX 80
#define STRING          "abcdefghijklmnopqrstuvwxyz\n"

int fd;

char *locktypes[] = { "F_RDLCK", "F_WRLCK", "F_UNLCK" };


int
do_lock (int cmd, short type, short whence, int start, int len)
{
	struct flock fl;

	fl.l_type = type;
	fl.l_whence = whence;
	fl.l_start = start;
	fl.l_len = len;
	return (fcntl (fd, cmd, &fl));
}

int
test_lock (int type, int start, int len, int expected)
{
	struct flock fl;

	fflush (stdout);
	if (fork () == 0) {
		fl.l_type = type;
		fl.l_whence = SEEK_SET;
		fl.l_start = start;
		fl.l_len = len;
		fl.l_pid = 0;
		if (fcntl (fd, F_GETLK, &fl) < 0) {
			perror ("fcntl");
			exit (1);
		}

		if (fl.l_type == expected) {
			printf ("PASS\n");
		} else {
			printf ("FAILED\n");
			printf ("\ttype = %s, expect %s\n",
				locktypes[fl.l_type], locktypes[expected]);
			printf ("\tstart = %d\n", fl.l_start);
			printf ("\tlen = %d\n", fl.l_len);
			printf ("\tpid = %d\n", fl.l_pid);
		}
		exit (0);
	} else {
		wait (NULL);
	}

	return 0;
}

main ()
{
	char *buf = STRING;
	char template[PATH_MAX];
	struct flock fl;

	snprintf (template, PATH_MAX, "tempfile.XXXXXX");

	if ((fd = mkstemp (template)) < 0) {
		perror ("mkstemp");
		fprintf (stderr, "Couldn't open temp file! errno = %d",
			 errno);
		exit (1);
	}

	if (write (fd, buf, strlen (STRING)) < 0) {
		perror ("write");
		fprintf (stderr, "Couldn't write to temp file! errno = %d",
			 errno);
		exit (1);
	}

	/*
	 * Add a write lock to the middle of the file and a read
	 * at the begining
	 */
	if (do_lock (F_SETLK, (short) F_WRLCK, (short) 0, 10, 5) < 0) {
		fprintf (stderr, "fcntl on file failed, errno =%d", errno);
		exit (1);
	}

	if (do_lock (F_SETLK, (short) F_RDLCK, (short) 0, 1, 5) < 0) {
		fprintf (stderr, "fcntl on file failed, errno =%d", errno);
		exit (1);
	}

	/* this first test fails */
	printf ("child will try to get a F_WRLCK on the same area that the F_RDLCK already exists\n");
	printf ("it should reject due to the F_RDLCK\n");
	test_lock (F_WRLCK, 1, 5, F_RDLCK);

}

             reply	other threads:[~2007-05-10 18:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-10 18:56 Doug Chapman [this message]
2007-05-10 19:14 ` Doug Chapman
2007-05-10 19:30 ` J. Bruce Fields
2007-05-10 19:38   ` J. Bruce Fields
2007-05-10 20:23     ` J. Bruce Fields
2007-05-10 21:01       ` Doug Chapman
2007-05-10 21:04         ` J. Bruce Fields
2007-05-10 21:35           ` J. Bruce Fields
2007-05-10 20:24     ` Doug Chapman
2007-05-10 22:38   ` [PATCH] locks: fix F_GETLK regression (failure to find conflicts) J. Bruce Fields
2007-05-10 23:30     ` Doug Chapman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1178823375.7247.11.camel@dchapman.boston.redhat.com \
    --to=doug.chapman@hp.com \
    --cc=bfields@citi.umich.edu \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®