Message ID | 20231025202019.5228-1-s.shtylyov@omp.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp216223vqb; Wed, 25 Oct 2023 13:21:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGb1xEdf7QO5M8+6q4hrCap/moADjnEmErZE+R9x58cPHoXhSxd116+oW8MWybaQynWnXvK X-Received: by 2002:a05:6808:210e:b0:3ae:1b21:fab1 with SMTP id r14-20020a056808210e00b003ae1b21fab1mr21235339oiw.31.1698265299598; Wed, 25 Oct 2023 13:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698265299; cv=none; d=google.com; s=arc-20160816; b=gkO74o/BnOApe/TfUDvnSNKhm/dvtLDJy6bkRXUGFa+hX12hFe4qvNgFVEvicHvK9d DHwxRnHb1rke14gSd37TyK1BAkYkbsZ/rmBCG7JhfMlJ8+cAJU6tkoKedrT1C4jSzy1e RKGL62YWs9TLihBSuJoo4SENrwbhQmu6jEf+D7Yw8/MrnzF//gg7TgywAmHE2W13MXhI kZDa4nKHYJFXoxzic7npzxjFoLuSHWVy0gyTA4RxEeqvj8P4Oam7vfdYDNvUoNpUjq/2 PuKHfhoh938RQvg4YT7q8nAl8sObw6mn6C33auPWWzf+/zquW7u6VELKzBTSAN0jvYqV njDg== 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.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id j62-20020a252341000000b00da04fb81279si4496002ybj.15.2023.10.25.13.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 13:21:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id D3435807C5DE; Wed, 25 Oct 2023 13:20:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbjJYUUj (ORCPT <rfc822;a1648639935@gmail.com> + 25 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <s.shtylyov@omp.ru> To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>, <linux-f2fs-devel@lists.sourceforge.net> CC: <linux-kernel@vger.kernel.org> 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 lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 25 Oct 2023 13:20:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780760234949576538 X-GMAIL-MSGID: 1780760234949576538 |
Series |
f2fs: data: fix possible overflow in check_swap_activate()
|
|
Commit Message
Sergey Shtylyov
Oct. 25, 2023, 8:20 p.m. UTC
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 <s.shtylyov@omp.ru>
---
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(-)
Comments
Hi Sergey, Thanks for the patch. On 2023/10/26 4:20, Sergey Shtylyov wrote: > 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... What do you think of returning -EINVAL for such case? I assume this is a corner case. > > Found by Linux Verification Center (linuxtesting.org) with the SVACE static > analysis tool. > > Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru> > --- > 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) if (unlikely(higest_pblock < lowest_pblock)) return -EINVAL; *span = 1 + highest_pblock - lowest_pblock; Thanks, > + *span = 1 + highest_pblock - lowest_pblock; > + else > + *span = 0; > if (cur_lblock == 0) > cur_lblock = 1; /* force Empty message */ > sis->max = cur_lblock;
Hello! Sorry for replying a month later than I should -- I got distracted by the other Svace reports... It took a significant part of the weekend to swap this stuff back in... :-/ On 11/7/23 6:29 PM, Chao Yu wrote: [...] >> 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... > > What do you think of returning -EINVAL for such case? I assume this is a > corner case. I don't know the code well enough but I got the impression that iff we have a file containing a single page, we'd have one successful call of add_swap_extent(). Am I missing something? >> Found by Linux Verification Center (linuxtesting.org) with the SVACE static >> analysis tool. >> >> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru> >> --- >> 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) > > if (unlikely(higest_pblock < lowest_pblock)) Well, Greg KH says we shouldn't use unlikely() unless we can prove that it indeed improves things... > return -EINVAL; > > *span = 1 + highest_pblock - lowest_pblock; > > Thanks, > >> + *span = 1 + highest_pblock - lowest_pblock; >> + else >> + *span = 0; >> if (cur_lblock == 0) >> cur_lblock = 1; /* force Empty message */ >> sis->max = cur_lblock; MBR, Sergey
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;