Skip to content

Commit

Permalink
sunrpc: add a generic rq_flags field to svc_rqst and move rq_secure t…
Browse files Browse the repository at this point in the history
…o it

In a later patch, we're going to need some atomic bit flags. Since that
field will need to be an unsigned long, we mitigate that space
consumption by migrating some other bitflags to the new field. Start
with the rq_secure flag.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
Jeff Layton authored and J. Bruce Fields committed Dec 9, 2014
1 parent 2941b0e commit 4d152e2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions fs/nfsd/nfscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp)
/* From the hall of fame of impractical attacks:
* Is this a user who tries to snoop on the cache? */
rtn = RC_DOIT;
if (!rqstp->rq_secure && rp->c_secure)
if (!test_bit(RQ_SECURE, &rqstp->rq_flags) && rp->c_secure)
goto out;

/* Compose RPC reply header */
Expand Down Expand Up @@ -579,7 +579,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
spin_lock(&b->cache_lock);
drc_mem_usage += bufsize;
lru_put_end(b, rp);
rp->c_secure = rqstp->rq_secure;
rp->c_secure = test_bit(RQ_SECURE, &rqstp->rq_flags);
rp->c_type = cachetype;
rp->c_state = RC_DONE;
spin_unlock(&b->cache_lock);
Expand Down
2 changes: 1 addition & 1 deletion fs/nfsd/nfsfh.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
int flags = nfsexp_flags(rqstp, exp);

/* Check if the request originated from a secure port. */
if (!rqstp->rq_secure && !(flags & NFSEXP_INSECURE_PORT)) {
if (!test_bit(RQ_SECURE, &rqstp->rq_flags) && !(flags & NFSEXP_INSECURE_PORT)) {
RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
dprintk("nfsd: request from insecure port %s!\n",
svc_print_addr(rqstp, buf, sizeof(buf)));
Expand Down
4 changes: 2 additions & 2 deletions include/linux/sunrpc/svc.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ struct svc_rqst {
u32 rq_vers; /* program version */
u32 rq_proc; /* procedure number */
u32 rq_prot; /* IP protocol */
unsigned short
rq_secure : 1; /* secure port */
#define RQ_SECURE (0) /* secure port */
unsigned long rq_flags; /* flags field */
unsigned short rq_local : 1; /* local request */

void * rq_argp; /* decoded arguments */
Expand Down
17 changes: 13 additions & 4 deletions include/trace/events/sunrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ TRACE_EVENT(xs_tcp_data_recv,
__entry->copied, __entry->reclen, __entry->offset)
);

#define show_rqstp_flags(flags) \
__print_flags(flags, "|", \
{ (1UL << RQ_SECURE), "RQ_SECURE"})

TRACE_EVENT(svc_recv,
TP_PROTO(struct svc_rqst *rqst, int status),

Expand All @@ -421,16 +425,19 @@ TRACE_EVENT(svc_recv,
__field(struct sockaddr *, addr)
__field(__be32, xid)
__field(int, status)
__field(unsigned long, flags)
),

TP_fast_assign(
__entry->addr = (struct sockaddr *)&rqst->rq_addr;
__entry->xid = status > 0 ? rqst->rq_xid : 0;
__entry->status = status;
__entry->flags = rqst->rq_flags;
),

TP_printk("addr=%pIScp xid=0x%x status=%d", __entry->addr,
be32_to_cpu(__entry->xid), __entry->status)
TP_printk("addr=%pIScp xid=0x%x status=%d flags=%s", __entry->addr,
be32_to_cpu(__entry->xid), __entry->status,
show_rqstp_flags(__entry->flags))
);

DECLARE_EVENT_CLASS(svc_rqst_status,
Expand All @@ -444,18 +451,20 @@ DECLARE_EVENT_CLASS(svc_rqst_status,
__field(__be32, xid)
__field(int, dropme)
__field(int, status)
__field(unsigned long, flags)
),

TP_fast_assign(
__entry->addr = (struct sockaddr *)&rqst->rq_addr;
__entry->xid = rqst->rq_xid;
__entry->dropme = (int)rqst->rq_dropme;
__entry->status = status;
__entry->flags = rqst->rq_flags;
),

TP_printk("addr=%pIScp rq_xid=0x%x dropme=%d status=%d",
TP_printk("addr=%pIScp rq_xid=0x%x dropme=%d status=%d flags=%s",
__entry->addr, be32_to_cpu(__entry->xid), __entry->dropme,
__entry->status)
__entry->status, show_rqstp_flags(__entry->flags))
);

DEFINE_EVENT(svc_rqst_status, svc_process,
Expand Down
5 changes: 4 additions & 1 deletion net/sunrpc/svc_xprt.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,10 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)

clear_bit(XPT_OLD, &xprt->xpt_flags);

rqstp->rq_secure = xprt->xpt_ops->xpo_secure_port(rqstp);
if (xprt->xpt_ops->xpo_secure_port(rqstp))
set_bit(RQ_SECURE, &rqstp->rq_flags);
else
clear_bit(RQ_SECURE, &rqstp->rq_flags);
rqstp->rq_chandle.defer = svc_defer;
rqstp->rq_xid = svc_getu32(&rqstp->rq_arg.head[0]);

Expand Down

0 comments on commit 4d152e2

Please sign in to comment.