Received: by 2002:a05:6520:2f93:b029:af:d4db:7a05 with SMTP id 19csp2294201lkf; Fri, 5 Feb 2021 09:33:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpqPqEwWLN6U5A4ypUmd+9tGE8tMKeYiMQQtF11qTTT9316DMrJ2IicOGMpXKVDEc7s2rp X-Received: by 2002:a50:d4d9:: with SMTP id e25mr4605285edj.183.1612546383398; Fri, 05 Feb 2021 09:33:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612546383; cv=none; d=google.com; s=arc-20160816; b=b2QFM4VkxsVNx+fH6i/I80CC08tV2ZxBG2smm4d3h/vIc34OoqduxLF5pdU/cgDZPe nwcB+JbqGI+6DMJGONDdvLsPw0JqFT8g/qBG9y6/NJOVeA2uKSjUcB1VX+V0HdlFDUwn s5qeYO2PpjRRLAhR131Qlr7yMdtCPkd1sfOJHXWhdZTzBckH7bs0ETvbbbAEvpm4s2S/ xYO7v9Gc2SVMIrNPkwFpxlox+fUajS6Ki70W0nERVAMfnnefId0vhcEuXeoQ3K8xT44w MEupHIlXDjAW2y5dGn7mmP8uHAanMcQsFOocoZ+haQu9bJakZfoKBHtQV03CjNjvW10L zYtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=pU+oBJ+LHNVj2KnAVgcVNuujM6VR0RmjEdFXyxePA9U=; b=UwrBoJy4ABWRUWCUm603gJ/Nd3cMXMyxKPoMXN0nX+PTj0f2WcnhFvBx7FQlKqP3q0 fE/rb5HCEcK28PLbJZVGAHc2rCIG+XdZ6zHtV5VMsZc2LRFm+HjdXjzyD/A7vHUjOREe u3sKC04rR2MecwxNG7r6uH5uNR3uCVK3OEyuX2htLhrHTJxqHjQC0psNEK2zLamAktix 6Xvcq38V9eX/zM0du0hnZLw5v6sQjEGlP63eBi2mt8Iakgy168PBJWYK4xlo3A0xnIWs IE28as+jWQshXxJmlVfyEdOB6hTlu1eiscNbz5tYP4E0Nf2vdDPFSliJHcRhBlWlUVpw d29g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si6424654ejb.242.2021.02.05.09.32.38; Fri, 05 Feb 2021 09:33:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231493AbhBEPsP (ORCPT + 99 others); Fri, 5 Feb 2021 10:48:15 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:38568 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233290AbhBEPaA (ORCPT ); Fri, 5 Feb 2021 10:30:00 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1l84du-0001ZI-5s; Fri, 05 Feb 2021 17:11:38 +0000 From: Colin King To: Dave Kleikamp , Tino Reichardt , jfs-discussion@lists.sourceforge.net Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fs/jfs: fix potential integer overflow on shift of a int Date: Fri, 5 Feb 2021 17:11:37 +0000 Message-Id: <20210205171137.208121-1-colin.king@canonical.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then assigned to a signed 64 bit integer. In the case where l2nb is 32 or more this can lead to an overflow. Avoid this by shifting using the BIT_ULL macro instead. Addresses-Coverity: ("Uninitentional integer overflow") Fixes: b40c2e665cd5 ("fs/jfs: TRIM support for JFS Filesystem") Signed-off-by: Colin Ian King --- fs/jfs/jfs_dmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index 94b7c1cb5ceb..47dbca7e52e0 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -1656,7 +1656,7 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen) } else if (rc == -ENOSPC) { /* search for next smaller log2 block */ l2nb = BLKSTOL2(nblocks) - 1; - nblocks = 1 << l2nb; + nblocks = BIT_ULL(l2nb); } else { /* Trim any already allocated blocks */ jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n"); -- 2.29.2