From patchwork Wed Oct 30 07:47:18 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: 13856092 Received: from mx07-001d1705.pphosted.com (mx07-001d1705.pphosted.com [185.132.183.11]) (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 144971B86E9 for ; Wed, 30 Oct 2024 07:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.132.183.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730274456; cv=fail; b=M0SS9KGKUt/6NolNA3t551d/z8B6dj04dh6W7qoIaAqjH7Dbchc04lYRKlKrrKHl2AoxLtP5BitCktQIpS0XbqZIVg7O9bb3I4l5jgTGKpSngjy0pn/XqSCssjAVlAQQfHtoQ49aumcjoxpTURavmcjamVm+C/+Op5AOQ3Hb/iY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730274456; c=relaxed/simple; bh=acvWYGI63PLxWNbHF7lmyOyCCWdpZBeGisGN6YsLQ6g=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=Tr0CkmO4Eg8kzC0gPirxTMpZblSk4MtcseQXdcE8h94bK2CXR1IkO3HRss7h7gILA3IinVQH7uWrAq92vnFznI3BU8dkafqpur0QG5yM7bYdrKLpIN8KQLK5WRmaGRkH6TVmc50nP8N3cD5nHUAHf43uzMPAQGU2on+Nb4SGa80= 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=PoTfosFI; arc=fail smtp.client-ip=185.132.183.11 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="PoTfosFI" Received: from pps.filterd (m0209325.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49U6eLmq031030; Wed, 30 Oct 2024 07:47:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=S1; bh=acvWYGI63PLxWNbHF7lmyOyCCWdpZ BeGisGN6YsLQ6g=; b=PoTfosFIHOyyntlmy1iOQjN05Ah2gSVJOYk+ye0XHAEI/ LkW8q8PoMAVAUnPO9przjoVB9yHJSkdJgrXU29Xx3JzqlRUZGGzqg41jUQthKY4m CUhYx8yXT62PGhIxaowlavU2GOmnGaqK13mmKy186jMR15ug4IBzkF1673BDSQGr +Kvwg72f2nAHfCQMl6sC2swT8hryz7Z2BkUptcGng57lspFQ0B1J6N1IkVRerWMV hmgwxvC5HwQLVxpyg43uFDXMB5gERkdO3db8+czEt9fuq6udQSKX0UAfoGi4IATc pQgX9+H+gKUHPcNMnd6zrKV+UZsiKAZ8fxxNVxypw== Received: from apc01-tyz-obe.outbound.protection.outlook.com (mail-tyzapc01lp2049.outbound.protection.outlook.com [104.47.110.49]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 42k2ypgnpy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Oct 2024 07:47:24 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hROgxftDFDkyvtXNzXk29l5gBF3kgi5U9SBZXQuNkWZwfIs5kE0uKcCm4obif59aHgZYx8ceXCMxzRYfSHj/QvLnotPgp+Iv1Vt6lMVhnpXaWAchy08vuXkeBm5Bp3Qj6jC1C7dSAIRg0Ib2Bx5t7De5nKCIng/EfKukbIeRQiDxbnfAYxLy6PXhBWq0LQr7IyrFHRIwVJpAcaGFC94c2WsHgS76Osin+54LwCi4dmXFnE+viEKkVHRcUSTu0hJvofslqxyY+AtPGnb2wRiDxbuEf2HcfFdGrXEHqFpw4DPGjQOrGa/HD3A2yHZqVMJZkvSoAQYMXsL5AA/fHPRTIQ== 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=acvWYGI63PLxWNbHF7lmyOyCCWdpZBeGisGN6YsLQ6g=; b=YYl1brYhifsGF4aJ1rqi+vsRn78Os9SwODzgVXozgQQ8BeslxIZ3Ila40oS5EDymjJuAKCYff1xfHcU0rmLW+v2aJhCpVlWmc3SUEnjmlLO63F0rF/2JBO3h2z2mMULzZFU7U1b2DUslrogpxD85D6sGwhtgypUmSeVYy2uyAqKvqXl8ZGQZ9LvPp6AZkUAgLvt0KbcOdSeu61QJfOH/SN5Ehf0T+z4DqcAO9X/+lEJKmrsyjZgL2+eUIrudjN+bF3T9ukiNO3eORGAFcv6t1AB5PmpucS3PjiZPG+ffOVV/shMjwBJUboUkLZgdtfHc0qIKx0U1Cc5z3yu+nKW+eQ== 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 KL1PR04MB7707.apcprd04.prod.outlook.com (2603:1096:820:118::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Wed, 30 Oct 2024 07:47:18 +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.8093.024; Wed, 30 Oct 2024 07:47:18 +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 file being changed by unaligned direct write Thread-Topic: [PATCH v1] exfat: fix file being changed by unaligned direct write Thread-Index: AdsgM2W/x1aURdJJQVemxv1csSA60QKbCK6Q Date: Wed, 30 Oct 2024 07:47:18 +0000 Message-ID: Accept-Language: en-US, zh-CN Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR04MB6316:EE_|KL1PR04MB7707:EE_ x-ms-office365-filtering-correlation-id: 9c4112ca-3575-48bb-1e4b-08dcf8b71463 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|366016|376014|1800799024|38070700018; x-microsoft-antispam-message-info: =?utf-8?q?MnE27PztbiQMox1SaboKM5/BWjr1noU?= =?utf-8?q?zQ3DDf+p0ROzCg63NZDdbTak2/5fgxtAR98/frBHYQFREdYf7EjfJn2WxQ/FlWjg2?= =?utf-8?q?FT9FaX2dWE9oLpZ5KHKSgN40ekzjeVsieq0HSs4RtEkWve6h2Q1NBgCVkk2a67nMv?= =?utf-8?q?sIELIOCa1McpOm6qYnNWFKYoKaD4lIZmJyGu8IblohZZkro5nLkDCGwWU1xDJOnfE?= =?utf-8?q?4bI6x63mJCEm0oG4sU7now29DlEM6aIOCRX+QnNhn+uIL2uSufMI9rskD6YT0ioGN?= =?utf-8?q?nQ5lds8hTx2zne6eo9SGn0fILYFyUezLwgx+QjPZtQF7iajG9Rxkrfw+AITRVW4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q?P6Vx1vipXzorDSEotO+MxAJSncyyAUt2CCaQR9BvFTi+Ho6cAXPVbtZWd+0cHPKQx?= =?utf-8?q?/+xkoSp/4NnvqZPrz8BLn6pj0Xjh0abZC9XF6schm3H+t6NrPa7jEraw=3D?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:zh-cn;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024)(38070700018);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?8Xks5s4E1EMCbqWLfnyr37tQ0PfT?= =?utf-8?q?UnFDjwdxvljkg5lmuNS51loP+RiBIEyCOGJ5+a99rX5RiIc6vgIzfpqK8FC7GtdF2?= =?utf-8?q?UYHIiW7xzyEFbdH0oO2ytXulPQuZXX1ebz/UbShSANHECUejOjp4Qt0WzX3aGOHTC?= =?utf-8?q?6B5oqouf/0flvxMca8rC+g8yYt4fmIqvmnR4Goq9Rro+AyXvo3T1JqBMsg50Cyaic?= =?utf-8?q?Twect3xi5knJ02Zt1h8suvPljPQe8Sa6zm0qZCOzBe3uJgJ8k/ab8xVmefJb/l9UD?= =?utf-8?q?xxFHBA5NBc34bHdWkcokZpdFEBBCW0yvSOd3Rd051Prod+CVPTuxpaXrks7jbRf4o?= =?utf-8?q?kwKkRfIM7kl0GrHRk8zmPmbRituy8cwvW/7JpK2sUWSDyZlNIBEBcedvE91VmKg0N?= =?utf-8?q?uVeNGwjR5VdWtexpj9YvomTpxs0TXSgQSGKxRX8JY5OAxMiFjbM5bHJFB8zsj4egh?= =?utf-8?q?SMZVt5quuNg1VnIUFdj44bRywt7bxRGij77EbrPLFQMWlTiQZCrWJ5eZZl2ivP3jP?= =?utf-8?q?W9vrr68e1BVazOT0QiF9NVxvVlixZdadb+7p2HKIhecCnoLOXybq4WID0F1oo5OPM?= =?utf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61c/GA1D5cKs7NfxKOVVL3Ojawhw2ulqzqX9yB7sv0M7JO1SJolV16mB/Shw/?= =?utf-8?q?Yfm7QTk02s/F?= 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: 1YcY2prUiOaQc/DzX1hSmAMC44paT8tlFT1vWf8RqP1Za1aRz82oi+g3TmbM8cAHExrcOHWJ27IPXgGamBORV8XuA7dxC3DCsnoH88CBxAPTGZkxOo69pwtAk5No7fhW5HTpNooN6wiyi9ZG0w9O7bWlQdJix+cmILic9ArDm9Y/0Vv7h0NmFJmJpHkmzdYrejRE5ccpMb8rxHeMkaYOLpPaBq2A+S9scHUZuxIL+JX9ik9n3Ny58doxkvSNsbY6GINBziXlzYhsx28MVTDM2H7EqH7QWX1zibxzCo9SUi/oCmllPvydEBQ4Zpe+aUfD74o3XjBPSupE3dJo4BNV6NLEo/cvX8watFoBcr0TLPRzJtPdKyYCkOYhRI19ZM7J+6JffdVuhhnZfRHz+arjgygd6zIaVpRAqs9jnP+QssRgnbq5MebmgWmKH3+dfM0lzEajdFLWfKS44onWLsM7Jw5VKUVl8VgTHEbuJB8F6k/XKLPgtybqwARs6pokrEKKTFEjZcdoj2kUOFtol+N1zeMUvF77oEAI+DTAKX9f7FKZGCXDnqSpuIV9/WEcl66jivLuKdV4gMthfmb5XhOh+OjvDa1Eq+8TtI0FEGZHdIPN8n30wA7d6FvldaKDii2W 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: 9c4112ca-3575-48bb-1e4b-08dcf8b71463 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Oct 2024 07:47:18.4291 (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: oO8fFaWUUG00nqKP3MJk7W/8RefkGZr2MctCozxYxIqgPWQIBFae6CJf1b5rLB7bPQ+nWv4PFBqWJ0zHHwOO3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR04MB7707 X-Proofpoint-GUID: 2950k_v_V8LQDoXKPkDm3QzTNV1eYvF2 X-Proofpoint-ORIG-GUID: 2950k_v_V8LQDoXKPkDm3QzTNV1eYvF2 X-Sony-Outbound-GUID: 2950k_v_V8LQDoXKPkDm3QzTNV1eYvF2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-30_06,2024-10-30_01,2024-09-30_01 Unaligned direct writes are invalid and should return an error without making any changes, rather than extending ->valid_size and then returning an error. Therefore, alignment checking is required before extending ->valid_size. Fixes: 11a347fb6cef ("exfat: change to get file size from DataLength") Signed-off-by: Yuezhang Mo Co-developed-by: Namjae Jeon Signed-off-by: Namjae Jeon --- fs/exfat/file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index a25d7eb789f4..a00f3f1b2cbb 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -584,6 +584,12 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter) if (ret < 0) goto unlock; + if ((iocb->ki_flags & IOCB_DIRECT) && + EXFAT_BLK_OFFSET(pos | ret, inode->i_sb)) { + ret = -EINVAL; + goto unlock; + } + if (pos > valid_size) { ret = exfat_extend_valid_size(file, pos); if (ret < 0 && ret != -ENOSPC) {