Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp641620pxb; Tue, 9 Feb 2021 08:56:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJwI0INHiIJt7mQUMtlxhjr5VQX6ENahKjeCxYVZ4KBVe3akV41TXq9rzjDc/IIPAkJ+/c+M X-Received: by 2002:a05:6402:c91:: with SMTP id cm17mr24543652edb.219.1612889788232; Tue, 09 Feb 2021 08:56:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1612889788; cv=pass; d=google.com; s=arc-20160816; b=bqYY8s15JCUQlDt1LyFaIylYpkLtQih/YwDyXYCWBlN56qihh17Du6CHnqz/bhjjHt fxFqRnL7+REl5UMYiIAIG/iG9QSlFHyMdeIAxPA77ZQ2dKBF6JnR3uov7v7+naTbcMpT 2/6ItPYTwBT7+TZ/yp94CxTfMz3wrsGVDYnVeiuqi7cEpHfC05fZFnwGmECLc/JckyN2 BBDFGMeCOtURMTw87a8XB/O2BL3MuHexJo2weabBTvsrUOZEt2DlwuRGLY/XjzowoyfE 14MJeQypNbUxyuplsbofzUGh7owHYeGpc2U4dEvuSUilb8rtO7kCRU6xDVXBZGY+vkgx ytUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature:dkim-signature; bh=rQ2mS8ucJ28TvXRHHjroXvheckYN/0SlaynncLjbqMw=; b=Gj2E1+uU3i68aadCmKJZfQfzZbp2P/aiBbX9bbkGOqX3NZqzD7sXp6xhi8KMCnhsLn NaV1AJZNsglBd4MwnYKHf9t9cD1rppaVTXZQ7CdH+cYQpglWVVJidomMQ9Sz1cDZyDd9 I9J/l4IlMdWww2ihhCiRCTMKcfN/c5YRZIYZuhmzumFx/R2ZRC/Ak07ynv7XzSxHgDvs QjHX2eD63AVb0bJAZO2Z6ELVQzitCC4TwMp46UIoXQRe8grc+MF2m2qyyfZvHP4y2ThT L1t85ebyJfmihfmnbV+0sbYHO9A6wolOAsBT3iA/EpgrZV6xWw/dFmFt+mfkeE24yGII Hk6w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=VZ+Nznok; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=R77o1utS; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si14198801edt.398.2021.02.09.08.56.04; Tue, 09 Feb 2021 08:56:28 -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; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=VZ+Nznok; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=R77o1utS; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232932AbhBIQyB (ORCPT + 99 others); Tue, 9 Feb 2021 11:54:01 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:33798 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232959AbhBIQxv (ORCPT ); Tue, 9 Feb 2021 11:53:51 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 119GY5vu051014; Tue, 9 Feb 2021 16:52:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=rQ2mS8ucJ28TvXRHHjroXvheckYN/0SlaynncLjbqMw=; b=VZ+Nznokv+QJ+vz6ZhnjTCS7tYv3bjYbM/Qs9w4U5i4ZXkWNMRQfVpJzxxRKuy9sczSk 2z8DTrMZ9WFKMdJvEz4t8jXurTgzgn4lpfNmUG2nvpKaWY0VHHN3LjVrtTgXQS6YC9vA A1QCvjcUBZb38LxdegDlZgqMRZjRN6kPnRQeoIIKKbcq4LV37b96QNdTWg4DPeFDJqW9 CNHmJlD7NZOLt+Xkamm3p3qgMZ/AqLrKBKaeHgh0j2yuFuShDqeq6JPVZx1laCm0ILVF KojSTU2WwzR4XJTlOTy6AeuMT+ivG9At0LuBLY6/GGBTRh4UKy3P+qqCQVzl/PRNp2jF iw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 36hgmagaqj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Feb 2021 16:52:36 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 119GZPb9158401; Tue, 9 Feb 2021 16:52:36 GMT Received: from nam02-bl2-obe.outbound.protection.outlook.com (mail-bl2nam02lp2052.outbound.protection.outlook.com [104.47.38.52]) by aserp3020.oracle.com with ESMTP id 36j511ferj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Feb 2021 16:52:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JYP1cZca6k9xa/Km5OiYoSf6jobD55lZYam9kcVaswOkfWQXvRisx3GdpHh1UuPymmKJGUgnfI+cTZbcp+nODhp8oj7Ao3zvv3xbYZLlYEc/+7j523/5a6kuPATDmOtKrIXkkIVtM5OwS1C4ovmsMMTA+pB08XkndL2TcKPS+bcVinyaKF6cv8/xHtKKhZKGpNNYfjQDQOhhvQu04sbb1pYRr88TNSEOsmRIkYrsWrnt88sqSeFQ7y7Pqgswe6ni17zcPvoymulA+EvFvzmXKJIsx96Q/MTrhf6bdXvuE2wKEiq6capWujiTE25eOzKngl+x7k9ongZ1eCHDnXZrXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rQ2mS8ucJ28TvXRHHjroXvheckYN/0SlaynncLjbqMw=; b=G31lNf8xUap9VPkpaS3L5s2ww1TbxZ1Cj7/+Zxk57nE7dK1+EXU8v+9Q/8dbqXryQLbZCA7AUPJgFb8i/hDitagVkY6rgKZA0tWyP2eGIrop0LuxQ7d/6WvqP0hXN6yasx/BnsUqAQLEGm/M5v1aiwdaMbyzOne3dY026JLtiJOMlNW10g0atotnMEJKvrRsB4JWX69TaU81hYoxQk05svpmumJRW8sp4u1CGjsdft4acOp02eIQIHHRangbrQRtwTARBDFlRhdkSUH6bdvSvOz9mRT3wIOV1V2AFlOpOj6xLyMVHL8M6d7qtjQhuw5fyVlMnu0jade9rZNAh8e3Xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rQ2mS8ucJ28TvXRHHjroXvheckYN/0SlaynncLjbqMw=; b=R77o1utSlzECviqxapS01ok9Z/cU3CB1IBtucQhPJ36hLgk4EbO97rCNCn1bA8Bj1TS7ceHq1PZic2t8KXDwkhss6WknfErGWTLrFkqIJs89dCWH9KNztXCHUP7pmPIc8jY6TEQa9fr7tUufbA7TAVdToOg4LsNB8mmo7vknSTU= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=oracle.com; Received: from CH2PR10MB4118.namprd10.prod.outlook.com (2603:10b6:610:a4::8) by CH2PR10MB4232.namprd10.prod.outlook.com (2603:10b6:610:a4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.25; Tue, 9 Feb 2021 16:52:34 +0000 Received: from CH2PR10MB4118.namprd10.prod.outlook.com ([fe80::b4f8:316f:3a25:faac]) by CH2PR10MB4118.namprd10.prod.outlook.com ([fe80::b4f8:316f:3a25:faac%7]) with mapi id 15.20.3846.025; Tue, 9 Feb 2021 16:52:34 +0000 Subject: Re: [PATCH] fs/jfs: fix potential integer overflow on shift of a int To: Colin King , Tino Reichardt , jfs-discussion@lists.sourceforge.net Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210205171137.208121-1-colin.king@canonical.com> From: Dave Kleikamp Message-ID: <044b0372-8612-6fb9-23c5-9c4e6ab79114@oracle.com> Date: Tue, 9 Feb 2021 10:52:32 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 In-Reply-To: <20210205171137.208121-1-colin.king@canonical.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [68.201.65.98] X-ClientProxiedBy: SA0PR11CA0162.namprd11.prod.outlook.com (2603:10b6:806:1bb::17) To CH2PR10MB4118.namprd10.prod.outlook.com (2603:10b6:610:a4::8) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.0.190] (68.201.65.98) by SA0PR11CA0162.namprd11.prod.outlook.com (2603:10b6:806:1bb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25 via Frontend Transport; Tue, 9 Feb 2021 16:52:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4ce5dd46-f579-4492-b5e5-08d8cd1b1927 X-MS-TrafficTypeDiagnostic: CH2PR10MB4232: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X6qTC5CzBTby6Vz0EEiAJ1OysXtdDC0QZ5zHg/fbHV65eh/Wnq4bZwR/JRv1TjiKsPxUnL+2XlCzUEihAXohBqKWCOF5oanTnZhvGzklmZY6ClyRdDMf5fsoyoj+1llAyUk16M+kdrtD4aqJh1C+UU/TSMhjmrwlsGgYhM0YKx+XOOOLvyPHk1s7UzJIsoCI0OIAq4IRTXGFdjcX4fmtZQd2KCjQwXhDDlbWdcSWgfJ8ObHbinY+UZgq9LmILSGnE7xVDmsy52/2G2KSz8Fes8iHXpqiz29s/omboE3KDCUoz1QFx+Xb5EEHjPgDvrMHtEZBz+d532VRL9mZG+1nEs7Wy+XhH+bmzb56T1MVSJmcwcEfXLcJKftgYSqM1MoE6eHo82szUjPGpZc/hv71cG4g8pV4F63VHWFn4tn3WkHqnYqmWv1J6tHRZAgyMCCjeEcjPfbIsQHXhxXJjkgCh1tf2OgLQkJzQnpXN67gmGQN22IJFCTa1yONstOcY+aqJ4c4bR/47BpuybpHWYZDgHlVgsZgMMtHLAOLx4G0ii8zMwIqsRLvr7YaCRlHLpXqgEEYJHel9qS9QT/gER+TdcrGbiqsel6aTsnBBh9OIo4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR10MB4118.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(39860400002)(346002)(136003)(376002)(396003)(366004)(66556008)(66476007)(26005)(31696002)(478600001)(83380400001)(2906002)(2616005)(44832011)(186003)(956004)(66946007)(31686004)(16576012)(316002)(16526019)(53546011)(8676002)(4326008)(86362001)(110136005)(5660300002)(36756003)(6486002)(8936002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?ZElwN29RUTRUYVVyUmVKNW9nRDBtRHp6TUpRQ3hMUXltR052ckUrZ2p6dkpE?= =?utf-8?B?OWRDckdseG1TMU9qcEkwVXh2OWNOczJYM0N4eW9ObWEya1lxYnFOWWdBdEo2?= =?utf-8?B?YWpqZk5LdllIR2xuTkxPN3lUcnI4dVZ4bVNaQlpZN3ZBKzhGa2o4VXBXZ3lZ?= =?utf-8?B?RHRlOWVULytLb2lGckJaZVl5cWVKTGVRWWg4WWxLMks3NGF6cWl2aXhLdW5l?= =?utf-8?B?ZFdSMWZDbExQbjhFblpaSHpKN2hHRGVuSnVNOGE3WE1TSHd6cy9wbThobUww?= =?utf-8?B?Z283bURXM1NJOUdaUko0Z1ExY1VkWUxNd21NOUpROHdocTRLNlBuR3NndW1P?= =?utf-8?B?M2pOMXlpajdWajU2cEVpeWlNTjhBbnZvUGV3TUpRSW8yOWpQZ09PMGhpR0VQ?= =?utf-8?B?dzdienBtVlV1UXY3eDR5R2JscXpUTW04ODdLdHR4VGlnaUNmOTR4c2VVQjA3?= =?utf-8?B?aEZZOTV5MGNYM3NFNWdTOHUrWGpZYzd6OVFWUytnZmFGcE85bTArMENNbWl4?= =?utf-8?B?bUFKSHd4RUQxUHRPTldZRnVySy9MUVE2eDVlVDlXYjFmZk9RUndPa0RwRjJv?= =?utf-8?B?dHlsVHk5elhzczVoRlg2Qj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jNONkM2UURvQ0FWRDBIZXlRTkN6L1MxcHVlWnVuTUR6VVA3WUw1cUZ5?= =?utf-8?B?ZUVxU1Jtc1RnRW44OTVsMXlpUlJFQXV4WTlzN1RIWmVWQ2lweDlKQjMwS04x?= =?utf-8?B?UGgvbStucGg3Z3c1dWV6Q2x6NkkycVMvNFRZdWZNRFlKcERtVERFYjBiaVZk?= =?utf-8?B?VHpZRE0wVmJqVHlocitxQmNnL1RVYkdOVUQwNm1SVENrRzZzR2hIaW1kb0N3?= =?utf-8?Q?yPYP3vf9WO/yrCqofyPgqLOJTssv7a+9AC7yzOM?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ce5dd46-f579-4492-b5e5-08d8cd1b1927 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4118.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2021 16:52:34.5228 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LuESIHbJCDiJFZD22wmt+YmXxM8cqHnDVkd4U7rP74sHvT2nP85RjYJJo9XzuiDuV1R+Q8Qnk1q5CGofgp0tb97X39+spzlsZrJbgVIL1Y8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4232 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9890 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 adultscore=0 mlxlogscore=999 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102090082 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9890 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 spamscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 suspectscore=0 mlxscore=0 clxscore=1011 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102090082 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/5/21 11:11 AM, Colin King wrote: > 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); I'm not sure I like the use of this macro here. It seems to imply a bit flag of some sort. I think it would be clearer to use nblocks = 1ULL << l2nb; Maybe 1LL rather than 1ULL since nblocks is s64. > } else { > /* Trim any already allocated blocks */ > jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n"); >