From patchwork Fri Sep 6 21:11:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catherine Hoang X-Patchwork-Id: 13794750 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 674FC1D6DA0 for ; Fri, 6 Sep 2024 21:12:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725657126; cv=fail; b=ba3frJ0WYzhad6hi7jpVJsVLh5iC//frRxzxnK3IsMdJdMztMk6mtQo0phg/2exseCeITkjtGyuDShQ6+A2HOp5R8Vmb9z1QJ6T64mgo19gwgcaWE0tJQlotLJNU9viylAaMkbi913oI9DBbnVvDT+mu0GXcom/UR3cnOyJP414= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725657126; c=relaxed/simple; bh=GO/FDL+UYj3uZlQGMrB/2CKdekfe7KyVHKMCK/eZz5E=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=lh9k49/tDFh0m/Hrgtt7+kLcpDFkmZqHn/lFkGvTUcZRkWpvAt34Ch6Mxk1MyoUnjgZKTpsvd0kbol3Fqfni2YCOKL9izmHQveaG7qKOhToT6D0vociBdBob5B5nYoeXbMNW22C0ul3tMx/OaFv4dAmvwv7aCLqWvRgcGbb0t3A= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Y8vhC+C6; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=U/orUzpD; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Y8vhC+C6"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="U/orUzpD" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 486KXU2d024511 for ; Fri, 6 Sep 2024 21:12:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=JfVAJ1s4jlNXvn5O2XfmUxuls4+9rdmfFiV4N2Pn/fw=; b= Y8vhC+C6xPxZ/68ZxASuADazGvMMVIkr49yW1KPJ3Um5xBltu1hNCfmt3HJuSJl7 YNMmceGGhl+VXJH7MhDp911gHzHeKarjJ38T8SZUPGPYVcWYN2iv8dRgbEZI2O0J y1/8V/lsyJKM9CHjR/6/rF5Sa04mBjfvYmp6YBt94H8savFvvkLN71sn6qBHRi9U r1wE9OX94LcDdTBKZqnN4ox780I5gN63rTliwPt0XQ+KFU3+GvjVeNcAQBwkJU4N 85Ew5wZgT7BN+71fIbm3vU0kKRBygSb2uUPMXFIimlsvA6ivGqhVjZHxL2nXzRid 0AHwDDLNiABPwBbCdfBozg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41fhwkak2w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 06 Sep 2024 21:12:03 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 486JUFKm036958 for ; Fri, 6 Sep 2024 21:12:02 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2175.outbound.protection.outlook.com [104.47.59.175]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41fhyge9sp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 06 Sep 2024 21:12:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i+Cp1QXrOps24zivk2n8/QuxXMz5Fn/jHXV+7hiUavL5vt+1fdU5CfCdcip+HBLDZFz01Nveka9wUt4ftjc1ulfVMjouEzuKhzOGDeU5hu4GhC713fXdM+nZ/FQiblKkptES5H41e+nFT+8wnWn9lpKKchfeX2u8QkjFRcyavFFtjGPM2LDZdveM3gyzrg2kRQSS12Y+70WS9uwyLyfAeD/92nEwN73O3oHRQ8Kx6JnSjIBdsVWs6sqIw51Exb7yG47FKSkDFRopZRv5DVwVFSfNvzxA5Y3gGc2JJmMEJRFt/bGSLdwE43w04F/YK/ZBglM7R3PXM2AcLrjOHQIQkg== 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=JfVAJ1s4jlNXvn5O2XfmUxuls4+9rdmfFiV4N2Pn/fw=; b=ht4KFYmOpuf00GEJnfTj6vNzGtKlAV85LWAFuZs3MLYiE4hnkNTvjj/gpvVWlkbR5mKF0Om2dUxmvSHZ5lxWfWwqV5juTEjk31GclEI9PJpcq+fVnqUKNxBtgF0usqxDc+i2rl6fgdoTxlVfHsXx9Q++q9tpR8RNh5e5zlNAcitd76aXHZvkDZGy2eQXJNxKiEKJX3/Mhb4ySOf7og7SqJmZNzu8DDOnvR7P+MwD0b0tEZgKxCKlQHVnfc6koWhWn3/mRTM5f4tKuIzMX1OOIRscqkYBf5U3MCd9WJKgqhAdafHhQ9ryItYHKyJP9Vr+nxCnxtHoGdh2B8tDi5FFMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JfVAJ1s4jlNXvn5O2XfmUxuls4+9rdmfFiV4N2Pn/fw=; b=U/orUzpDckkOJaPBrHg43dqrDdLlnh+tqwv1XKXRi/apVX9g4f3ZUWX2aA0UMLtoexd6kxDy+fwS+fipdXjRzVrErvT5sdZSnPJpj4ikO3ejrYUyqsuCfTBHvHMaJ5YOPaYsRNQ7U1xrlaUqYd+d06c4PI2dC/azZsblyViWTMQ= Received: from BLAPR10MB5316.namprd10.prod.outlook.com (2603:10b6:208:326::6) by CO6PR10MB5587.namprd10.prod.outlook.com (2603:10b6:303:146::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.9; Fri, 6 Sep 2024 21:12:00 +0000 Received: from BLAPR10MB5316.namprd10.prod.outlook.com ([fe80::a63b:c94b:7ed8:4142]) by BLAPR10MB5316.namprd10.prod.outlook.com ([fe80::a63b:c94b:7ed8:4142%4]) with mapi id 15.20.7939.010; Fri, 6 Sep 2024 21:12:00 +0000 From: Catherine Hoang To: linux-xfs@vger.kernel.org Subject: [PATCH 6.6 CANDIDATE 09/22] xfs: validate recovered name buffers when recovering xattr items Date: Fri, 6 Sep 2024 14:11:23 -0700 Message-Id: <20240906211136.70391-10-catherine.hoang@oracle.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240906211136.70391-1-catherine.hoang@oracle.com> References: <20240906211136.70391-1-catherine.hoang@oracle.com> X-ClientProxiedBy: SJ0PR13CA0091.namprd13.prod.outlook.com (2603:10b6:a03:2c5::6) To BLAPR10MB5316.namprd10.prod.outlook.com (2603:10b6:208:326::6) Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BLAPR10MB5316:EE_|CO6PR10MB5587:EE_ X-MS-Office365-Filtering-Correlation-Id: f2023ff1-500f-4685-cb57-08dcceb88c0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: iUlWhkOHYGxB11dml7cFlC3ZQkuL8EOX/TDDMqlJk8e9/OxehVp29Vn82XrLfVjeP45tekJ7m8SeLdvKWLRI6inrSLSA+O9skr+skoMkQ0SBlLipjpUqSXSDt8dHpmItkn0hBaHXUV12petjta010SVb3piRA/n18aC+vtgesZI69eWh/PH5PVW2/ScU8UBzD4utjYZk/VGfqP8dPGAC0wS28/5LX1Li2mKbX2BdjzApxziaaqqEIYdbFnM/4mp5N2LHJl3zzGi2zV72wTzMDSm7BC9aDFFGBElMpl5N/uzsEQsURnl58GMmnx3sTgsUhba0nTyDl3ey54bvUoZCpFR3BUy897tr46VJzHXqkKE0oOMUwEIO0g+rWPeHY87IC2xP/dSaMT9CPGOkX71uEuHOdQwRBYX9em5VQGjimVe1J8UCgwuOwEi+wfKE5ouh2GYd4hebPJDSzBbmXnR7OF8S6Lm5h/1Z3Zx3MleAmuVpu6h0kScsAu6Bh1+oun2UVFED4RWdCT1KkWC8uaB+ffDKt8UvaGV/EKPvDMAUuoJ8ZErqlYUkrfByxo6EL/YLk7+1qNwgrw1N5WedaRZDA3zPah0NYEKj/X8+dvDtypQxh0rHz4LTztQKNxtfeczw2XPVVZ+BmXQMawfrcKsjpqIq4DjvGvARhgzliJIzeRRBqFbDpExzL4D1SH8Ib+zLi4FitO71dfjipz+UpBpOMWEih0XFuNwMGYuw0ZboWUzZs5CmC6mjLo7NgSMvKI5d6Kit3KLH3epWvkJdaSk786JjDzxTjf5T/FhOEouaQT62rtGBnw4ihFHLBaW4U6fxeZ8y2ubKa6PESL0CjyqMhcMaRLb7KZ+pLhXZaBidANJLI+za/WFDinE4mgKXWWS9a4D+qCV9GHMFozw/Vh7xPj1uY9R/CpSZTw02IIpIKLdzd0eAItyCFjXmSl8q5D+owtIBG3xtKRXdEt9c7Xz7yuulh9D6UcDxEQ1+sAum63b7gsKUQFXy3Gyv5RXXzYS8qE+SnV32YeFn4mU3hXPKlFUi325dMOeBgyeSaBqYL86+tNToYVz8ZpuLxfvijy8mjJY8eX6GOXTTdeh59DeY0T+0pFB3gD28O8eyVTBtbYNx47z7KPEfiJvyFg7gzWwGBdoCXRP2UG3xZe8/5L1nYPzk3AAtajvcR1CQBg7Eub0ayimPtJwgHhDgXyRENi3sMzLz/YdJYTafqnJ0TGEqzc5a/V4o3eBMNAYcBFLHg0XlJ8sANEPDYS8XNmMtv1PMJnds6P78r4lfxpbKLwuMeCuUWJaBml0ZMRvu4iDX9N34cGCVxHqj+TjmkODDiFPOqpMGxnMvlZb1dljM1qra0A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BLAPR10MB5316.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-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ACK6bBaIQ7QJQkB5hI2pYqnpdZ9f7feVd06mSFivuTn/wVC9xn/YNgJyJg4cIsDDIDfs1SKwjyJYCbQ/HXFJ3vVxphGCYMydA45Y1x3cMgjXuemhZBE5v310gtcCtzwm2dt0YURvASG8qQNm/IqBPG6NQq2k7evfEsbDnMDwtTkCETH837E= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2023ff1-500f-4685-cb57-08dcceb88c0b X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5316.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 21:11:59.9934 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XsONzHPR4uVHW2F9k/k9ThpFgn1WwXIvklVdjTnE1MFpvPW2YCPLUxx6oN6tI/Zs1dcstIeXjtZiJTkVUycRWwTeRT6z+fMQC2y68rNHqbQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR10MB5587 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_06,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 mlxlogscore=999 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409060157 X-Proofpoint-GUID: uzao9JgrP-T3Pz6D7lWWBqrX9piN_5_h X-Proofpoint-ORIG-GUID: uzao9JgrP-T3Pz6D7lWWBqrX9piN_5_h From: "Darrick J. Wong" commit 1c7f09d210aba2f2bb206e2e8c97c9f11a3fd880 upstream. Strengthen the xattri log item recovery code by checking that we actually have the required name and newname buffers for whatever operation we're replaying. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Catherine Hoang --- fs/xfs/xfs_attr_item.c | 58 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/fs/xfs/xfs_attr_item.c b/fs/xfs/xfs_attr_item.c index 064cb4fe5df4..141631b0d64c 100644 --- a/fs/xfs/xfs_attr_item.c +++ b/fs/xfs/xfs_attr_item.c @@ -719,22 +719,20 @@ xlog_recover_attri_commit_pass2( const void *attr_value = NULL; const void *attr_name; size_t len; - unsigned int op; - - attri_formatp = item->ri_buf[0].i_addr; - attr_name = item->ri_buf[1].i_addr; + unsigned int op, i = 0; /* Validate xfs_attri_log_format before the large memory allocation */ len = sizeof(struct xfs_attri_log_format); - if (item->ri_buf[0].i_len != len) { + if (item->ri_buf[i].i_len != len) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, item->ri_buf[0].i_addr, item->ri_buf[0].i_len); return -EFSCORRUPTED; } + attri_formatp = item->ri_buf[i].i_addr; if (!xfs_attri_validate(mp, attri_formatp)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - item->ri_buf[0].i_addr, item->ri_buf[0].i_len); + attri_formatp, len); return -EFSCORRUPTED; } @@ -763,31 +761,69 @@ xlog_recover_attri_commit_pass2( attri_formatp, len); return -EFSCORRUPTED; } + i++; /* Validate the attr name */ - if (item->ri_buf[1].i_len != + if (item->ri_buf[i].i_len != xlog_calc_iovec_len(attri_formatp->alfi_name_len)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - item->ri_buf[0].i_addr, item->ri_buf[0].i_len); + attri_formatp, len); return -EFSCORRUPTED; } + attr_name = item->ri_buf[i].i_addr; if (!xfs_attr_namecheck(attr_name, attri_formatp->alfi_name_len)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - item->ri_buf[1].i_addr, item->ri_buf[1].i_len); + attri_formatp, len); return -EFSCORRUPTED; } + i++; /* Validate the attr value, if present */ if (attri_formatp->alfi_value_len != 0) { - if (item->ri_buf[2].i_len != xlog_calc_iovec_len(attri_formatp->alfi_value_len)) { + if (item->ri_buf[i].i_len != xlog_calc_iovec_len(attri_formatp->alfi_value_len)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, item->ri_buf[0].i_addr, item->ri_buf[0].i_len); return -EFSCORRUPTED; } - attr_value = item->ri_buf[2].i_addr; + attr_value = item->ri_buf[i].i_addr; + i++; + } + + /* + * Make sure we got the correct number of buffers for the operation + * that we just loaded. + */ + if (i != item->ri_total) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + attri_formatp, len); + return -EFSCORRUPTED; + } + + switch (op) { + case XFS_ATTRI_OP_FLAGS_REMOVE: + /* Regular remove operations operate only on names. */ + if (attr_value != NULL || attri_formatp->alfi_value_len != 0) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + attri_formatp, len); + return -EFSCORRUPTED; + } + fallthrough; + case XFS_ATTRI_OP_FLAGS_SET: + case XFS_ATTRI_OP_FLAGS_REPLACE: + /* + * Regular xattr set/remove/replace operations require a name + * and do not take a newname. Values are optional for set and + * replace. + */ + if (attr_name == NULL || attri_formatp->alfi_name_len == 0) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + attri_formatp, len); + return -EFSCORRUPTED; + } + break; } /*