Commit cf64b9bc authored by NeilBrown's avatar NeilBrown Committed by Chuck Lever

SUNRPC: return proper error from get_expiry()

The get_expiry() function currently returns a timestamp, and uses the
special return value of 0 to indicate an error.

Unfortunately this causes a problem when 0 is the correct return value.

On a system with no RTC it is possible that the boot time will be seen
to be "3".  When exportfs probes to see if a particular filesystem
supports NFS export it tries to cache information with an expiry time of
"3".  The intention is for this to be "long in the past".  Even with no
RTC it will not be far in the future (at most a second or two) so this
is harmless.
But if the boot time happens to have been calculated to be "3", then
get_expiry will fail incorrectly as it converts the number to "seconds
since bootime" - 0.

To avoid this problem we change get_expiry() to report the error quite
separately from the expiry time.  The error is now the return value.
The expiry time is reported through a by-reference parameter.
Reported-by: default avatarJerry Zhang <jerry@skydio.com>
Tested-by: default avatarJerry Zhang <jerry@skydio.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 2f90e18f
...@@ -123,11 +123,11 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) ...@@ -123,11 +123,11 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
/* OK, we seem to have a valid key */ /* OK, we seem to have a valid key */
key.h.flags = 0; key.h.flags = 0;
key.h.expiry_time = get_expiry(&mesg); err = get_expiry(&mesg, &key.h.expiry_time);
if (key.h.expiry_time == 0) if (err)
goto out; goto out;
key.ek_client = dom; key.ek_client = dom;
key.ek_fsidtype = fsidtype; key.ek_fsidtype = fsidtype;
memcpy(key.ek_fsid, buf, len); memcpy(key.ek_fsid, buf, len);
...@@ -610,9 +610,8 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) ...@@ -610,9 +610,8 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
exp.ex_devid_map = NULL; exp.ex_devid_map = NULL;
/* expiry */ /* expiry */
err = -EINVAL; err = get_expiry(&mesg, &exp.h.expiry_time);
exp.h.expiry_time = get_expiry(&mesg); if (err)
if (exp.h.expiry_time == 0)
goto out3; goto out3;
/* flags */ /* flags */
...@@ -624,7 +623,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) ...@@ -624,7 +623,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
if (err || an_int < 0) if (err || an_int < 0)
goto out3; goto out3;
exp.ex_flags= an_int; exp.ex_flags= an_int;
/* anon uid */ /* anon uid */
err = get_int(&mesg, &an_int); err = get_int(&mesg, &an_int);
if (err) if (err)
......
...@@ -240,8 +240,8 @@ idtoname_parse(struct cache_detail *cd, char *buf, int buflen) ...@@ -240,8 +240,8 @@ idtoname_parse(struct cache_detail *cd, char *buf, int buflen)
goto out; goto out;
/* expiry */ /* expiry */
ent.h.expiry_time = get_expiry(&buf); error = get_expiry(&buf, &ent.h.expiry_time);
if (ent.h.expiry_time == 0) if (error)
goto out; goto out;
error = -ENOMEM; error = -ENOMEM;
...@@ -408,8 +408,8 @@ nametoid_parse(struct cache_detail *cd, char *buf, int buflen) ...@@ -408,8 +408,8 @@ nametoid_parse(struct cache_detail *cd, char *buf, int buflen)
memcpy(ent.name, buf1, sizeof(ent.name)); memcpy(ent.name, buf1, sizeof(ent.name));
/* expiry */ /* expiry */
ent.h.expiry_time = get_expiry(&buf); error = get_expiry(&buf, &ent.h.expiry_time);
if (ent.h.expiry_time == 0) if (error)
goto out; goto out;
/* ID */ /* ID */
......
...@@ -300,17 +300,18 @@ static inline int get_time(char **bpp, time64_t *time) ...@@ -300,17 +300,18 @@ static inline int get_time(char **bpp, time64_t *time)
return 0; return 0;
} }
static inline time64_t get_expiry(char **bpp) static inline int get_expiry(char **bpp, time64_t *rvp)
{ {
time64_t rv; int error;
struct timespec64 boot; struct timespec64 boot;
if (get_time(bpp, &rv)) error = get_time(bpp, rvp);
return 0; if (error)
if (rv < 0) return error;
return 0;
getboottime64(&boot); getboottime64(&boot);
return rv - boot.tv_sec; (*rvp) -= boot.tv_sec;
return 0;
} }
#endif /* _LINUX_SUNRPC_CACHE_H_ */ #endif /* _LINUX_SUNRPC_CACHE_H_ */
...@@ -257,11 +257,11 @@ static int rsi_parse(struct cache_detail *cd, ...@@ -257,11 +257,11 @@ static int rsi_parse(struct cache_detail *cd,
rsii.h.flags = 0; rsii.h.flags = 0;
/* expiry */ /* expiry */
expiry = get_expiry(&mesg); status = get_expiry(&mesg, &expiry);
status = -EINVAL; if (status)
if (expiry == 0)
goto out; goto out;
status = -EINVAL;
/* major/minor */ /* major/minor */
len = qword_get(&mesg, buf, mlen); len = qword_get(&mesg, buf, mlen);
if (len <= 0) if (len <= 0)
...@@ -483,11 +483,11 @@ static int rsc_parse(struct cache_detail *cd, ...@@ -483,11 +483,11 @@ static int rsc_parse(struct cache_detail *cd,
rsci.h.flags = 0; rsci.h.flags = 0;
/* expiry */ /* expiry */
expiry = get_expiry(&mesg); status = get_expiry(&mesg, &expiry);
status = -EINVAL; if (status)
if (expiry == 0)
goto out; goto out;
status = -EINVAL;
rscp = rsc_lookup(cd, &rsci); rscp = rsc_lookup(cd, &rsci);
if (!rscp) if (!rscp)
goto out; goto out;
......
...@@ -225,9 +225,9 @@ static int ip_map_parse(struct cache_detail *cd, ...@@ -225,9 +225,9 @@ static int ip_map_parse(struct cache_detail *cd,
return -EINVAL; return -EINVAL;
} }
expiry = get_expiry(&mesg); err = get_expiry(&mesg, &expiry);
if (expiry ==0) if (err)
return -EINVAL; return err;
/* domainname, or empty for NEGATIVE */ /* domainname, or empty for NEGATIVE */
len = qword_get(&mesg, buf, mlen); len = qword_get(&mesg, buf, mlen);
...@@ -506,9 +506,9 @@ static int unix_gid_parse(struct cache_detail *cd, ...@@ -506,9 +506,9 @@ static int unix_gid_parse(struct cache_detail *cd,
uid = make_kuid(current_user_ns(), id); uid = make_kuid(current_user_ns(), id);
ug.uid = uid; ug.uid = uid;
expiry = get_expiry(&mesg); err = get_expiry(&mesg, &expiry);
if (expiry == 0) if (err)
return -EINVAL; return err;
rv = get_int(&mesg, &gids); rv = get_int(&mesg, &gids);
if (rv || gids < 0 || gids > 8192) if (rv || gids < 0 || gids > 8192)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment