From patchwork Wed Oct 25 20:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Shtylyov X-Patchwork-Id: 13436778 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33A8EC07545 for ; Wed, 25 Oct 2023 20:36:10 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qvkbm-0007NF-BB; Wed, 25 Oct 2023 20:36:07 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qvkbe-0007Mr-UV for linux-f2fs-devel@lists.sourceforge.net; Wed, 25 Oct 2023 20:35:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Date:Subject:CC:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=t3BHxIawpfGclTTbmX0pNTfMllfpaz/5irmFLDfBUno=; b=j1RDAMyuBXW9Mclq6GqfgInz+P CuOrDtoKv3U06POAnw2uMOL9Oo814DCYs/EL4NsvYKCgdSneGhYPHC8HS9C/6Y//AzW+Tt9B90VGQ a+zc5QVjH1nAeRzi6tOG5AaT9EVJPOwD1gMCf+o/9GRb5Bbdr3eKH8W4TbfadXWId6bU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:CC:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=t3BHxIawpfGclTTbmX0pNTfMllfpaz/5irmFLDfBUno=; b=E 7jdsWjr8MTGkdbEa6yxdkGLZ9M8nIDpJd6BAzWAhQlpH4jxy8nbpe8R4nT2hgB/z/dQavqa+z4gUS 8zRUmWlzKdI+xlV7YjLmOVp3m7pCnkTAr06oJTHzf1M2S8Uk3gcZ/xrviq56hH3ZGVoSMkHcIss56 pSU6rOQwf3hBXFiY=; Received: from mx01.omp.ru ([90.154.21.10]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-SHA384:256) (Exim 4.95) id 1qvkba-0008Om-LM for linux-f2fs-devel@lists.sourceforge.net; Wed, 25 Oct 2023 20:35:58 +0000 Received: from localhost.localdomain (31.173.86.85) by msexch01.omp.ru (10.188.4.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.986.14; Wed, 25 Oct 2023 23:20:25 +0300 From: Sergey Shtylyov To: Jaegeuk Kim , Chao Yu , Date: Wed, 25 Oct 2023 23:20:19 +0300 Message-ID: <20231025202019.5228-1-s.shtylyov@omp.ru> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Originating-IP: [31.173.86.85] X-ClientProxiedBy: msexch01.omp.ru (10.188.4.12) To msexch01.omp.ru (10.188.4.12) X-KSE-ServerInfo: msexch01.omp.ru, 9 X-KSE-AntiSpam-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 6.0.0, Database issued on: 10/25/2023 20:04:26 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 59 X-KSE-AntiSpam-Info: Lua profiles 180898 [Oct 25 2023] X-KSE-AntiSpam-Info: Version: 6.0.0.2 X-KSE-AntiSpam-Info: Envelope from: s.shtylyov@omp.ru X-KSE-AntiSpam-Info: LuaCore: 543 543 1e3516af5cdd92079dfeb0e292c8747a62cb1ee4 X-KSE-AntiSpam-Info: {rep_avail} X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: {relay has no DNS name} X-KSE-AntiSpam-Info: {SMTP from is not routable} X-KSE-AntiSpam-Info: {Found in DNSBL: 31.173.86.85 in (user) b.barracudacentral.org} X-KSE-AntiSpam-Info: {Found in DNSBL: 31.173.86.85 in (user) dbl.spamhaus.org} X-KSE-AntiSpam-Info: omp.ru:7.1.1; 127.0.0.199:7.1.2; d41d8cd98f00b204e9800998ecf8427e.com:7.1.1 X-KSE-AntiSpam-Info: ApMailHostAddress: 31.173.86.85 X-KSE-AntiSpam-Info: {DNS response errors} X-KSE-AntiSpam-Info: Rate: 59 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-AntiSpam-Info: Auth:dmarc=temperror header.from=omp.ru;spf=temperror smtp.mailfrom=omp.ru;dkim=none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Heuristic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 10/25/2023 20:09:00 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 10/25/2023 7:21:00 PM X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit X-Headers-End: 1qvkba-0008Om-LM Subject: [f2fs-dev] [PATCH] f2fs: data: fix possible overflow in check_swap_activate() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net In check_swap_activate(), if the *while* loop exits early (0- or 1-page long swap file), an overflow happens while calculating the value of the span parameter as the lowest_pblock variable ends up being greater than the highest_pblock variable. Let's set *span to 0 in this case... Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. Signed-off-by: Sergey Shtylyov --- This patch is against the 'master' branch of Jaegeuk Kim's F2FS repo... fs/f2fs/data.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 916e317ac925..342cb0d5056d 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -4047,7 +4047,10 @@ static int check_swap_activate(struct swap_info_struct *sis, cur_lblock += nr_pblocks; } ret = nr_extents; - *span = 1 + highest_pblock - lowest_pblock; + if (lowest_pblock <= highest_pblock) + *span = 1 + highest_pblock - lowest_pblock; + else + *span = 0; if (cur_lblock == 0) cur_lblock = 1; /* force Empty message */ sis->max = cur_lblock;