Skip to content

Commit 64a38e8

Browse files
DaveWysochanskiRHJ. Bruce Fields
authored andcommitted
SUNRPC: Track writers of the 'channel' file to improve cache_listeners_exist
The sunrpc cache interface is susceptible to being fooled by a rogue process just reading a 'channel' file. If this happens the kernel may think a valid daemon exists to service the cache when it does not. For example, the following may fool the kernel: cat /proc/net/rpc/auth.unix.gid/channel Change the tracking of readers to writers when considering whether a listener exists as all valid daemon processes either open a channel file O_RDWR or O_WRONLY. While this does not prevent a rogue process from "stealing" a message from the kernel, it does at least improve the kernels perception of whether a valid process servicing the cache exists. Signed-off-by: Dave Wysochanski <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 609488b commit 64a38e8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

include/linux/sunrpc/cache.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ struct cache_detail {
107107
/* fields for communication over channel */
108108
struct list_head queue;
109109

110-
atomic_t readers; /* how many time is /chennel open */
111-
time_t last_close; /* if no readers, when did last close */
112-
time_t last_warn; /* when we last warned about no readers */
110+
atomic_t writers; /* how many time is /channel open */
111+
time_t last_close; /* if no writers, when did last close */
112+
time_t last_warn; /* when we last warned about no writers */
113113

114114
union {
115115
struct proc_dir_entry *procfs;

net/sunrpc/cache.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void sunrpc_init_cache_detail(struct cache_detail *cd)
373373
spin_lock(&cache_list_lock);
374374
cd->nextcheck = 0;
375375
cd->entries = 0;
376-
atomic_set(&cd->readers, 0);
376+
atomic_set(&cd->writers, 0);
377377
cd->last_close = 0;
378378
cd->last_warn = -1;
379379
list_add(&cd->others, &cache_list);
@@ -1029,11 +1029,13 @@ static int cache_open(struct inode *inode, struct file *filp,
10291029
}
10301030
rp->offset = 0;
10311031
rp->q.reader = 1;
1032-
atomic_inc(&cd->readers);
1032+
10331033
spin_lock(&queue_lock);
10341034
list_add(&rp->q.list, &cd->queue);
10351035
spin_unlock(&queue_lock);
10361036
}
1037+
if (filp->f_mode & FMODE_WRITE)
1038+
atomic_inc(&cd->writers);
10371039
filp->private_data = rp;
10381040
return 0;
10391041
}
@@ -1062,8 +1064,10 @@ static int cache_release(struct inode *inode, struct file *filp,
10621064
filp->private_data = NULL;
10631065
kfree(rp);
10641066

1067+
}
1068+
if (filp->f_mode & FMODE_WRITE) {
1069+
atomic_dec(&cd->writers);
10651070
cd->last_close = seconds_since_boot();
1066-
atomic_dec(&cd->readers);
10671071
}
10681072
module_put(cd->owner);
10691073
return 0;
@@ -1171,7 +1175,7 @@ static void warn_no_listener(struct cache_detail *detail)
11711175

11721176
static bool cache_listeners_exist(struct cache_detail *detail)
11731177
{
1174-
if (atomic_read(&detail->readers))
1178+
if (atomic_read(&detail->writers))
11751179
return true;
11761180
if (detail->last_close == 0)
11771181
/* This cache was never opened */

0 commit comments

Comments
 (0)