From patchwork Mon Dec 16 03:37:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuezhang.Mo@sony.com" X-Patchwork-Id: 13909197 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB83F1BF24 for ; Mon, 16 Dec 2024 03:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.183.30.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734320262; cv=fail; b=UmYdv6Va4cSTEVT4KwpK20xxSXoWJ69hiI1TNz+/Pom7L2sypJQcs7ZD0IyzsQKz/PY9f6BnNgVCqpMtnbp9QrWKVkxikemofcciiYydyEFTH06i0qoZ52GTl5wVDO7We6ZFP9ff40YHs5FJQ5E+botBQa+3yTyDVw+sNFRCJHY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734320262; c=relaxed/simple; bh=zV8yvWDpOSr1RjfhbwyVTGwJgiFg6PxCcTF/thqEOf8=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=TbP3Ct2vwHViPAzc0RyeuKi+PxGCnoGedZZmJSLI2vkoM4v3Y44A8M80+QuvbWrhj1lvZcXYqdlrD3Xync3dmq1cZ/lEpZOt12YUfCyV5H3bHVxFMxcp3dSylRh2wTMPuTOWCvRe+tLC2oAhJxreeCGmtoyi5F1IM9cilEh87v4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b=e8DBqyTk; arc=fail smtp.client-ip=185.183.30.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="e8DBqyTk" Received: from pps.filterd (m0209322.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4BG3RRwN028464; Mon, 16 Dec 2024 03:37:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=cc :content-type:date:from:message-id:mime-version:subject:to; s= S1; bh=A+u+7+Fw/zy0bf8HucDgk5QOmqdkYOkDaStqhXYprEc=; b=e8DBqyTkA fpJ2SMi1l3hRl86xsL5tA9LTtQKMW5hJS7IBc0a7DviwGPaqz89M5XxTNLhp/8eb M3Dmt4knImpH9390ADJoCPkftwghiNKAuxd4cd3KgRFFg8FxgTPlJ6IYaJRtaPKE muREZFeRE0ZmL5GRfn4tC/wJpANNkDbR+wp6ZDri9iZiAsdvy9aMUZ/VIwnpnWkA s9N/tc3G1WwJ/dyVaq7alI1LHXx9DBMP9YUWpO1hw1bx7BxaWGcGaR44tcRsureZ i/MozDUghPvxPC65PJ0HeB7GrGR8/i/jpI/PFDCbJQZ/kblS1VVyXm2Bp7zTPnkZ yVZJrU4+92lCg== Received: from apc01-psa-obe.outbound.protection.outlook.com (mail-psaapc01lp2043.outbound.protection.outlook.com [104.47.26.43]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 43h0t493yy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Dec 2024 03:37:14 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=a2OWOoTiSIiLxc8ZSCR3HoqA8CylPsyU1Kiu+C9qoHCltSdatF4SPU3UqYNy96QVaTAWgb0vOWwPe5L1kDthXGwc5Iast0tXtRzKlyEgRPCJANq+mbVTvPcgG40Ks4sxHD5I8tJEe2SNr7OwCC/rkx6Riery1H+7pceOa5Aek+GE4Qy5FBYg22+FWP7rWtGmWeQF8uo+74FbBGAM8syG73Rvvzuoxw/NLE6x43rw2aZ5lcgOqupMW8rYJky2E56/PJ6qouksHLkrOqvGC1oIEq6qgzIHfz1ftDwCnAi6qZyxDq/RSvFwauzFY3HbP/INvOv5hSvgumpItcFmBZyJdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=A+u+7+Fw/zy0bf8HucDgk5QOmqdkYOkDaStqhXYprEc=; b=JLntTXLClONPS2lOt2W140hKkak1lDo18ZeSA0ukwWwBhoqQpytcvZ29t/RC7P1n4nePhchuFelRtjuU2Q/r1qh8aBLI5eYWWwM8RM5I+KyWiLieor+Iyk2mHdMSFHUhZYLgDYDBHHRI/0+GTMe7eFNl0nT7eWmFSn8KCXbqKUdB2ZRUjkNzh6zeop27KCsk+3AyszFUey7/hMdjGZ65R/5Va3NstWh9y6TLo5zaeC75ai+HOBslROqN/ZI6AE/VvQ9jcj+JyFep0CShJ4CXRtW8oLHpGa2+fr82cKEg4IsL2/qpGsZjWiMxcSHSlkddz4qvsnBEw1oMDTWeucVFpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sony.com; dmarc=pass action=none header.from=sony.com; dkim=pass header.d=sony.com; arc=none Received: from PUZPR04MB6316.apcprd04.prod.outlook.com (2603:1096:301:fc::7) by TYZPR04MB8299.apcprd04.prod.outlook.com (2603:1096:405:dc::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.19; Mon, 16 Dec 2024 03:37:04 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::409e:64d3:cee0:7b06]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::409e:64d3:cee0:7b06%4]) with mapi id 15.20.8251.015; Mon, 16 Dec 2024 03:37:03 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-fsdevel@vger.kernel.org" Subject: [PATCH v1] exfat: fix the infinite loop in exfat_readdir() Thread-Topic: [PATCH v1] exfat: fix the infinite loop in exfat_readdir() Thread-Index: AQHbT2lQTa3uFYN5MUScy4mppc6EkA== Date: Mon, 16 Dec 2024 03:37:03 +0000 Message-ID: Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR04MB6316:EE_|TYZPR04MB8299:EE_ x-ms-office365-filtering-correlation-id: 48b2f8bd-63f1-47d5-201a-08dd1d82e85c x-proofpoint-id: d8690225-876f-412f-87c6-a7cb45557a4c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|1800799024|376014|10070799003|366016|38070700018; x-microsoft-antispam-message-info: =?iso-8859-1?q?f6A2k75H0rzqz1iKMOvIr2YtoC?= =?iso-8859-1?q?68XTZsikLMSizO7wduXM8fht1GABoYDgwPj3rakUDJRTtzRsJs7gvK392e0u?= =?iso-8859-1?q?jmYN9E6t26qJ8Zsdp+MB78Q8QBQag988cZb8gbEco1o+tFtxBVeZgBRyJba3?= =?iso-8859-1?q?EmdmmlRxO+PZQAV+IwuxEYFzypskZB0JH9D4QQxeMEcYaG6BjnMpiO07kHBn?= =?iso-8859-1?q?V+S5aH/blWCMyb7/Zi6sFm5qRhOswP5ChtSCgJ0I/FmIPnciYjEb3VOCA5qk?= =?iso-8859-1?q?cunjEr83Nev+Af/VCP5KZcZQlY318B1xy0kkC4XwFb8dt2id2wEypPgsie6y?= =?iso-8859-1?q?ZcahuTths9OgGb1WddLbj0f+MXGwONCNNbpj5BAoY3iZ877mtrRE5dFmclBL?= =?iso-8859-1?q?7DT1fWRWstzVyf4/yPwAr1lPOX7w7CJ2jSZuia0K4RcYNFUkd1T5XOjfua4k?= =?iso-8859-1?q?0IOXNwQoGdnD1J7vvvBBk+OUR7Pzn2ord3kcMI6OTVzjya4Hl5f3A21MlF0i?= =?iso-8859-1?q?P2ZfP2u1tyTQsWOzSy4Tupx/RWC2HSXbc0wePSFgXX9wSJhGlG11mnG7xvvP?= =?iso-8859-1?q?s//TEP2idaqvdwScdOltZZO5AXVkFIJbHmeIsZrLAEbvjyhFsIyQfi/ha3ag?= =?iso-8859-1?q?/UITy22pzoS19C2xqGONT7ylPR+V8MZhjuh7kwsedIO//nGURnS/mcE2k43v?= =?iso-8859-1?q?lJxdwA1rBvw0yZTUyNW2C4kR6s1YpoIM225RzFU7EfHtz92MacbIyrUFORpU?= =?iso-8859-1?q?mT5gCKnW0Tg0fsG5XF41LgZPcvEgdPT/YuseHRv5hZS4YZ/hBpia6YznAxp9?= =?iso-8859-1?q?/rAOMM+ZXQpcyJr/Yori3gLY3/QTvDlor4bRw6xxnEx+s+u0ziydemOR4hXw?= =?iso-8859-1?q?eKL7la1TsrfViJYzdDUIq0J9PMtK5vJc2wusT5k9I6wpLcMUkegn2r07Ap9Q?= =?iso-8859-1?q?YRfsiT+P/97RcT46TS1X2TriZogszyLY6jrUap9dchNpYTwx5bdcflXVvi5x?= =?iso-8859-1?q?6oJ6Z5LAozQmIU2DDWQhdJ3L6M3WgqLzqh2efZk/vOkgTEO8xyrHkis/PwNb?= =?iso-8859-1?q?12Nl/KFQGndaJLFr8+7IXK6NxhApg4XOcCAfZZzEPwfcpSRIyXdSnLBKsKob?= =?iso-8859-1?q?/7Aj2fry7wsI97c6pRpv3W3GHdxnFpju9YSpDBiUX9qjypYbMfpVM3rDeFAq?= =?iso-8859-1?q?XDbEbM5n8iUpYydVD25JoG0rWTCRXLX+GvBd2QZbTAkkkP2H+VFNF/R15MXZ?= =?iso-8859-1?q?ki1nk0QrHX5NqROVXg3IOTRt0JCjpLSk8vX2XQs3936IN6hIIV2zAHbYgVm6?= =?iso-8859-1?q?6nV24RsSR6xI1A4oXS4p9RqayT5MWCFzkEGlK2xOemT2zsmjiVqRMAdabloK?= =?iso-8859-1?q?v5trUkvoo/M8WEqb7E71K2Ig/JBhx7OiCEG1l8ks+dzGYeHvKQrel4+MYUpk?= =?iso-8859-1?q?i+?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(10070799003)(366016)(38070700018);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?hYF7KZ61c304XTmcfNqvyEQ?= =?iso-8859-1?q?QM0WdbjdYOBcJ7BGNKlJvr6qoodpKzYmklLCbpYoRaAogPifuw77XIHaxOkw?= =?iso-8859-1?q?gG/0SpGV1OyI6ZU6gQjK8AC7qxAkFugK9fgyKs7liALNSGDyJ6XvCUpE1mAx?= =?iso-8859-1?q?ZtO61ycHamClWRK+1si2ziEyXeOCT4Qc8Y6yldC67Jxck9///PUQIAOFkzXN?= =?iso-8859-1?q?IkVVzIO6bKNGQJ59kGL+yOtCPU8phF21GhqJPfWttISqt6fiXL4Ynd8teAAH?= =?iso-8859-1?q?YJiWpg67cEMOc6vV6hH2TUlqcwj17WAW5nxQ/O6DRhVQc9kR+RPGxCpaFyup?= =?iso-8859-1?q?JVHneGp3TWDHaNGWHdytBqxFLD7iFPDIQbLspetZ0TD2m7dg600s4P2ZXujn?= =?iso-8859-1?q?3FXWr8NBRPR2K05ghgQN0zvr4bHxpKFWQleTbi3vH3PjwUighO4fnvTWmzw1?= =?iso-8859-1?q?A6mmamd3ErDFTfH2k7UdK8YzXAgg0EJq5QUHsiXyXsouv/6FiHMyI71XyMF5?= =?iso-8859-1?q?CFEnVWCRJXf1grmuzdtnkrE64AaC8+FmwKJfnC5X6Nl2h2PnGYkQ3FEZ/F66?= =?iso-8859-1?q?F+WUdpesbAHRx9RYPVqoe5NLE06sTEJXC44ZeXDDFC4eQcCK0FAjSP+i4/AA?= =?iso-8859-1?q?xdaSBX/ngUM5zySUctqmBiMHQZP85U7dJSBLcRu6e1lCIPWmOdIn9KxQWXfc?= =?iso-8859-1?q?//VcbTImqY5rBX1W45XRjC2eF5bjTB0Cst0/ZmRh8XOM433tPF9K7WJYLxFk?= =?iso-8859-1?q?hd0xocPZT3e4uoMgHNCFg7/RajHNfPsG/6nFViLXCdKxLNT3CME6GqNgBFp5?= =?iso-8859-1?q?BzKmrJageq3dExrt6xVZ5FgCsFLuH0iw1wRU0mctqsKjgYfX9zBCf/tuZhF1?= =?iso-8859-1?q?lJwTKUGAdakQhFEEUr/0xnjI7J1qmf4NNS1HzW7H2gBHxdRTivYFCJAhec+l?= =?iso-8859-1?q?2UxhK0pdsHi/qbUNgxwbuU1krmcW2aT+cjKahCDNoyaukGDzXYCElkecafu6?= =?iso-8859-1?q?U67t7O0P+5tykIM96UN9UPt1kPB5XAvkwtBcd7DTiFPUijgU/6LiJL1OD+6x?= =?iso-8859-1?q?pGFs1vXetJxOiOxhJVcgw8/oW6+QAHOPh06cfENbBgDSTsTao5lcpT4c2LLO?= =?iso-8859-1?q?xcDqTMSJ/5gVrtTzuSbDEaXwpT5/PFokVez1kUFh+NAomF2DJnzeouTQAVpl?= =?iso-8859-1?q?m8wghcb6A1DFuYtpwDu75Co3hGFlf14UiC1uASuYj1WTR4bw6GLwhmKmmkJk?= =?iso-8859-1?q?Vm0hHIITrHXYxjiWYSh9Pz39T6GFkNEHJwmRa1ZgMNOkeE3vjcdVxJqGRgk3?= =?iso-8859-1?q?XRHsU+3E5+A56rainY94Uulol+uDzw0XxokHhfK28cktCmlpuVOT5AyGA4e1?= =?iso-8859-1?q?o87N0CX7w4b+CklYKkMZLJGFqHeyBESPt8NUroErPFuzff+2PbhuPkVFqilx?= =?iso-8859-1?q?nTQW6ysA9HQUd5sH/VlXzeZ2WqA5IjnT9dgtD2raDoHE7vsXKaSXz8Tjhl4n?= =?iso-8859-1?q?yIW7IixHyTf/b+Ab87NbNHfkw4bhreMWtgBYr275iZ8+xeV31hrUZLTM04uC?= =?iso-8859-1?q?O87vHuy6XxS/AYDGuwCpWIe8BYfXQwqChhEzOujIjkShad7NBh0RJkak0n2s?= =?iso-8859-1?q?LNNtKGOxA76DDPsAtV28WSA2+3HyQdkiX4A44IL4ZE/T3m8Cph1RooXFknFY?= =?iso-8859-1?q?=3D?= Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: PvdCeqHLmD9Y0iXxCGLVIYiVoUxZh9aK2PaZ3zS4eeMTNwvlehlGaqMnkOyNFl/GMeIKfLDJnTLNwyvaR+x4oB1w73FjxLSNsx8vmwsUEwQIsekoYCYB+IhIv4bkSeT6gwxIGmBER0lpXVH7+NXL2oUe5vXehlq9rqOY8IT2FGNsvYC+HjJhXo9nEdDp2FcLIl7CVhliiDOrHXVzGQXE9o0oNG6u8KPXCAjD089tgOJ8d/o7BWJNHE3C723pJshJbQMg918KhNq8C9P/jSiYdJkdW3DAJmf2WmTspkGTsjDi+eGtW9jhOXnFZoi9aoLV2uHZqo8Aj9ZFABL+LWS3syyPEmJQ4xyr4+np0DsKhuZdnxAWnz8U97n3iOkh9pD0wlXE62wiBUE97Q8jUc2RpjgffBRH/7bYKYaiZzezvqnGvdqV90XY4hSeEzjzhi+qh0fyL4hWG3TEBCBZzhzDVbAZ0XADHpFeGdAyNrzYnsBtrb6RrwkieYdKJwkXoZvqhv3uVZzUPbVybasJBWqL+Is0GZLKSTkGDGLeAR9O9ctbWu0x1UjtRzY9H8Z2H2Fr8PkiEjeBLJmeUmZlIeYSdpJTppZ09DVaz7bBJp5QB79PiYnnk7Q4wa01Cc1baEEj X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PUZPR04MB6316.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48b2f8bd-63f1-47d5-201a-08dd1d82e85c X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Dec 2024 03:37:03.7686 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +9I9dEaf0N3ke2xWSbyHdflU+quokOATZHnI8Ojcz7wca8ttQ0nZJsJbGStLj4SXx7E55YFBWESBUVMz6r1+Nw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR04MB8299 X-Proofpoint-GUID: 4ZmJGACde6igyiQgs-IK6qh7HfPepvW_ X-Proofpoint-ORIG-GUID: 4ZmJGACde6igyiQgs-IK6qh7HfPepvW_ X-Sony-Outbound-GUID: 4ZmJGACde6igyiQgs-IK6qh7HfPepvW_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-16_01,2024-12-13_01,2024-11-22_01 If the file system is corrupted so that a cluster is linked to itself in the cluster chain, and there is an unused directory entry in the cluster, 'dentry' will not be incremented, causing condition 'dentry < max_dentries' unable to prevent an infinite loop. This infinite loop causes s_lock not to be released, and other tasks will hang, such as exfat_sync_fs(). This commit stops traversing the cluster chain when there is unused directory entry in the cluster to avoid this infinite loop. Reported-by: syzbot+205c2644abdff9d3f9fc@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=205c2644abdff9d3f9fc Tested-by: syzbot+205c2644abdff9d3f9fc@syzkaller.appspotmail.com Fixes: ca06197382bd ("exfat: add directory operations") Signed-off-by: Yuezhang Mo --- fs/exfat/dir.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) From 2ba96e6e4923f0ad0d1bbcc077e887d5d7031bc0 Mon Sep 17 00:00:00 2001 From: Yuezhang Mo Date: Fri, 13 Dec 2024 13:08:37 +0800 Subject: [PATCH v1] exfat: fix the infinite loop in exfat_readdir() If the file system is corrupted so that a cluster is linked to itself in the cluster chain, and there is an unused directory entry in the cluster, 'dentry' will not be incremented, causing condition 'dentry < max_dentries' unable to prevent an infinite loop. This infinite loop causes s_lock not to be released, and other tasks will hang, such as exfat_sync_fs(). This commit stops traversing the cluster chain when there is unused directory entry in the cluster to avoid this infinite loop. Reported-by: syzbot+205c2644abdff9d3f9fc@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=205c2644abdff9d3f9fc Tested-by: syzbot+205c2644abdff9d3f9fc@syzkaller.appspotmail.com Fixes: ca06197382bd ("exfat: add directory operations") Signed-off-by: Yuezhang Mo --- fs/exfat/dir.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index fe0a9b8a0cd0..3103b932b674 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -122,7 +122,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent type = exfat_get_entry_type(ep); if (type == TYPE_UNUSED) { brelse(bh); - break; + goto out; } if (type != TYPE_FILE && type != TYPE_DIR) { @@ -170,6 +170,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent } } +out: dir_entry->namebuf.lfn[0] = '\0'; *cpos = EXFAT_DEN_TO_B(dentry); return 0; -- 2.43.0