From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f195.google.com ([209.85.192.195]:37711 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933033AbeGHVFf (ORCPT ); Sun, 8 Jul 2018 17:05:35 -0400 From: Eric Biggers To: David Howells , Alexander Viro , linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 03/18] fs_context: fix detecting full log buffer Date: Sun, 8 Jul 2018 14:01:39 -0700 Message-Id: <20180708210154.10423-4-ebiggers3@gmail.com> In-Reply-To: <20180708210154.10423-1-ebiggers3@gmail.com> References: <20180708210154.10423-1-ebiggers3@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Eric Biggers When 'head' and 'tail' wrap around, 'log->head - log->tail' will be something like '4 - 252 = -248', and comparing that directly to the array size is wrong. Fix by casting to 'u8'. Fixes: 09aeca629fb3 ("vfs: Implement logging through fs_context") Signed-off-by: Eric Biggers --- fs/fs_context.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/fs_context.c b/fs/fs_context.c index 97e8c1dc4e3b1..a0e22f4c6b64a 100644 --- a/fs/fs_context.c +++ b/fs/fs_context.c @@ -418,7 +418,9 @@ void logfc(struct fs_context *fc, const char *fmt, ...) freeable = 0; store_string: index = log->head & (logsize - 1); - if ((int)log->head - (int)log->tail == 8) { + BUILD_BUG_ON(sizeof(log->head) != sizeof(u8) || + sizeof(log->tail) != sizeof(u8)); + if ((u8)(log->head - log->tail) == logsize) { /* The buffer is full, discard the oldest message */ if (log->need_free & (1 << index)) kfree(log->buffer[index]); -- 2.18.0