Skip to content

Commit 3b68e6e

Browse files
NeilBrownJ. Bruce Fields
authored andcommitted
SUNRPC: cache: ignore timestamp written to 'flush' file.
The interface for flushing the sunrpc auth cache was poorly designed and has caused problems a number of times. The design is that you write a timestamp, and all entries created before that time are discarded. The most obvious problem is that this is not what people actually want. They want to just flush the whole cache. The 1-second granularity can be a problem, as can the use of wall-clock time. A current problem is that code will write the current time to this file - expecting it to clear everything - and if the seconds number ticks over before this timestamp is checked, the test "then >= now" fails, and a full flush isn't forced. So lets just drop the subtleties and always flush the whole cache. The worst this could do is impose an extra cost refilling it, but that would require someone to be using non-standard tools. We still report an error if the string written is not a number, but we cause any valid number to flush the whole cache. Reported-by: "Wang, Alan 1. (NSB - CN/Hangzhou)" <alan.1.wang@nokia-sbell.com> Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 90a9b14 commit 3b68e6e

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

‎net/sunrpc/cache.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,8 @@ static ssize_t write_flush(struct file *file, const char __user *buf,
14501450
struct cache_detail *cd)
14511451
{
14521452
char tbuf[20];
1453-
char *bp, *ep;
1454-
time_t then, now;
1453+
char *ep;
1454+
time_t now;
14551455

14561456
if (*ppos || count > sizeof(tbuf)-1)
14571457
return -EINVAL;
@@ -1461,24 +1461,24 @@ static ssize_t write_flush(struct file *file, const char __user *buf,
14611461
simple_strtoul(tbuf, &ep, 0);
14621462
if (*ep && *ep != '\n')
14631463
return -EINVAL;
1464+
/* Note that while we check that 'buf' holds a valid number,
1465+
* we always ignore the value and just flush everything.
1466+
* Making use of the number leads to races.
1467+
*/
14641468

1465-
bp = tbuf;
1466-
then = get_expiry(&bp);
14671469
now = seconds_since_boot();
1468-
cd->nextcheck = now;
1469-
/* Can only set flush_time to 1 second beyond "now", or
1470-
* possibly 1 second beyond flushtime. This is because
1471-
* flush_time never goes backwards so it mustn't get too far
1472-
* ahead of time.
1470+
/* Always flush everything, so behave like cache_purge()
1471+
* Do this by advancing flush_time to the current time,
1472+
* or by one second if it has already reached the current time.
1473+
* Newly added cache entries will always have ->last_refresh greater
1474+
* that ->flush_time, so they don't get flushed prematurely.
14731475
*/
1474-
if (then >= now) {
1475-
/* Want to flush everything, so behave like cache_purge() */
1476-
if (cd->flush_time >= now)
1477-
now = cd->flush_time + 1;
1478-
then = now;
1479-
}
14801476

1481-
cd->flush_time = then;
1477+
if (cd->flush_time >= now)
1478+
now = cd->flush_time + 1;
1479+
1480+
cd->flush_time = now;
1481+
cd->nextcheck = now;
14821482
cache_flush();
14831483

14841484
*ppos += count;

0 commit comments

Comments
 (0)