From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx01.omp.ru (mx01.omp.ru [90.154.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF7DF171AC for ; Fri, 22 Mar 2024 09:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.154.21.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711098338; cv=none; b=e7x9q5/FWu/dY2loKnaJSlO+3V4boDlU1vM77tfWaVOgYFJbESk0GYDw5avV1fMGqyXW7ka0iIcRtKN2KgbVR4BPih4rjGctnPctylMOORN9NAdRtEQgaDrjPYP05oFMJzcwhDQ5uZahfoNy0NjkMWsu455VdASbnZlMejRWRGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711098338; c=relaxed/simple; bh=0SfqVZk9hcRK6f4B5G6z0EpueUIq5c4y6dDJtYndN1Q=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=O54b5QKH3pVkY648geusCWQR/ysDcD+fg0pkyISYOoUsqw5Ih2C8BlOBJ1zJ7H3R1X5ljMF9SJ3W16iPdWMctVbb3ewK/uGz2tHLvZfMIL/mlTO70m3Z9wl6fKj/VKoH6+9Ww9rx+h1aIMZuYpMxMjhGE687K5ntn9oJ5xI55q0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru; spf=pass smtp.mailfrom=omp.ru; arc=none smtp.client-ip=90.154.21.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=omp.ru Received: from msexch01.omp.ru (10.188.4.12) 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.1258.12; Fri, 22 Mar 2024 12:05:32 +0300 Received: from msexch01.omp.ru ([fe80::485b:1c4a:fb7f:c753]) by msexch01.omp.ru ([fe80::485b:1c4a:fb7f:c753%5]) with mapi id 15.02.1258.012; Fri, 22 Mar 2024 12:05:32 +0300 From: Roman Smirnov To: "jaegeuk@kernel.org" , "chao@kernel.org" CC: "linux-f2fs-devel@lists.sourceforge.net" , "linux-kernel@vger.kernel.org" , Sergey Shtylyov , "Karina Yankevich" , "lvc-project@linuxtesting.org" Subject: [bug report] fs: f2fs: integer overflow in f2fs_truncate_inode_blocks() Thread-Topic: [bug report] fs: f2fs: integer overflow in f2fs_truncate_inode_blocks() Thread-Index: AQHafDfLQelSTjCNm0mAqA97oN6w2Q== Date: Fri, 22 Mar 2024 09:05:32 +0000 Message-ID: <085b27fd2b364a3c8c3a9ca77363e246@omp.ru> Accept-Language: ru-RU, en-US Content-Language: ru-RU X-MS-Has-Attach: X-MS-TNEF-Correlator: x-kse-serverinfo: msexch01.omp.ru, 9 x-kse-antivirus-interceptor-info: scan successful x-kse-antivirus-info: Clean, bases: 3/22/2024 6:00:00 AM x-kse-attachment-filter-triggered-rules: Clean x-kse-attachment-filter-triggered-filters: Clean x-kse-bulkmessagesfiltering-scan-result: InTheLimit Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hello.=20 There is a possible bug in f2fs_truncate_inode_blocks(): if (err < 0 && err !=3D -ENOENT) goto fail; ... offset[1] =3D 0; offset[0]++; nofs +=3D err; If err =3D -ENOENT then nofs will sum with an error code, which is strange behaviour. Also if nofs < ENOENT this will cause an overflow. err will be equal to -ENOENT with the following call stack: truncate_nodes() f2fs_get_node_page() __get_node_page() read_node_page() It looks like ENOENT processing is missing here. What can you say about it? How can it be fixed? Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.= From mboxrd@z Thu Jan 1 00:00:00 1970 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 3635DC47DD9 for ; Fri, 22 Mar 2024 09:05:50 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rnaqR-0007gt-QN; Fri, 22 Mar 2024 09:05:48 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rnaqQ-0007gd-Iw for linux-f2fs-devel@lists.sourceforge.net; Fri, 22 Mar 2024 09:05:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Transfer-Encoding:Content-Type :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=JpJY8nN7ePdbJUAfzWfHTiZULV4nOMaCYCz1s07YbH4=; b=YX5WAdhmmD+mEtIpWKQZZ+OWkU rCMNuU8TKvSY/YnDOUC8bYevEgZzbCkC4U7EZRMGYfVpNkaVLy3JYPY+h8ktqtgSlAfzD++5/I77V Gy8Qy3rWA5jNIWEmMyDgboW9dTvvQcEFGgbT1lT8oaB0dyf6S7h14BNzXQJqlWMsluvQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Transfer-Encoding:Content-Type: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=JpJY8nN7ePdbJUAfzWfHTiZULV4nOMaCYCz1s07YbH4=; b=m 4+dMoUIhlXK/qK+F6rj7MGIgtuOyk6HG0qjD8yXKDoH/pDCorYBRbNYrl7eULcFlmIhfnvwy6RbVz +YLZ21qQTUd0rjW0Tw3CtJObv77a9qfWlstuM4K7KuEOGWGMVDPDXVO3Xinn11L7zhYOKvRno7NdB +bDyC67yn6N0Y3Bk=; 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 1rnaqP-0005IB-TP for linux-f2fs-devel@lists.sourceforge.net; Fri, 22 Mar 2024 09:05:47 +0000 Received: from msexch01.omp.ru (10.188.4.12) 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.1258.12; Fri, 22 Mar 2024 12:05:32 +0300 Received: from msexch01.omp.ru ([fe80::485b:1c4a:fb7f:c753]) by msexch01.omp.ru ([fe80::485b:1c4a:fb7f:c753%5]) with mapi id 15.02.1258.012; Fri, 22 Mar 2024 12:05:32 +0300 From: Roman Smirnov To: "jaegeuk@kernel.org" , "chao@kernel.org" Thread-Topic: [bug report] fs: f2fs: integer overflow in f2fs_truncate_inode_blocks() Thread-Index: AQHafDfLQelSTjCNm0mAqA97oN6w2Q== Date: Fri, 22 Mar 2024 09:05:32 +0000 Message-ID: <085b27fd2b364a3c8c3a9ca77363e246@omp.ru> Accept-Language: ru-RU, en-US Content-Language: ru-RU X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.188.4.41] x-kse-serverinfo: msexch01.omp.ru, 9 x-kse-antivirus-interceptor-info: scan successful x-kse-antivirus-info: Clean, bases: 3/22/2024 6:00:00 AM x-kse-attachment-filter-triggered-rules: Clean x-kse-attachment-filter-triggered-filters: Clean x-kse-bulkmessagesfiltering-scan-result: InTheLimit MIME-Version: 1.0 X-Headers-End: 1rnaqP-0005IB-TP Subject: [f2fs-dev] [bug report] fs: f2fs: integer overflow in f2fs_truncate_inode_blocks() 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: "lvc-project@linuxtesting.org" , Sergey Shtylyov , "linux-kernel@vger.kernel.org" , Karina Yankevich , "linux-f2fs-devel@lists.sourceforge.net" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Hello. There is a possible bug in f2fs_truncate_inode_blocks(): if (err < 0 && err != -ENOENT) goto fail; ... offset[1] = 0; offset[0]++; nofs += err; If err = -ENOENT then nofs will sum with an error code, which is strange behaviour. Also if nofs < ENOENT this will cause an overflow. err will be equal to -ENOENT with the following call stack: truncate_nodes() f2fs_get_node_page() __get_node_page() read_node_page() It looks like ENOENT processing is missing here. What can you say about it? How can it be fixed? Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool. _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel