[rh7] fs/fuse kio: add a sanity check on statistic inc

Submitted by Konstantin Khorenko on Aug. 21, 2019, 10:38 a.m.

Details

Message ID 20190821103806.10783-1-khorenko@virtuozzo.com
State New
Series "fs/fuse kio: add a sanity check on statistic inc"
Headers show

Commit Message

Konstantin Khorenko Aug. 21, 2019, 10:38 a.m.
As there are still possible cases when we expect code to work without
statistic inited, it's theoretically possible some day we again get an
update request for non-inited stat struct, and corrupt stack-protector
cookie and who knows what alse.

So add a sanity check to prevent it.

https://jira.sw.ru/browse/PSBM-96128

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 fs/fuse/kio/pcs/fuse_stat.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch hide | download patch | download mbox

diff --git a/fs/fuse/kio/pcs/fuse_stat.c b/fs/fuse/kio/pcs/fuse_stat.c
index b57be607f5e1..c91bfe8b3bf7 100644
--- a/fs/fuse/kio/pcs/fuse_stat.c
+++ b/fs/fuse/kio/pcs/fuse_stat.c
@@ -31,6 +31,12 @@  static u64 lat_oreder_list[] = {
 
 static inline void fuse_val_stat_update(struct fuse_val_stat *s, u64 val)
 {
+	/*
+	 * Sanity check. In case s == NULL, stack protector cookie is
+	 * corrupted, quite difficult to debug.
+	 */
+	BUG_ON(!s);
+
 	preempt_disable();
 	if (!__this_cpu_read(s->events)) {
 		__this_cpu_write(s->val_min, val);
@@ -48,6 +54,11 @@  void fuse_latency_update(struct fuse_lat_stat *s, u64 val)
 {
 	int i;
 
+	/*
+	 * Sanity check. In case s == NULL, stack protector cookie is
+	 * corrupted, quite difficult to debug.
+	 */
+	BUG_ON(!s);
 	this_cpu_inc(s->count);
 	for (i = LAT_ORDER1; i <= LAT_ORDER5; i++) {
 		if (likely(val <= lat_oreder_list[i])) {

Comments

Kirill Tkhai Aug. 21, 2019, 11 a.m.
On 21.08.2019 13:38, Konstantin Khorenko wrote:
> As there are still possible cases when we expect code to work without
> statistic inited, it's theoretically possible some day we again get an
> update request for non-inited stat struct, and corrupt stack-protector
> cookie and who knows what alse.
> 
> So add a sanity check to prevent it.
> 
> https://jira.sw.ru/browse/PSBM-96128
> 
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>

> ---
>  fs/fuse/kio/pcs/fuse_stat.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/fs/fuse/kio/pcs/fuse_stat.c b/fs/fuse/kio/pcs/fuse_stat.c
> index b57be607f5e1..c91bfe8b3bf7 100644
> --- a/fs/fuse/kio/pcs/fuse_stat.c
> +++ b/fs/fuse/kio/pcs/fuse_stat.c
> @@ -31,6 +31,12 @@ static u64 lat_oreder_list[] = {
>  
>  static inline void fuse_val_stat_update(struct fuse_val_stat *s, u64 val)
>  {
> +	/*
> +	 * Sanity check. In case s == NULL, stack protector cookie is
> +	 * corrupted, quite difficult to debug.
> +	 */
> +	BUG_ON(!s);
> +
>  	preempt_disable();
>  	if (!__this_cpu_read(s->events)) {
>  		__this_cpu_write(s->val_min, val);
> @@ -48,6 +54,11 @@ void fuse_latency_update(struct fuse_lat_stat *s, u64 val)
>  {
>  	int i;
>  
> +	/*
> +	 * Sanity check. In case s == NULL, stack protector cookie is
> +	 * corrupted, quite difficult to debug.
> +	 */
> +	BUG_ON(!s);
>  	this_cpu_inc(s->count);
>  	for (i = LAT_ORDER1; i <= LAT_ORDER5; i++) {
>  		if (likely(val <= lat_oreder_list[i])) {
>