Skip to content

Commit 2aed8b4

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
SUNRPC: Convert auth_gss pipe detection to work in namespaces
This seems to have been overlooked when we did the namespace conversion. If a container is running a legacy version of rpc.gssd then it will be disrupted if the global 'pipe_version' is set by a container running the new version of rpc.gssd. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent abfdbd5 commit 2aed8b4

3 files changed

Lines changed: 30 additions & 19 deletions

File tree

‎net/sunrpc/auth_gss/auth_gss.c‎

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ struct gss_auth {
8787
};
8888

8989
/* pipe_version >= 0 if and only if someone has a pipe open. */
90-
static int pipe_version = -1;
91-
static atomic_t pipe_users = ATOMIC_INIT(0);
9290
static DEFINE_SPINLOCK(pipe_version_lock);
9391
static struct rpc_wait_queue pipe_version_rpc_waitqueue;
9492
static DECLARE_WAIT_QUEUE_HEAD(pipe_version_waitqueue);
@@ -268,34 +266,38 @@ struct gss_upcall_msg {
268266
char databuf[UPCALL_BUF_LEN];
269267
};
270268

271-
static int get_pipe_version(void)
269+
static int get_pipe_version(struct net *net)
272270
{
271+
struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
273272
int ret;
274273

275274
spin_lock(&pipe_version_lock);
276-
if (pipe_version >= 0) {
277-
atomic_inc(&pipe_users);
278-
ret = pipe_version;
275+
if (sn->pipe_version >= 0) {
276+
atomic_inc(&sn->pipe_users);
277+
ret = sn->pipe_version;
279278
} else
280279
ret = -EAGAIN;
281280
spin_unlock(&pipe_version_lock);
282281
return ret;
283282
}
284283

285-
static void put_pipe_version(void)
284+
static void put_pipe_version(struct net *net)
286285
{
287-
if (atomic_dec_and_lock(&pipe_users, &pipe_version_lock)) {
288-
pipe_version = -1;
286+
struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
287+
288+
if (atomic_dec_and_lock(&sn->pipe_users, &pipe_version_lock)) {
289+
sn->pipe_version = -1;
289290
spin_unlock(&pipe_version_lock);
290291
}
291292
}
292293

293294
static void
294295
gss_release_msg(struct gss_upcall_msg *gss_msg)
295296
{
297+
struct net *net = rpc_net_ns(gss_msg->auth->client);
296298
if (!atomic_dec_and_test(&gss_msg->count))
297299
return;
298-
put_pipe_version();
300+
put_pipe_version(net);
299301
BUG_ON(!list_empty(&gss_msg->list));
300302
if (gss_msg->ctx != NULL)
301303
gss_put_ctx(gss_msg->ctx);
@@ -441,7 +443,10 @@ static void gss_encode_msg(struct gss_upcall_msg *gss_msg,
441443
struct rpc_clnt *clnt,
442444
const char *service_name)
443445
{
444-
if (pipe_version == 0)
446+
struct net *net = rpc_net_ns(clnt);
447+
struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
448+
449+
if (sn->pipe_version == 0)
445450
gss_encode_v0_msg(gss_msg);
446451
else /* pipe_version == 1 */
447452
gss_encode_v1_msg(gss_msg, clnt, service_name);
@@ -457,7 +462,7 @@ gss_alloc_msg(struct gss_auth *gss_auth, struct rpc_clnt *clnt,
457462
gss_msg = kzalloc(sizeof(*gss_msg), GFP_NOFS);
458463
if (gss_msg == NULL)
459464
return ERR_PTR(-ENOMEM);
460-
vers = get_pipe_version();
465+
vers = get_pipe_version(rpc_net_ns(clnt));
461466
if (vers < 0) {
462467
kfree(gss_msg);
463468
return ERR_PTR(vers);
@@ -581,8 +586,8 @@ gss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred)
581586
gss_msg = gss_setup_upcall(gss_auth->client, gss_auth, cred);
582587
if (PTR_ERR(gss_msg) == -EAGAIN) {
583588
err = wait_event_interruptible_timeout(pipe_version_waitqueue,
584-
pipe_version >= 0, timeout);
585-
if (pipe_version < 0) {
589+
sn->pipe_version >= 0, timeout);
590+
if (sn->pipe_version < 0) {
586591
if (err == 0)
587592
sn->gssd_running = 0;
588593
warn_gssd();
@@ -719,20 +724,22 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
719724

720725
static int gss_pipe_open(struct inode *inode, int new_version)
721726
{
727+
struct net *net = inode->i_sb->s_fs_info;
728+
struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
722729
int ret = 0;
723730

724731
spin_lock(&pipe_version_lock);
725-
if (pipe_version < 0) {
732+
if (sn->pipe_version < 0) {
726733
/* First open of any gss pipe determines the version: */
727-
pipe_version = new_version;
734+
sn->pipe_version = new_version;
728735
rpc_wake_up(&pipe_version_rpc_waitqueue);
729736
wake_up(&pipe_version_waitqueue);
730-
} else if (pipe_version != new_version) {
737+
} else if (sn->pipe_version != new_version) {
731738
/* Trying to open a pipe of a different version */
732739
ret = -EBUSY;
733740
goto out;
734741
}
735-
atomic_inc(&pipe_users);
742+
atomic_inc(&sn->pipe_users);
736743
out:
737744
spin_unlock(&pipe_version_lock);
738745
return ret;
@@ -752,6 +759,7 @@ static int gss_pipe_open_v1(struct inode *inode)
752759
static void
753760
gss_pipe_release(struct inode *inode)
754761
{
762+
struct net *net = inode->i_sb->s_fs_info;
755763
struct rpc_pipe *pipe = RPC_I(inode)->pipe;
756764
struct gss_upcall_msg *gss_msg;
757765

@@ -770,7 +778,7 @@ gss_pipe_release(struct inode *inode)
770778
}
771779
spin_unlock(&pipe->lock);
772780

773-
put_pipe_version();
781+
put_pipe_version(net);
774782
}
775783

776784
static void

‎net/sunrpc/netns.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct sunrpc_net {
2828
wait_queue_head_t gssp_wq;
2929
struct rpc_clnt *gssp_clnt;
3030
int use_gss_proxy;
31+
int pipe_version;
32+
atomic_t pipe_users;
3133
struct proc_dir_entry *use_gssp_proc;
3234

3335
unsigned int gssd_running;

‎net/sunrpc/rpc_pipe.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ void rpc_pipefs_init_net(struct net *net)
10731073

10741074
mutex_init(&sn->pipefs_sb_lock);
10751075
sn->gssd_running = 1;
1076+
sn->pipe_version = -1;
10761077
}
10771078

10781079
/*

0 commit comments

Comments
 (0)