[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 52/87: libdiskfs: fix reference counting of peropen objects
From: |
Samuel Thibault |
Subject: |
[hurd] 52/87: libdiskfs: fix reference counting of peropen objects |
Date: |
Sun, 09 Nov 2014 11:05:03 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit 520ef2ed66d47bb81a55829a88dda81f62dc95e5
Author: Justus Winter <address@hidden>
Date: Fri Jun 20 13:54:28 2014 +0200
libdiskfs: fix reference counting of peropen objects
Previously, peropen objects were created with a reference count of
zero. Therefore, if diskfs_create_protid fails, passing such an
object to diskfs_release_peropen would lead to a reference count
underflow.
* libdiskfs/peropen-make.c (diskfs_peropen_make): Initialize reference
count to one.
* libdiskfs/protid-make.c (diskfs_start_protid): And consume this
reference on success. Update comment.
(diskfs_create_protid): Update comment.
* libdiskfs/diskfs.h: Update comments.
* libdiskfs/io-duplicate.c (diskfs_S_io_duplicate): Adjust reference
counting accordingly.
* libdiskfs/io-reauthenticate.c (diskfs_S_io_reauthenticate): Likewise.
* libdiskfs/io-restrict-auth.c (diskfs_S_io_restrict_auth): Likewise.
* doc/hurd.texi (Diskfs Internals): Update accordingly.
---
doc/hurd.texi | 4 ++--
libdiskfs/diskfs.h | 4 ++--
libdiskfs/io-duplicate.c | 3 +++
libdiskfs/io-reauthenticate.c | 2 ++
libdiskfs/io-restrict-auth.c | 3 +++
libdiskfs/peropen-make.c | 2 +-
libdiskfs/protid-make.c | 6 +++---
7 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/doc/hurd.texi b/doc/hurd.texi
index 07ddfb4..8fa6da7 100644
--- a/doc/hurd.texi
+++ b/doc/hurd.texi
@@ -4431,13 +4431,13 @@ provides.
@deftypefun error_t diskfs_create_protid (@w{struct peropen address@hidden,
@w{struct iouser address@hidden, @w{struct protid address@hidden)
Create and return a protid for an existing peropen @var{po} in
@var{cred}, referring to user @var{user}. The node @address@hidden>np}
-must be locked.
+must be locked. On success, a reference to @var{po} is consumed.
@end deftypefun
@deftypefun error_t diskfs_start_protid (@w{struct peropen address@hidden,
@w{struct protid address@hidden)
Build and return in @var{cred} a protid which has no user
identification, for peropen @var{po}. The node @address@hidden>np} must
-be locked.
+be locked. On success, a reference to @var{po} is consumed.
@end deftypefun
@deftypefun void diskfs_finish_protid (@w{struct protid address@hidden,
@w{struct iouser address@hidden)
diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index e328527..e59ba99 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -820,12 +820,12 @@ diskfs_create_node (struct node *dir, const char *name,
mode_t mode,
struct dirstat *ds);
/* Create and return a protid for an existing peropen PO in CRED,
- referring to user USER. */
+ referring to user USER. On success, consume a reference to PO. */
error_t diskfs_create_protid (struct peropen *po, struct iouser *user,
struct protid **cred);
/* Build and return in CRED a protid which has no user identification, for
- peropen PO. */
+ peropen PO. On success, consume a reference to PO. */
error_t diskfs_start_protid (struct peropen *po, struct protid **cred);
/* Finish building protid CRED started with diskfs_start_protid;
diff --git a/libdiskfs/io-duplicate.c b/libdiskfs/io-duplicate.c
index 45c4df5..a2e568b 100644
--- a/libdiskfs/io-duplicate.c
+++ b/libdiskfs/io-duplicate.c
@@ -32,6 +32,7 @@ diskfs_S_io_duplicate (struct protid *cred,
pthread_mutex_lock (&cred->po->np->lock);
+ refcount_ref (&cred->po->refcnt);
err = diskfs_create_protid (cred->po, cred->user, &newpi);
if (! err)
{
@@ -39,6 +40,8 @@ diskfs_S_io_duplicate (struct protid *cred,
*portpoly = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newpi);
}
+ else
+ refcount_deref (&cred->po->refcnt);
pthread_mutex_unlock (&cred->po->np->lock);
diff --git a/libdiskfs/io-reauthenticate.c b/libdiskfs/io-reauthenticate.c
index 69d78bc..649315f 100644
--- a/libdiskfs/io-reauthenticate.c
+++ b/libdiskfs/io-reauthenticate.c
@@ -35,11 +35,13 @@ diskfs_S_io_reauthenticate (struct protid *cred,
are a simpleroutine, so callers won't know to restart. */
pthread_mutex_lock (&cred->po->np->lock);
+ refcount_ref (&cred->po->refcnt);
do
err = diskfs_start_protid (cred->po, &newcred);
while (err == EINTR);
if (err)
{
+ refcount_deref (&cred->po->refcnt);
pthread_mutex_unlock (&cred->po->np->lock);
return err;
}
diff --git a/libdiskfs/io-restrict-auth.c b/libdiskfs/io-restrict-auth.c
index 011aa19..80c0b20 100644
--- a/libdiskfs/io-restrict-auth.c
+++ b/libdiskfs/io-restrict-auth.c
@@ -41,6 +41,7 @@ diskfs_S_io_restrict_auth (struct protid *cred,
return err;
pthread_mutex_lock (&cred->po->np->lock);
+ refcount_ref (&cred->po->refcnt);
err = diskfs_create_protid (cred->po, user, &newpi);
if (! err)
{
@@ -48,6 +49,8 @@ diskfs_S_io_restrict_auth (struct protid *cred,
*newportpoly = MACH_MSG_TYPE_MAKE_SEND;
ports_port_deref (newpi);
}
+ else
+ refcount_deref (&cred->po->refcnt);
pthread_mutex_unlock (&cred->po->np->lock);
iohelp_free_iouser (user);
diff --git a/libdiskfs/peropen-make.c b/libdiskfs/peropen-make.c
index 6d5ca01..788b9a7 100644
--- a/libdiskfs/peropen-make.c
+++ b/libdiskfs/peropen-make.c
@@ -31,7 +31,7 @@ diskfs_make_peropen (struct node *np, int flags, struct
peropen *context,
po->filepointer = 0;
po->lock_status = LOCK_UN;
- refcount_init (&po->refcnt, 0);
+ refcount_init (&po->refcnt, 1);
po->openstat = flags;
po->np = np;
po->path = NULL;
diff --git a/libdiskfs/protid-make.c b/libdiskfs/protid-make.c
index 22aaa2e..0b09299 100644
--- a/libdiskfs/protid-make.c
+++ b/libdiskfs/protid-make.c
@@ -20,7 +20,7 @@
#include <assert.h>
/* Build and return in CRED a protid which has no user identification, for
- peropen PO. */
+ peropen PO. On success, consume a reference to PO. */
error_t
diskfs_start_protid (struct peropen *po, struct protid **cred)
{
@@ -29,7 +29,7 @@ diskfs_start_protid (struct peropen *po, struct protid **cred)
sizeof (struct protid), cred);
if (! err)
{
- refcount_ref (&po->refcnt);
+ /* Consume a reference to po. */
(*cred)->po = po;
(*cred)->shared_object = MACH_PORT_NULL;
(*cred)->mapped = 0;
@@ -56,7 +56,7 @@ diskfs_finish_protid (struct protid *cred, struct iouser
*user)
}
/* Create and return a protid for an existing peropen PO in CRED for
- USER. */
+ USER. On success, consume a reference to PO. */
error_t
diskfs_create_protid (struct peropen *po, struct iouser *user,
struct protid **cred)
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 54/87: trans/mtab: use setnullauth to drop privileges, (continued)
- [hurd] 54/87: trans/mtab: use setnullauth to drop privileges, Samuel Thibault, 2014/11/09
- [hurd] 21/87: ext2fs: fix compiler warning, Samuel Thibault, 2014/11/09
- [hurd] 49/87: Add missing linefeed, Samuel Thibault, 2014/11/09
- [hurd] 58/87: libdiskfs: fix /servers/exec lookup, Samuel Thibault, 2014/11/09
- [hurd] 59/87: hurd: make memory_object parameter polymorphic, Samuel Thibault, 2014/11/09
- [hurd] 61/87: procfs: fix typo in comment, Samuel Thibault, 2014/11/09
- [hurd] 53/87: libtrivfs: fix typo, Samuel Thibault, 2014/11/09
- [hurd] 64/87: BSD apps want sin_zero cleared in sys_getname., Samuel Thibault, 2014/11/09
- [hurd] 60/87: trans/hello{, -mt}: properly escape contents in trivfs_append_args, Samuel Thibault, 2014/11/09
- [hurd] 66/87: exec: redzone page zero before loading anything, Samuel Thibault, 2014/11/09
- [hurd] 52/87: libdiskfs: fix reference counting of peropen objects,
Samuel Thibault <=
- [hurd] 62/87: hurd: add symbolic name for the mtab translator, Samuel Thibault, 2014/11/09
- [hurd] 70/87: procfs: generalize the translator linkage code, Samuel Thibault, 2014/11/09
- [hurd] 56/87: hurd: fix semantic of file_get_children, Samuel Thibault, 2014/11/09
- [hurd] 47/87: Make the ncursesw driver of the console client compile properly, Samuel Thibault, 2014/11/09
- [hurd] 65/87: exec: add proper argument parsing, add --device-master-port, Samuel Thibault, 2014/11/09
- [hurd] 18/87: hurd: fix type of optimal_transfer_size, Samuel Thibault, 2014/11/09
- [hurd] 50/87: sutils: add urandom device target to MAKEDEV, Samuel Thibault, 2014/11/09
- [hurd] 45/87: Revert "libpipe: fix calls to pipe_send with no data", Samuel Thibault, 2014/11/09
- [hurd] 57/87: include: detect use-after-free errors using the reference counts, Samuel Thibault, 2014/11/09
- [hurd] 73/87: libdiskfs: remove code counting cache misses, Samuel Thibault, 2014/11/09