Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2821640rda; Wed, 25 Oct 2023 13:21:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSHNT37TrEB+kX7UgzHNpq8oxdeUcX1OAHgwJNecg063m/h4bkEZ9nGMhshQcD85V2Kdjt X-Received: by 2002:a05:690c:ecf:b0:58e:fa3c:9401 with SMTP id cs15-20020a05690c0ecf00b0058efa3c9401mr19971330ywb.12.1698265260764; Wed, 25 Oct 2023 13:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698265260; cv=none; d=google.com; s=arc-20160816; b=t/x9JK6+yarDyMjjf3ZS3aEyJdceCYXqCWoU44R3+AcNIydebLi8tFqeBDahoNCw2g 5Bc4oBwXxe5kiuRcDPyoUEE4oXyG4NkH4Gyt/LbsRXDRjW3HhmF+uSNrLlwCyCRXvQIS 9r3uWDlMJDeJg1ChnRI/0SpS4OEdwIA8cnGtvAW2A0QjdC/AvduRX24OcZc8LDdoR8Rs 4vX97fAHf1h5VKjD//Q+D3fu8R8LUTtRhSrjergqJr8LTahBxbBjVH11ZgbRCRo1iZ8R RHRZ92QxxOqtL9dKmjiiUmeugu1rJr0rditWIALhDzLvf+04IWycEKrjaANoGqXddVyG beoA== 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=t3BHxIawpfGclTTbmX0pNTfMllfpaz/5irmFLDfBUno=; fh=FmjeRyBu/d9Jh+W5fTH5eckhXs/egnA4RoVoBOZYAPU=; b=O3MPVnOZMO06b3zSK+/eB7I3sGqdVN0IrwbFiZWGpDwf6V6AxJyoSAxNEamBGTRMaS cImHwlWnc9HfDDPus4epWmTVK56nG1gqSuh/Bq36B19c9GlanLI3fRJz4tI/hjTuTXHD rPknuqAFn1MbuqAegvCrHNzp+/FySfVop+00v8SND0VkOQy65BIVsjwZKMVLoVHzNbZn D+mxnyCgiVIhgKczskkCscoafMzegtlwlefVV/Uy/3LcIUoos+oyWlT1IHRjn6FONJy5 qLG3kyZu1FoNwccZmRrEMJvPbekHKyeVnkGIP/H/nI8pAItexsLa/LtH0mrk4wmMRgi4 +G5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id h68-20020a0df747000000b0059290308f8bsi12415304ywf.11.2023.10.25.13.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 13:21:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 006648022B7B; Wed, 25 Oct 2023 13:20:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229812AbjJYUUj (ORCPT + 99 others); Wed, 25 Oct 2023 16:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjJYUUh (ORCPT ); Wed, 25 Oct 2023 16:20:37 -0400 Received: from mx01.omp.ru (mx01.omp.ru [90.154.21.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8F7A4 for ; Wed, 25 Oct 2023 13:20:35 -0700 (PDT) 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 , CC: Subject: [PATCH] f2fs: data: fix possible overflow in check_swap_activate() 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 25 Oct 2023 13:20:58 -0700 (PDT) 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; -- 2.26.3