From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753924AbeDKN0U (ORCPT ); Wed, 11 Apr 2018 09:26:20 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:45536 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753170AbeDKN0S (ORCPT ); Wed, 11 Apr 2018 09:26:18 -0400 From: Colin King To: David Howells , linux-afs@lists.infradead.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] afs: fix integer overflow when shifting 1 more than 32 places Date: Wed, 11 Apr 2018 14:26:13 +0100 Message-Id: <20180411132613.18974-1-colin.king@canonical.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Shifting 1 (a 32 bit signed int) more than 32 places will overflow the int, so explicitly use 1ULL to avoid this overflow. Detected by CoverityScan, CID#1467808 ("Uninitentional integer overflow") Fixes: 63a4681ff39c ("afs: Locally edit directory data for mkdir/create/unlink/...") Signed-off-by: Colin Ian King --- fs/afs/dir_edit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/afs/dir_edit.c b/fs/afs/dir_edit.c index 8b400f5aead5..42a63f9467c5 100644 --- a/fs/afs/dir_edit.c +++ b/fs/afs/dir_edit.c @@ -40,7 +40,7 @@ static int afs_find_contig_bits(union afs_xdr_dir_block *block, unsigned int nr_ bitmap |= (u64)block->hdr.bitmap[7] << 7 * 8; bitmap >>= 1; /* The first entry is metadata */ bit = 1; - mask = (1 << nr_slots) - 1; + mask = (1ULL << nr_slots) - 1; do { if (sizeof(unsigned long) == 8) @@ -74,7 +74,7 @@ static void afs_set_contig_bits(union afs_xdr_dir_block *block, { u64 mask, before, after; - mask = (1 << nr_slots) - 1; + mask = (1ULL << nr_slots) - 1; mask <<= bit; before = *(u64 *)block->hdr.bitmap; @@ -99,7 +99,7 @@ static void afs_clear_contig_bits(union afs_xdr_dir_block *block, { u64 mask, before, after; - mask = (1 << nr_slots) - 1; + mask = (1ULL << nr_slots) - 1; mask <<= bit; before = *(u64 *)block->hdr.bitmap; -- 2.17.0 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Colin King Date: Wed, 11 Apr 2018 13:26:13 +0000 Subject: [PATCH][next] afs: fix integer overflow when shifting 1 more than 32 places Message-Id: <20180411132613.18974-1-colin.king@canonical.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: David Howells , linux-afs@lists.infradead.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org From: Colin Ian King Shifting 1 (a 32 bit signed int) more than 32 places will overflow the int, so explicitly use 1ULL to avoid this overflow. Detected by CoverityScan, CID#1467808 ("Uninitentional integer overflow") Fixes: 63a4681ff39c ("afs: Locally edit directory data for mkdir/create/unlink/...") Signed-off-by: Colin Ian King --- fs/afs/dir_edit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/afs/dir_edit.c b/fs/afs/dir_edit.c index 8b400f5aead5..42a63f9467c5 100644 --- a/fs/afs/dir_edit.c +++ b/fs/afs/dir_edit.c @@ -40,7 +40,7 @@ static int afs_find_contig_bits(union afs_xdr_dir_block *block, unsigned int nr_ bitmap |= (u64)block->hdr.bitmap[7] << 7 * 8; bitmap >>= 1; /* The first entry is metadata */ bit = 1; - mask = (1 << nr_slots) - 1; + mask = (1ULL << nr_slots) - 1; do { if (sizeof(unsigned long) = 8) @@ -74,7 +74,7 @@ static void afs_set_contig_bits(union afs_xdr_dir_block *block, { u64 mask, before, after; - mask = (1 << nr_slots) - 1; + mask = (1ULL << nr_slots) - 1; mask <<= bit; before = *(u64 *)block->hdr.bitmap; @@ -99,7 +99,7 @@ static void afs_clear_contig_bits(union afs_xdr_dir_block *block, { u64 mask, before, after; - mask = (1 << nr_slots) - 1; + mask = (1ULL << nr_slots) - 1; mask <<= bit; before = *(u64 *)block->hdr.bitmap; -- 2.17.0