lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 2 Dec 2016 20:07:04 -0200
From:   Marcelo Tosatti <mtosatti@...hat.com>
To:     Thomas Gleixner <tglx@...utronix.de>
Cc:     Fenghua Yu <fenghua.yu@...el.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] intelrdt: resctrl: recommend locking for resctrlfs

On Fri, Dec 02, 2016 at 12:20:29PM +0100, Thomas Gleixner wrote:
> On Thu, 1 Dec 2016, Marcelo Tosatti wrote:
> > 
> > There is a locking problem between different applications
> > reading/writing to resctrlfs directory at the same time (read the patch
> > below for details).
> > 
> > Suggest a standard locking scheme for applications to use.
> 
> ....
> 
> > +To coordinate atomic operations on resctrl and avoid the problem
> > +above, the following locking procedure is recommended:
> > +
> > +A) open /var/lock/resctrl/fs.lock with O_CREAT|O_EXCL.
> > +B) if success, write pid of program accessing the directory
> > +   structure to this file.
> > +C) read/write the directory structure.
> > +D) remove file.
> 
> What's wrong with using flock, which works from shell scripts as well?
> 
> Thanks,
> 
> 	tglx

Hi Thomas,

Nothing wrong with it... I'm just copying the behaviour of other
programs.

Actually, using flock(2) allows one to use LOCK_SH for readers and 
this allows consistent writer/reader behaviour (say, a reader
won't see a partially written directory).

NAME
       flock - apply or remove an advisory lock on an open file

SYNOPSIS
       #include <sys/file.h>

       int flock(int fd, int operation);

DESCRIPTION
       Apply  or remove an advisory lock on the open file specified by
fd.  The argument operation is one of
       the following:

           LOCK_SH  Place a shared lock.  More than one process may hold
a shared lock for a given file at a
                    given time.

           LOCK_EX  Place  an  exclusive lock.  Only one process may
hold an exclusive lock for a given file
                    at a given time.

           LOCK_UN  Remove an existing lock held by this process.

--- 

So the procedure would be:

    /var/lock/resctrl/fs.lock created previously in the filesystem.

WRITE LOCK:

A) Take flock(EXCLUSIVE) on /var/lock/resctrl/fs.lock
B) If success, write pid of the program to the file.
C) read/write the directory structure.
D) funlock

READ LOCK:

A) Take flock(SHARED) on /var/lock/resctrl/fs.lock
B) If success read the directory structure.
C) funlock


How about that?



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ