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] [day] [month] [year] [list]
Date:	Mon, 22 Dec 2008 12:05:31 +0100
From:	"Bert Wesarg" <bert.wesarg@...glemail.com>
To:	"Sebastian Andrzej Siewior" <sebastian@...akpoint.cc>
Cc:	mtk.manpages@...il.com, linux-man@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	"Thomas Gleixner" <tglx@...utronix.de>,
	"Ulrich Drepper" <drepper@...hat.com>
Subject: Re: [PATCH v2] add man-page for pthread_mutexattr_setrobust_np()

>>> +static int create_new_lock(void)
>>> +{
>>> +    int fd;
>>> +    pthread_mutex_t cmutex = PTHREAD_MUTEX_INITIALIZER;
>>> +    pthread_mutexattr_t attr;
>>> +    int ret;
>>> +
>>> +    pthread_mutexattr_init(&attr);
>>> +    pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP);
>>> +    pthread_mutex_init(&cmutex, &attr);
>>> +
>>> +    fd = open(lock_name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR |
>>> +            S_IRGRP | S_IWGRP);
>>> +    if (fd < 0)
>>> +        return fd;
>>> +
>>> +    ret = write(fd, &cmutex, sizeof(cmutex));
>>I think its undefined behavior if you copy a struct pthread_mutex. You
>>should use mmap here too.
> Why should be this undefined? Is there something special about this
> struct? And why should this behave different with mmap() ?
If you would use mmap, you would initialize the mutex inside the
mmaped area, i.e. directly in the file.

To the copying:

Short answer: http://www.lambdacs.com/cpt/FAQ.html#Q15

Slightly longer:

pthread_mutex_t m1, m2;
pthread_mutex_init(&m1, NULL);
pthread_mutex_lock(&m1);
m2 = m1;
pthread_mutex_unlock(&m2);

How can you be sure, that you have unlocked m1 here?

Yes, you throw away the cmutex after returning from the function and
the copy inside the file is the only one left. I still think such code
should not be in a documentation.

Bert
>
> Sebastian
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ