From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bob Copeland Subject: [PATCH 3/4] omfs: fix sign confusion for bitmap loop counter Date: Mon, 18 May 2015 07:34:37 -0400 Message-ID: <1431948878-3756-4-git-send-email-me@bobcopeland.com> References: <1431948878-3756-1-git-send-email-me@bobcopeland.com> Cc: linux-fsdevel@vger.kernel.org, Bob Copeland , stable@vger.kernel.org To: akpm@linux-foundation.org Return-path: Received: from mail-ig0-f177.google.com ([209.85.213.177]:38782 "EHLO mail-ig0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753791AbbERLhc (ORCPT ); Mon, 18 May 2015 07:37:32 -0400 Received: by igcau1 with SMTP id au1so44724685igc.1 for ; Mon, 18 May 2015 04:37:30 -0700 (PDT) In-Reply-To: <1431948878-3756-1-git-send-email-me@bobcopeland.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: The count variable is used to iterate down to (below) zero from the size of the bitmap and handle the one-filling the remainder of the last partial bitmap block. The loop conditional expects count to be signed in order to detect when the final block is processed, after which count goes negative. Unfortunately, a recent change made this unsigned along with some other related fields. The result of is this is that during mount, omfs_get_imap will overrun the bitmap array and corrupt memory unless number of blocks happens to be a multiple of 8 * blocksize. Fix by changing count back to signed: it is guaranteed to fit in an s32 without overflow due to an enforced limit on the number of blocks in the filesystem. Cc: stable@vger.kernel.org Signed-off-by: Bob Copeland --- fs/omfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/omfs/inode.c b/fs/omfs/inode.c index 6ce542c11f98..3d935c81789a 100644 --- a/fs/omfs/inode.c +++ b/fs/omfs/inode.c @@ -306,7 +306,8 @@ static const struct super_operations omfs_sops = { */ static int omfs_get_imap(struct super_block *sb) { - unsigned int bitmap_size, count, array_size; + unsigned int bitmap_size, array_size; + int count; struct omfs_sb_info *sbi = OMFS_SB(sb); struct buffer_head *bh; unsigned long **ptr; -- 2.1.4