18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * fs/hmdfs/comm/message_verify.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include "message_verify.h" 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/errno.h> 118c2ecf20Sopenharmony_ci#include <linux/limits.h> 128c2ecf20Sopenharmony_ci#include <linux/statfs.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "connection.h" 158c2ecf20Sopenharmony_ci#include "hmdfs.h" 168c2ecf20Sopenharmony_ci#include "hmdfs_server.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cisize_t message_length[C_FLAG_SIZE][F_SIZE][HMDFS_MESSAGE_MIN_MAX]; 198c2ecf20Sopenharmony_cibool need_response[F_SIZE]; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_civoid hmdfs_message_verify_init(void) 228c2ecf20Sopenharmony_ci{ 238c2ecf20Sopenharmony_ci int flag, cmd; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci for (cmd = 0; cmd < F_SIZE; cmd++) 268c2ecf20Sopenharmony_ci need_response[cmd] = true; 278c2ecf20Sopenharmony_ci need_response[F_RELEASE] = false; 288c2ecf20Sopenharmony_ci need_response[F_CONNECT_REKEY] = false; 298c2ecf20Sopenharmony_ci need_response[F_DROP_PUSH] = false; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci for (flag = 0; flag < C_FLAG_SIZE; flag++) { 328c2ecf20Sopenharmony_ci for (cmd = 0; cmd < F_SIZE; cmd++) { 338c2ecf20Sopenharmony_ci message_length[flag][cmd][HMDFS_MESSAGE_MIN_INDEX] = 1; 348c2ecf20Sopenharmony_ci message_length[flag][cmd][HMDFS_MESSAGE_MAX_INDEX] = 0; 358c2ecf20Sopenharmony_ci message_length[flag][cmd][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 368c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 378c2ecf20Sopenharmony_ci } 388c2ecf20Sopenharmony_ci } 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_OPEN][HMDFS_MESSAGE_MIN_INDEX] = 418c2ecf20Sopenharmony_ci sizeof(struct open_request); 428c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_OPEN][HMDFS_MESSAGE_MAX_INDEX] = 438c2ecf20Sopenharmony_ci sizeof(struct open_request) + PATH_MAX + 1; 448c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_OPEN][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 458c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 468c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_OPEN][HMDFS_MESSAGE_MIN_INDEX] = 0; 478c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_OPEN][HMDFS_MESSAGE_MAX_INDEX] = 488c2ecf20Sopenharmony_ci sizeof(struct open_response); 498c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_OPEN][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 508c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_ATOMIC_OPEN][HMDFS_MESSAGE_MIN_INDEX] = 538c2ecf20Sopenharmony_ci sizeof(struct atomic_open_request); 548c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_ATOMIC_OPEN][HMDFS_MESSAGE_MAX_INDEX] = 558c2ecf20Sopenharmony_ci sizeof(struct atomic_open_request) + PATH_MAX + NAME_MAX + 1; 568c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_ATOMIC_OPEN][HMDFS_MESSAGE_LEN_JUDGE_INDEX] 578c2ecf20Sopenharmony_ci = MESSAGE_LEN_JUDGE_RANGE; 588c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_ATOMIC_OPEN][HMDFS_MESSAGE_MIN_INDEX] = 0; 598c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_ATOMIC_OPEN][HMDFS_MESSAGE_MAX_INDEX] = 608c2ecf20Sopenharmony_ci sizeof(struct atomic_open_response); 618c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_ATOMIC_OPEN][HMDFS_MESSAGE_LEN_JUDGE_INDEX] 628c2ecf20Sopenharmony_ci = MESSAGE_LEN_JUDGE_BIN; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RELEASE][HMDFS_MESSAGE_MIN_INDEX] = 658c2ecf20Sopenharmony_ci sizeof(struct release_request); 668c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RELEASE][HMDFS_MESSAGE_MAX_INDEX] = 678c2ecf20Sopenharmony_ci sizeof(struct release_request); 688c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RELEASE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 698c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_FSYNC][HMDFS_MESSAGE_MIN_INDEX] = 728c2ecf20Sopenharmony_ci sizeof(struct fsync_request); 738c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_FSYNC][HMDFS_MESSAGE_MAX_INDEX] = 748c2ecf20Sopenharmony_ci sizeof(struct fsync_request); 758c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_FSYNC][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 768c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 778c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_FSYNC][HMDFS_MESSAGE_MIN_INDEX] = 0; 788c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_FSYNC][HMDFS_MESSAGE_MAX_INDEX] = 0; 798c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_FSYNC][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 808c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_READPAGE][HMDFS_MESSAGE_MIN_INDEX] = 838c2ecf20Sopenharmony_ci sizeof(struct readpage_request); 848c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_READPAGE][HMDFS_MESSAGE_MAX_INDEX] = 858c2ecf20Sopenharmony_ci sizeof(struct readpage_request); 868c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_READPAGE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 878c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 888c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_READPAGE][HMDFS_MESSAGE_MIN_INDEX] = 0; 898c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_READPAGE][HMDFS_MESSAGE_MAX_INDEX] = 908c2ecf20Sopenharmony_ci HMDFS_PAGE_SIZE; 918c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_READPAGE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 928c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_WRITEPAGE][HMDFS_MESSAGE_MIN_INDEX] = 958c2ecf20Sopenharmony_ci sizeof(struct writepage_request) + HMDFS_PAGE_SIZE; 968c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_WRITEPAGE][HMDFS_MESSAGE_MAX_INDEX] = 978c2ecf20Sopenharmony_ci sizeof(struct writepage_request) + HMDFS_PAGE_SIZE; 988c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_WRITEPAGE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 998c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1008c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_WRITEPAGE][HMDFS_MESSAGE_MIN_INDEX] = 0; 1018c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_WRITEPAGE][HMDFS_MESSAGE_MAX_INDEX] = 1028c2ecf20Sopenharmony_ci sizeof(struct writepage_response); 1038c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_WRITEPAGE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1048c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_ITERATE][HMDFS_MESSAGE_MIN_INDEX] = 1078c2ecf20Sopenharmony_ci sizeof(struct readdir_request); 1088c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_ITERATE][HMDFS_MESSAGE_MAX_INDEX] = 1098c2ecf20Sopenharmony_ci sizeof(struct readdir_request) + PATH_MAX + 1; 1108c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_ITERATE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1118c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1128c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_ITERATE][HMDFS_MESSAGE_MIN_INDEX] = 0; 1138c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_ITERATE][HMDFS_MESSAGE_MAX_INDEX] = 1148c2ecf20Sopenharmony_ci sizeof(__le64) + HMDFS_MAX_MESSAGE_LEN; 1158c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_ITERATE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1168c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_MKDIR][HMDFS_MESSAGE_MIN_INDEX] = 1198c2ecf20Sopenharmony_ci sizeof(struct mkdir_request); 1208c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_MKDIR][HMDFS_MESSAGE_MAX_INDEX] = 1218c2ecf20Sopenharmony_ci sizeof(struct mkdir_request) + PATH_MAX + NAME_MAX + 2; 1228c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_MKDIR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1238c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1248c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_MKDIR][HMDFS_MESSAGE_MIN_INDEX] = 1258c2ecf20Sopenharmony_ci sizeof(struct hmdfs_inodeinfo_response); 1268c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_MKDIR][HMDFS_MESSAGE_MAX_INDEX] = 1278c2ecf20Sopenharmony_ci sizeof(struct hmdfs_inodeinfo_response); 1288c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_MKDIR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1298c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_CREATE][HMDFS_MESSAGE_MIN_INDEX] = 1328c2ecf20Sopenharmony_ci sizeof(struct create_request); 1338c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_CREATE][HMDFS_MESSAGE_MAX_INDEX] = 1348c2ecf20Sopenharmony_ci sizeof(struct create_request) + PATH_MAX + NAME_MAX + 2; 1358c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_CREATE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1368c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1378c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_CREATE][HMDFS_MESSAGE_MIN_INDEX] = 1388c2ecf20Sopenharmony_ci sizeof(struct hmdfs_inodeinfo_response); 1398c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_CREATE][HMDFS_MESSAGE_MAX_INDEX] = 1408c2ecf20Sopenharmony_ci sizeof(struct hmdfs_inodeinfo_response); 1418c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_CREATE][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1428c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RMDIR][HMDFS_MESSAGE_MIN_INDEX] = 1458c2ecf20Sopenharmony_ci sizeof(struct rmdir_request); 1468c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RMDIR][HMDFS_MESSAGE_MAX_INDEX] = 1478c2ecf20Sopenharmony_ci sizeof(struct rmdir_request) + PATH_MAX + NAME_MAX + 2; 1488c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RMDIR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1498c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1508c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_RMDIR][HMDFS_MESSAGE_MIN_INDEX] = 0; 1518c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_RMDIR][HMDFS_MESSAGE_MAX_INDEX] = 0; 1528c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_RMDIR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1538c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_UNLINK][HMDFS_MESSAGE_MIN_INDEX] = 1568c2ecf20Sopenharmony_ci sizeof(struct unlink_request); 1578c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_UNLINK][HMDFS_MESSAGE_MAX_INDEX] = 1588c2ecf20Sopenharmony_ci sizeof(struct unlink_request) + PATH_MAX + NAME_MAX + 2; 1598c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_UNLINK][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1608c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1618c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_UNLINK][HMDFS_MESSAGE_MIN_INDEX] = 0; 1628c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_UNLINK][HMDFS_MESSAGE_MAX_INDEX] = 0; 1638c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_UNLINK][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1648c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RENAME][HMDFS_MESSAGE_MIN_INDEX] = 1678c2ecf20Sopenharmony_ci sizeof(struct rename_request); 1688c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RENAME][HMDFS_MESSAGE_MAX_INDEX] = 1698c2ecf20Sopenharmony_ci sizeof(struct rename_request) + 4 + 4 * PATH_MAX; 1708c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_RENAME][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1718c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1728c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_RENAME][HMDFS_MESSAGE_MIN_INDEX] = 0; 1738c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_RENAME][HMDFS_MESSAGE_MAX_INDEX] = 0; 1748c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_RENAME][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1758c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SETATTR][HMDFS_MESSAGE_MIN_INDEX] = 1788c2ecf20Sopenharmony_ci sizeof(struct setattr_request); 1798c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SETATTR][HMDFS_MESSAGE_MAX_INDEX] = 1808c2ecf20Sopenharmony_ci sizeof(struct setattr_request) + PATH_MAX + 1; 1818c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SETATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1828c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1838c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SETATTR][HMDFS_MESSAGE_MIN_INDEX] = 0; 1848c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SETATTR][HMDFS_MESSAGE_MAX_INDEX] = 0; 1858c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SETATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1868c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_GETATTR][HMDFS_MESSAGE_MIN_INDEX] = 1898c2ecf20Sopenharmony_ci sizeof(struct getattr_request); 1908c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_GETATTR][HMDFS_MESSAGE_MAX_INDEX] = 1918c2ecf20Sopenharmony_ci sizeof(struct getattr_request) + PATH_MAX + 1; 1928c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_GETATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1938c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 1948c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_GETATTR][HMDFS_MESSAGE_MIN_INDEX] = 0; 1958c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_GETATTR][HMDFS_MESSAGE_MAX_INDEX] = 1968c2ecf20Sopenharmony_ci sizeof(struct getattr_response); 1978c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_GETATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 1988c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_STATFS][HMDFS_MESSAGE_MIN_INDEX] = 2018c2ecf20Sopenharmony_ci sizeof(struct statfs_request); 2028c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_STATFS][HMDFS_MESSAGE_MAX_INDEX] = 2038c2ecf20Sopenharmony_ci sizeof(struct statfs_request) + PATH_MAX + 1; 2048c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_STATFS][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2058c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 2068c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_STATFS][HMDFS_MESSAGE_MIN_INDEX] = 0; 2078c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_STATFS][HMDFS_MESSAGE_MAX_INDEX] = 2088c2ecf20Sopenharmony_ci sizeof(struct statfs_response); 2098c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_STATFS][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2108c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SYNCFS][HMDFS_MESSAGE_MIN_INDEX] = 2138c2ecf20Sopenharmony_ci sizeof(struct syncfs_request); 2148c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SYNCFS][HMDFS_MESSAGE_MAX_INDEX] = 2158c2ecf20Sopenharmony_ci sizeof(struct syncfs_request); 2168c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SYNCFS][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2178c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 2188c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SYNCFS][HMDFS_MESSAGE_MIN_INDEX] = 0; 2198c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SYNCFS][HMDFS_MESSAGE_MAX_INDEX] = 0; 2208c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SYNCFS][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2218c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_GETXATTR][HMDFS_MESSAGE_MIN_INDEX] = 2248c2ecf20Sopenharmony_ci sizeof(struct getxattr_request); 2258c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_GETXATTR][HMDFS_MESSAGE_MAX_INDEX] = 2268c2ecf20Sopenharmony_ci sizeof(struct getxattr_request) + PATH_MAX + XATTR_NAME_MAX + 2; 2278c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_GETXATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2288c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 2298c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_GETXATTR][HMDFS_MESSAGE_MIN_INDEX] = 0; 2308c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_GETXATTR][HMDFS_MESSAGE_MAX_INDEX] = 2318c2ecf20Sopenharmony_ci sizeof(struct getxattr_response) + HMDFS_XATTR_SIZE_MAX; 2328c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_GETXATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2338c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SETXATTR][HMDFS_MESSAGE_MIN_INDEX] = 2368c2ecf20Sopenharmony_ci sizeof(struct setxattr_request); 2378c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SETXATTR][HMDFS_MESSAGE_MAX_INDEX] = 2388c2ecf20Sopenharmony_ci sizeof(struct setxattr_request) + PATH_MAX + XATTR_NAME_MAX + 2398c2ecf20Sopenharmony_ci HMDFS_XATTR_SIZE_MAX + 2; 2408c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_SETXATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2418c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 2428c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SETXATTR][HMDFS_MESSAGE_MIN_INDEX] = 0; 2438c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SETXATTR][HMDFS_MESSAGE_MAX_INDEX] = 0; 2448c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_SETXATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2458c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_BIN; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_LISTXATTR][HMDFS_MESSAGE_MIN_INDEX] = 2488c2ecf20Sopenharmony_ci sizeof(struct listxattr_request); 2498c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_LISTXATTR][HMDFS_MESSAGE_MAX_INDEX] = 2508c2ecf20Sopenharmony_ci sizeof(struct listxattr_request) + PATH_MAX + 1; 2518c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_LISTXATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2528c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 2538c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_LISTXATTR][HMDFS_MESSAGE_MIN_INDEX] = 0; 2548c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_LISTXATTR][HMDFS_MESSAGE_MAX_INDEX] = 2558c2ecf20Sopenharmony_ci sizeof(struct listxattr_response) + HMDFS_LISTXATTR_SIZE_MAX; 2568c2ecf20Sopenharmony_ci message_length[C_RESPONSE][F_LISTXATTR][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2578c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_CONNECT_REKEY][HMDFS_MESSAGE_MIN_INDEX] = 2608c2ecf20Sopenharmony_ci sizeof(struct connection_rekey_request); 2618c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_CONNECT_REKEY][HMDFS_MESSAGE_MAX_INDEX] = 2628c2ecf20Sopenharmony_ci sizeof(struct connection_rekey_request); 2638c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_CONNECT_REKEY] 2648c2ecf20Sopenharmony_ci [HMDFS_MESSAGE_LEN_JUDGE_INDEX] = MESSAGE_LEN_JUDGE_BIN; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_DROP_PUSH][HMDFS_MESSAGE_MIN_INDEX] = 2678c2ecf20Sopenharmony_ci sizeof(struct drop_push_request); 2688c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_DROP_PUSH][HMDFS_MESSAGE_MAX_INDEX] = 2698c2ecf20Sopenharmony_ci sizeof(struct drop_push_request) + PATH_MAX + 1; 2708c2ecf20Sopenharmony_ci message_length[C_REQUEST][F_DROP_PUSH][HMDFS_MESSAGE_LEN_JUDGE_INDEX] = 2718c2ecf20Sopenharmony_ci MESSAGE_LEN_JUDGE_RANGE; 2728c2ecf20Sopenharmony_ci} 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_cistatic int is_str_msg_valid(char *msg, int str_len[], size_t str_num) 2758c2ecf20Sopenharmony_ci{ 2768c2ecf20Sopenharmony_ci int i = 0; 2778c2ecf20Sopenharmony_ci int pos = 0; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci for (i = 0; i < str_num; i++) { 2808c2ecf20Sopenharmony_ci if (msg[pos + str_len[i]] != '\0' || 2818c2ecf20Sopenharmony_ci strnlen(msg + pos, PATH_MAX) != str_len[i]) 2828c2ecf20Sopenharmony_ci return -EINVAL; 2838c2ecf20Sopenharmony_ci pos += str_len[i] + 1; 2848c2ecf20Sopenharmony_ci } 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci return 0; 2878c2ecf20Sopenharmony_ci} 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_cistatic int verify_open_req(size_t msg_len, void *msg) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci struct open_request *req = msg; 2928c2ecf20Sopenharmony_ci int str_len[] = { req->path_len }; 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX) 2958c2ecf20Sopenharmony_ci return -EINVAL; 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1) 2988c2ecf20Sopenharmony_ci return -EINVAL; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci str_len[0] = req->path_len; 3018c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->buf, str_len, sizeof(str_len) / sizeof(int))) 3028c2ecf20Sopenharmony_ci return -EINVAL; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci return 0; 3058c2ecf20Sopenharmony_ci} 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_cistatic int verify_open_resp(size_t msg_len, void *msg) 3088c2ecf20Sopenharmony_ci{ 3098c2ecf20Sopenharmony_ci struct open_response *resp = msg; 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci if (msg_len != sizeof(*resp)) 3128c2ecf20Sopenharmony_ci return -EINVAL; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci return 0; 3158c2ecf20Sopenharmony_ci} 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_cistatic int hmdfs_open_verify(int flag, size_t msg_len, void *msg) 3188c2ecf20Sopenharmony_ci{ 3198c2ecf20Sopenharmony_ci if (!msg || !msg_len) 3208c2ecf20Sopenharmony_ci return 0; 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 3238c2ecf20Sopenharmony_ci return verify_open_req(msg_len, msg); 3248c2ecf20Sopenharmony_ci else 3258c2ecf20Sopenharmony_ci return verify_open_resp(msg_len, msg); 3268c2ecf20Sopenharmony_ci} 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistatic int verify_atomic_open_req(size_t msg_len, void *msg) 3298c2ecf20Sopenharmony_ci{ 3308c2ecf20Sopenharmony_ci struct atomic_open_request *req = msg; 3318c2ecf20Sopenharmony_ci int str_len[] = { req->path_len, req->file_len}; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX || 3348c2ecf20Sopenharmony_ci req->file_len < 0 || req->file_len >= PATH_MAX) 3358c2ecf20Sopenharmony_ci return -EINVAL; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1 + req->file_len + 1) 3388c2ecf20Sopenharmony_ci return -EINVAL; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->buf, str_len, sizeof(str_len) / sizeof(int))) 3418c2ecf20Sopenharmony_ci return -EINVAL; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci return 0; 3448c2ecf20Sopenharmony_ci} 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_cistatic int verify_atomic_open_resp(size_t msg_len, void *msg) 3478c2ecf20Sopenharmony_ci{ 3488c2ecf20Sopenharmony_ci struct atomic_open_response *resp = msg; 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci if (msg_len != sizeof(*resp)) 3518c2ecf20Sopenharmony_ci return -EINVAL; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci return 0; 3548c2ecf20Sopenharmony_ci} 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_cistatic int hmdfs_atomic_open_verify(int flag, size_t msg_len, void *msg) 3578c2ecf20Sopenharmony_ci{ 3588c2ecf20Sopenharmony_ci if (!msg || !msg_len) 3598c2ecf20Sopenharmony_ci return 0; 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 3628c2ecf20Sopenharmony_ci return verify_atomic_open_req(msg_len, msg); 3638c2ecf20Sopenharmony_ci else 3648c2ecf20Sopenharmony_ci return verify_atomic_open_resp(msg_len, msg); 3658c2ecf20Sopenharmony_ci} 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_cistatic int verify_iterate_req(size_t msg_len, void *msg) 3688c2ecf20Sopenharmony_ci{ 3698c2ecf20Sopenharmony_ci struct readdir_request *req = msg; 3708c2ecf20Sopenharmony_ci int str_len[] = { req->path_len }; 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX) 3738c2ecf20Sopenharmony_ci return -EINVAL; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1) 3768c2ecf20Sopenharmony_ci return -EINVAL; 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->path, str_len, sizeof(str_len) / sizeof(int))) 3798c2ecf20Sopenharmony_ci return -EINVAL; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci return 0; 3828c2ecf20Sopenharmony_ci} 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistatic int hmdfs_iterate_verify(int flag, size_t msg_len, void *msg) 3858c2ecf20Sopenharmony_ci{ 3868c2ecf20Sopenharmony_ci if (!msg || !msg_len) 3878c2ecf20Sopenharmony_ci return 0; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 3908c2ecf20Sopenharmony_ci return verify_iterate_req(msg_len, msg); 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci return 0; 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_cistatic int verify_mkdir_req(size_t msg_len, void *msg) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci struct mkdir_request *req = msg; 3988c2ecf20Sopenharmony_ci int str_len[] = { req->path_len, req->name_len }; 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX || 4018c2ecf20Sopenharmony_ci req->name_len < 0 || req->name_len >= PATH_MAX) 4028c2ecf20Sopenharmony_ci return -EINVAL; 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1 + req->name_len + 1) 4058c2ecf20Sopenharmony_ci return -EINVAL; 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->path, str_len, sizeof(str_len) / sizeof(int))) 4088c2ecf20Sopenharmony_ci return -EINVAL; 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci return 0; 4118c2ecf20Sopenharmony_ci} 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_cistatic int verify_mkdir_resp(size_t msg_len, void *msg) 4148c2ecf20Sopenharmony_ci{ 4158c2ecf20Sopenharmony_ci struct hmdfs_inodeinfo_response *resp = msg; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci if (msg_len != sizeof(*resp)) 4188c2ecf20Sopenharmony_ci return -EINVAL; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci return 0; 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_cistatic int hmdfs_mkdir_verify(int flag, size_t msg_len, void *msg) 4248c2ecf20Sopenharmony_ci{ 4258c2ecf20Sopenharmony_ci if (!msg || !msg_len) 4268c2ecf20Sopenharmony_ci return 0; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 4298c2ecf20Sopenharmony_ci return verify_mkdir_req(msg_len, msg); 4308c2ecf20Sopenharmony_ci else 4318c2ecf20Sopenharmony_ci return verify_mkdir_resp(msg_len, msg); 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_cistatic int verify_create_req(size_t msg_len, void *msg) 4358c2ecf20Sopenharmony_ci{ 4368c2ecf20Sopenharmony_ci struct create_request *req = msg; 4378c2ecf20Sopenharmony_ci int str_len[] = { req->path_len, req->name_len }; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX || 4408c2ecf20Sopenharmony_ci req->name_len < 0 || req->name_len >= PATH_MAX) 4418c2ecf20Sopenharmony_ci return -EINVAL; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1 + req->name_len + 1) 4448c2ecf20Sopenharmony_ci return -EINVAL; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->path, str_len, sizeof(str_len) / sizeof(int))) 4478c2ecf20Sopenharmony_ci return -EINVAL; 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci return 0; 4508c2ecf20Sopenharmony_ci} 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_cistatic int verify_create_resp(size_t msg_len, void *msg) 4538c2ecf20Sopenharmony_ci{ 4548c2ecf20Sopenharmony_ci struct hmdfs_inodeinfo_response *resp = msg; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci if (msg_len != sizeof(*resp)) 4578c2ecf20Sopenharmony_ci return -EINVAL; 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci return 0; 4608c2ecf20Sopenharmony_ci} 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_cistatic int hmdfs_create_verify(int flag, size_t msg_len, void *msg) 4638c2ecf20Sopenharmony_ci{ 4648c2ecf20Sopenharmony_ci if (!msg || !msg_len) 4658c2ecf20Sopenharmony_ci return 0; 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 4688c2ecf20Sopenharmony_ci return verify_create_req(msg_len, msg); 4698c2ecf20Sopenharmony_ci else 4708c2ecf20Sopenharmony_ci return verify_create_resp(msg_len, msg); 4718c2ecf20Sopenharmony_ci} 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_cistatic int verify_rmdir_req(size_t msg_len, void *msg) 4748c2ecf20Sopenharmony_ci{ 4758c2ecf20Sopenharmony_ci struct rmdir_request *req = msg; 4768c2ecf20Sopenharmony_ci int str_len[] = { req->path_len, req->name_len }; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX || 4798c2ecf20Sopenharmony_ci req->name_len < 0 || req->name_len >= PATH_MAX) 4808c2ecf20Sopenharmony_ci return -EINVAL; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1 + req->name_len + 1) 4838c2ecf20Sopenharmony_ci return -EINVAL; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->path, str_len, sizeof(str_len) / sizeof(int))) 4868c2ecf20Sopenharmony_ci return -EINVAL; 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci return 0; 4898c2ecf20Sopenharmony_ci} 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_cistatic int hmdfs_rmdir_verify(int flag, size_t msg_len, void *msg) 4928c2ecf20Sopenharmony_ci{ 4938c2ecf20Sopenharmony_ci if (!msg || !msg_len) 4948c2ecf20Sopenharmony_ci return 0; 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 4978c2ecf20Sopenharmony_ci return verify_rmdir_req(msg_len, msg); 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci return 0; 5008c2ecf20Sopenharmony_ci} 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_cistatic int verify_unlink_req(size_t msg_len, void *msg) 5038c2ecf20Sopenharmony_ci{ 5048c2ecf20Sopenharmony_ci struct unlink_request *req = msg; 5058c2ecf20Sopenharmony_ci int str_len[] = { req->path_len, req->name_len }; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX || 5088c2ecf20Sopenharmony_ci req->name_len < 0 || req->name_len >= PATH_MAX) 5098c2ecf20Sopenharmony_ci return -EINVAL; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1 + req->name_len + 1) 5128c2ecf20Sopenharmony_ci return -EINVAL; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->path, str_len, sizeof(str_len) / sizeof(int))) 5158c2ecf20Sopenharmony_ci return -EINVAL; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci return 0; 5188c2ecf20Sopenharmony_ci} 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_cistatic int hmdfs_unlink_verify(int flag, size_t msg_len, void *msg) 5218c2ecf20Sopenharmony_ci{ 5228c2ecf20Sopenharmony_ci if (!msg || !msg_len) 5238c2ecf20Sopenharmony_ci return 0; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 5268c2ecf20Sopenharmony_ci return verify_unlink_req(msg_len, msg); 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci return 0; 5298c2ecf20Sopenharmony_ci} 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_cistatic int verify_rename_req(size_t msg_len, void *msg) 5328c2ecf20Sopenharmony_ci{ 5338c2ecf20Sopenharmony_ci struct rename_request *req = msg; 5348c2ecf20Sopenharmony_ci int str_len[] = { req->old_path_len, req->new_path_len, 5358c2ecf20Sopenharmony_ci req->old_name_len, req->new_name_len }; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci if (req->old_path_len < 0 || req->old_path_len >= PATH_MAX || 5388c2ecf20Sopenharmony_ci req->new_path_len < 0 || req->new_path_len >= PATH_MAX || 5398c2ecf20Sopenharmony_ci req->old_name_len < 0 || req->old_name_len >= PATH_MAX || 5408c2ecf20Sopenharmony_ci req->new_name_len < 0 || req->new_name_len >= PATH_MAX) 5418c2ecf20Sopenharmony_ci return -EINVAL; 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->old_path_len + 1 + 5448c2ecf20Sopenharmony_ci req->new_path_len + 1 + req->old_name_len + 1 + 5458c2ecf20Sopenharmony_ci req->new_name_len + 1) 5468c2ecf20Sopenharmony_ci return -EINVAL; 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->path, str_len, sizeof(str_len) / sizeof(int))) 5498c2ecf20Sopenharmony_ci return -EINVAL; 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci return 0; 5528c2ecf20Sopenharmony_ci} 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_cistatic int hmdfs_rename_verify(int flag, size_t msg_len, void *msg) 5558c2ecf20Sopenharmony_ci{ 5568c2ecf20Sopenharmony_ci if (!msg || !msg_len) 5578c2ecf20Sopenharmony_ci return 0; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 5608c2ecf20Sopenharmony_ci return verify_rename_req(msg_len, msg); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci return 0; 5638c2ecf20Sopenharmony_ci} 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_cistatic int verify_setattr_req(size_t msg_len, void *msg) 5668c2ecf20Sopenharmony_ci{ 5678c2ecf20Sopenharmony_ci struct setattr_request *req = msg; 5688c2ecf20Sopenharmony_ci int str_len[] = { req->path_len }; 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci req = msg; 5718c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX) 5728c2ecf20Sopenharmony_ci return -EINVAL; 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1) 5758c2ecf20Sopenharmony_ci return -EINVAL; 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->buf, str_len, sizeof(str_len) / sizeof(int))) 5788c2ecf20Sopenharmony_ci return -EINVAL; 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci return 0; 5818c2ecf20Sopenharmony_ci} 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_cistatic int hmdfs_setattr_verify(int flag, size_t msg_len, void *msg) 5848c2ecf20Sopenharmony_ci{ 5858c2ecf20Sopenharmony_ci if (!msg || !msg_len) 5868c2ecf20Sopenharmony_ci return 0; 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 5898c2ecf20Sopenharmony_ci return verify_setattr_req(msg_len, msg); 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci return 0; 5928c2ecf20Sopenharmony_ci} 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_cistatic int verify_getattr_req(size_t msg_len, void *msg) 5958c2ecf20Sopenharmony_ci{ 5968c2ecf20Sopenharmony_ci struct getattr_request *req = msg; 5978c2ecf20Sopenharmony_ci int str_len[] = { req->path_len }; 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX) 6008c2ecf20Sopenharmony_ci return -EINVAL; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1) 6038c2ecf20Sopenharmony_ci return -EINVAL; 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->buf, str_len, sizeof(str_len) / sizeof(int))) 6068c2ecf20Sopenharmony_ci return -EINVAL; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci return 0; 6098c2ecf20Sopenharmony_ci} 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_cistatic int verify_getattr_resp(size_t msg_len, void *msg) 6128c2ecf20Sopenharmony_ci{ 6138c2ecf20Sopenharmony_ci struct getattr_response *resp = msg; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci if (msg_len != sizeof(*resp)) 6168c2ecf20Sopenharmony_ci return -EINVAL; 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci return 0; 6198c2ecf20Sopenharmony_ci} 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_cistatic int hmdfs_getattr_verify(int flag, size_t msg_len, void *msg) 6228c2ecf20Sopenharmony_ci{ 6238c2ecf20Sopenharmony_ci if (!msg || !msg_len) 6248c2ecf20Sopenharmony_ci return 0; 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 6278c2ecf20Sopenharmony_ci return verify_getattr_req(msg_len, msg); 6288c2ecf20Sopenharmony_ci else 6298c2ecf20Sopenharmony_ci return verify_getattr_resp(msg_len, msg); 6308c2ecf20Sopenharmony_ci} 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_cistatic int verify_getxattr_req(size_t msg_len, void *msg) 6338c2ecf20Sopenharmony_ci{ 6348c2ecf20Sopenharmony_ci struct getxattr_request *req = msg; 6358c2ecf20Sopenharmony_ci int str_len[] = { req->path_len, req->name_len}; 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX || 6388c2ecf20Sopenharmony_ci req->name_len < 0 || req->name_len >= PATH_MAX) 6398c2ecf20Sopenharmony_ci return -EINVAL; 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1 + req->name_len + 1) 6428c2ecf20Sopenharmony_ci return -EINVAL; 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci if (req->name_len > XATTR_NAME_MAX || req->size < 0 || 6458c2ecf20Sopenharmony_ci req->size > XATTR_SIZE_MAX) 6468c2ecf20Sopenharmony_ci return -EINVAL; 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->buf, str_len, sizeof(str_len) / sizeof(int))) 6498c2ecf20Sopenharmony_ci return -EINVAL; 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci return 0; 6528c2ecf20Sopenharmony_ci} 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_cistatic int verify_getxattr_resp(size_t msg_len, void *msg) 6558c2ecf20Sopenharmony_ci{ 6568c2ecf20Sopenharmony_ci struct getxattr_response *resp = msg; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci if (resp->size != sizeof(*resp->value)) 6598c2ecf20Sopenharmony_ci return -EINVAL; 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci if (msg_len < sizeof(*resp)) 6628c2ecf20Sopenharmony_ci return -EINVAL; 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci if (resp->size > XATTR_SIZE_MAX) 6658c2ecf20Sopenharmony_ci return -EINVAL; 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci return 0; 6688c2ecf20Sopenharmony_ci} 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_cistatic int hmdfs_getxattr_verify(int flag, size_t msg_len, void *msg) 6718c2ecf20Sopenharmony_ci{ 6728c2ecf20Sopenharmony_ci if (!msg || !msg_len) 6738c2ecf20Sopenharmony_ci return 0; 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 6768c2ecf20Sopenharmony_ci return verify_getxattr_req(msg_len, msg); 6778c2ecf20Sopenharmony_ci else 6788c2ecf20Sopenharmony_ci return verify_getxattr_resp(msg_len, msg); 6798c2ecf20Sopenharmony_ci} 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_cistatic int verify_setxattr_req(size_t msg_len, void *msg) 6828c2ecf20Sopenharmony_ci{ 6838c2ecf20Sopenharmony_ci struct setxattr_request *req = msg; 6848c2ecf20Sopenharmony_ci int str_len[] = { req->path_len, req->name_len}; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX || 6878c2ecf20Sopenharmony_ci req->name_len < 0 || req->name_len >= PATH_MAX) 6888c2ecf20Sopenharmony_ci return -EINVAL; 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1 + req->name_len + 1 + 6918c2ecf20Sopenharmony_ci req->size) 6928c2ecf20Sopenharmony_ci return -EINVAL; 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci if (req->name_len > XATTR_NAME_MAX || req->size < 0 || 6958c2ecf20Sopenharmony_ci req->size > XATTR_SIZE_MAX) 6968c2ecf20Sopenharmony_ci return -EINVAL; 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->buf, str_len, sizeof(str_len) / sizeof(int))) 6998c2ecf20Sopenharmony_ci return -EINVAL; 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci return 0; 7028c2ecf20Sopenharmony_ci} 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_cistatic int hmdfs_setxattr_verify(int flag, size_t msg_len, void *msg) 7058c2ecf20Sopenharmony_ci{ 7068c2ecf20Sopenharmony_ci if (!msg || !msg_len) 7078c2ecf20Sopenharmony_ci return 0; 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 7108c2ecf20Sopenharmony_ci return verify_setxattr_req(msg_len, msg); 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci return 0; 7138c2ecf20Sopenharmony_ci} 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_cistatic int verify_listxattr_req(size_t msg_len, void *msg) 7168c2ecf20Sopenharmony_ci{ 7178c2ecf20Sopenharmony_ci struct listxattr_request *req = msg; 7188c2ecf20Sopenharmony_ci int str_len[] = { req->path_len }; 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX) 7218c2ecf20Sopenharmony_ci return -EINVAL; 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1) 7248c2ecf20Sopenharmony_ci return -EINVAL; 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci if (req->size < 0 || req->size > XATTR_LIST_MAX) 7278c2ecf20Sopenharmony_ci return -EINVAL; 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->buf, str_len, sizeof(str_len) / sizeof(int))) 7308c2ecf20Sopenharmony_ci return -EINVAL; 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci return 0; 7338c2ecf20Sopenharmony_ci} 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_cistatic int verify_listxattr_resp(size_t msg_len, void *msg) 7368c2ecf20Sopenharmony_ci{ 7378c2ecf20Sopenharmony_ci struct listxattr_response *resp = msg; 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci if (resp->size != sizeof(*resp->list)) 7408c2ecf20Sopenharmony_ci return -EINVAL; 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci if (msg_len < sizeof(*resp)) 7438c2ecf20Sopenharmony_ci return -EINVAL; 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci if (resp->size > XATTR_LIST_MAX) 7468c2ecf20Sopenharmony_ci return -EINVAL; 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci return 0; 7498c2ecf20Sopenharmony_ci} 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_cistatic int hmdfs_listxattr_verify(int flag, size_t msg_len, void *msg) 7528c2ecf20Sopenharmony_ci{ 7538c2ecf20Sopenharmony_ci if (!msg || !msg_len) 7548c2ecf20Sopenharmony_ci return 0; 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 7578c2ecf20Sopenharmony_ci return verify_listxattr_req(msg_len, msg); 7588c2ecf20Sopenharmony_ci else 7598c2ecf20Sopenharmony_ci return verify_listxattr_resp(msg_len, msg); 7608c2ecf20Sopenharmony_ci} 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_cistatic int hmdfs_readpage_verify(int flag, size_t msg_len, void *msg) 7638c2ecf20Sopenharmony_ci{ 7648c2ecf20Sopenharmony_ci struct readpage_request *req = NULL; 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci if (flag != C_REQUEST || !msg || !msg_len) 7678c2ecf20Sopenharmony_ci return 0; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci req = msg; 7708c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req)) 7718c2ecf20Sopenharmony_ci return -EINVAL; 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ci return 0; 7748c2ecf20Sopenharmony_ci} 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_cistatic int hmdfs_writepage_verify(int flag, size_t msg_len, void *msg) 7778c2ecf20Sopenharmony_ci{ 7788c2ecf20Sopenharmony_ci struct writepage_request *req = NULL; 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_ci if (flag != C_REQUEST || !msg || !msg_len) 7818c2ecf20Sopenharmony_ci return 0; 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci req = msg; 7848c2ecf20Sopenharmony_ci if (req->count <= 0 || req->count > HMDFS_PAGE_SIZE) 7858c2ecf20Sopenharmony_ci return -EINVAL; 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + HMDFS_PAGE_SIZE) 7888c2ecf20Sopenharmony_ci return -EINVAL; 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_ci return 0; 7918c2ecf20Sopenharmony_ci} 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_cistatic int verify_statfs_req(size_t msg_len, void *msg) 7948c2ecf20Sopenharmony_ci{ 7958c2ecf20Sopenharmony_ci struct statfs_request *req = msg; 7968c2ecf20Sopenharmony_ci int str_len[] = { req->path_len }; 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX) 7998c2ecf20Sopenharmony_ci return -EINVAL; 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1) 8028c2ecf20Sopenharmony_ci return -EINVAL; 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->path, str_len, sizeof(str_len) / sizeof(int))) 8058c2ecf20Sopenharmony_ci return -EINVAL; 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci return 0; 8088c2ecf20Sopenharmony_ci} 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_cistatic int verify_statfs_resp(size_t msg_len, void *msg) 8118c2ecf20Sopenharmony_ci{ 8128c2ecf20Sopenharmony_ci struct statfs_response *resp = msg; 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci if (msg_len != sizeof(*resp)) 8158c2ecf20Sopenharmony_ci return -EINVAL; 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci return 0; 8188c2ecf20Sopenharmony_ci} 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_cistatic int hmdfs_statfs_verify(int flag, size_t msg_len, void *msg) 8218c2ecf20Sopenharmony_ci{ 8228c2ecf20Sopenharmony_ci if (!msg || !msg_len) 8238c2ecf20Sopenharmony_ci return 0; 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 8268c2ecf20Sopenharmony_ci return verify_statfs_req(msg_len, msg); 8278c2ecf20Sopenharmony_ci else 8288c2ecf20Sopenharmony_ci return verify_statfs_resp(msg_len, msg); 8298c2ecf20Sopenharmony_ci} 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_cistatic int verify_drop_push_req(size_t msg_len, void *msg) 8328c2ecf20Sopenharmony_ci{ 8338c2ecf20Sopenharmony_ci struct drop_push_request *req = msg; 8348c2ecf20Sopenharmony_ci int str_len[] = { req->path_len }; 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_ci if (req->path_len < 0 || req->path_len >= PATH_MAX) 8378c2ecf20Sopenharmony_ci return -EINVAL; 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_ci if (msg_len != sizeof(*req) + req->path_len + 1) 8408c2ecf20Sopenharmony_ci return -EINVAL; 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci if (is_str_msg_valid(req->path, str_len, sizeof(str_len) / sizeof(int))) 8438c2ecf20Sopenharmony_ci return -EINVAL; 8448c2ecf20Sopenharmony_ci 8458c2ecf20Sopenharmony_ci return 0; 8468c2ecf20Sopenharmony_ci} 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_cistatic int hmdfs_drop_push_verify(int flag, size_t msg_len, void *msg) 8498c2ecf20Sopenharmony_ci{ 8508c2ecf20Sopenharmony_ci if (!msg || !msg_len) 8518c2ecf20Sopenharmony_ci return 0; 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_ci if (flag == C_REQUEST) 8548c2ecf20Sopenharmony_ci return verify_drop_push_req(msg_len, msg); 8558c2ecf20Sopenharmony_ci 8568c2ecf20Sopenharmony_ci return 0; 8578c2ecf20Sopenharmony_ci} 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_citypedef int (*hmdfs_message_verify_func)(int, size_t, void *); 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_cistatic const hmdfs_message_verify_func message_verify[F_SIZE] = { 8628c2ecf20Sopenharmony_ci [F_OPEN] = hmdfs_open_verify, 8638c2ecf20Sopenharmony_ci [F_READPAGE] = hmdfs_readpage_verify, 8648c2ecf20Sopenharmony_ci [F_WRITEPAGE] = hmdfs_writepage_verify, 8658c2ecf20Sopenharmony_ci [F_ITERATE] = hmdfs_iterate_verify, 8668c2ecf20Sopenharmony_ci [F_MKDIR] = hmdfs_mkdir_verify, 8678c2ecf20Sopenharmony_ci [F_RMDIR] = hmdfs_rmdir_verify, 8688c2ecf20Sopenharmony_ci [F_CREATE] = hmdfs_create_verify, 8698c2ecf20Sopenharmony_ci [F_UNLINK] = hmdfs_unlink_verify, 8708c2ecf20Sopenharmony_ci [F_RENAME] = hmdfs_rename_verify, 8718c2ecf20Sopenharmony_ci [F_SETATTR] = hmdfs_setattr_verify, 8728c2ecf20Sopenharmony_ci [F_STATFS] = hmdfs_statfs_verify, 8738c2ecf20Sopenharmony_ci [F_DROP_PUSH] = hmdfs_drop_push_verify, 8748c2ecf20Sopenharmony_ci [F_GETATTR] = hmdfs_getattr_verify, 8758c2ecf20Sopenharmony_ci [F_GETXATTR] = hmdfs_getxattr_verify, 8768c2ecf20Sopenharmony_ci [F_SETXATTR] = hmdfs_setxattr_verify, 8778c2ecf20Sopenharmony_ci [F_LISTXATTR] = hmdfs_listxattr_verify, 8788c2ecf20Sopenharmony_ci [F_ATOMIC_OPEN] = hmdfs_atomic_open_verify, 8798c2ecf20Sopenharmony_ci}; 8808c2ecf20Sopenharmony_ci 8818c2ecf20Sopenharmony_cistatic void handle_bad_message(struct hmdfs_peer *con, 8828c2ecf20Sopenharmony_ci struct hmdfs_head_cmd *head, int *err) 8838c2ecf20Sopenharmony_ci{ 8848c2ecf20Sopenharmony_ci /* 8858c2ecf20Sopenharmony_ci * Bad message won't be awared by upper layer, so ETIME is 8868c2ecf20Sopenharmony_ci * always given to upper layer. It is prefer to pass EOPNOTSUPP 8878c2ecf20Sopenharmony_ci * to upper layer when bad message (eg. caused by wrong len) 8888c2ecf20Sopenharmony_ci * received. 8898c2ecf20Sopenharmony_ci */ 8908c2ecf20Sopenharmony_ci if (head->operations.cmd_flag == C_RESPONSE) { 8918c2ecf20Sopenharmony_ci /* 8928c2ecf20Sopenharmony_ci * Change msg ret code. To let upper layer handle 8938c2ecf20Sopenharmony_ci * EOPNOTSUPP, hmdfs_message_verify() should return 8948c2ecf20Sopenharmony_ci * 0, so err code is modified either. 8958c2ecf20Sopenharmony_ci */ 8968c2ecf20Sopenharmony_ci head->ret_code = cpu_to_le32(-EOPNOTSUPP); 8978c2ecf20Sopenharmony_ci *err = 0; 8988c2ecf20Sopenharmony_ci } else { 8998c2ecf20Sopenharmony_ci if (head->operations.command >= F_SIZE) 9008c2ecf20Sopenharmony_ci return; 9018c2ecf20Sopenharmony_ci /* 9028c2ecf20Sopenharmony_ci * Some request messages do not need to be responded. 9038c2ecf20Sopenharmony_ci * Even if a response is returned, the response msg 9048c2ecf20Sopenharmony_ci * is automatically ignored in hmdfs_response_recv(). 9058c2ecf20Sopenharmony_ci * Therefore, it is normal to directly return a response. 9068c2ecf20Sopenharmony_ci */ 9078c2ecf20Sopenharmony_ci if (need_response[head->operations.command]) 9088c2ecf20Sopenharmony_ci hmdfs_send_err_response(con, head, -EOPNOTSUPP); 9098c2ecf20Sopenharmony_ci } 9108c2ecf20Sopenharmony_ci} 9118c2ecf20Sopenharmony_ci 9128c2ecf20Sopenharmony_cibool is_reserved_command(int command) 9138c2ecf20Sopenharmony_ci{ 9148c2ecf20Sopenharmony_ci if ((command >= F_RESERVED_1 && command <= F_RESERVED_4) || 9158c2ecf20Sopenharmony_ci command == F_RESERVED_5 || command == F_RESERVED_6 || 9168c2ecf20Sopenharmony_ci command == F_RESERVED_7 || command == F_RESERVED_8) 9178c2ecf20Sopenharmony_ci return true; 9188c2ecf20Sopenharmony_ci return false; 9198c2ecf20Sopenharmony_ci} 9208c2ecf20Sopenharmony_ci 9218c2ecf20Sopenharmony_ciint hmdfs_message_verify(struct hmdfs_peer *con, struct hmdfs_head_cmd *head, 9228c2ecf20Sopenharmony_ci void *data) 9238c2ecf20Sopenharmony_ci{ 9248c2ecf20Sopenharmony_ci int err = 0; 9258c2ecf20Sopenharmony_ci int flag, cmd, len_type; 9268c2ecf20Sopenharmony_ci size_t len, min, max; 9278c2ecf20Sopenharmony_ci 9288c2ecf20Sopenharmony_ci if (!head) 9298c2ecf20Sopenharmony_ci return -EINVAL; 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci flag = head->operations.cmd_flag; 9328c2ecf20Sopenharmony_ci if (flag != C_REQUEST && flag != C_RESPONSE) 9338c2ecf20Sopenharmony_ci return -EINVAL; 9348c2ecf20Sopenharmony_ci 9358c2ecf20Sopenharmony_ci cmd = head->operations.command; 9368c2ecf20Sopenharmony_ci if (cmd >= F_SIZE || cmd < F_OPEN || is_reserved_command(cmd)) { 9378c2ecf20Sopenharmony_ci err = -EINVAL; 9388c2ecf20Sopenharmony_ci goto handle_bad_msg; 9398c2ecf20Sopenharmony_ci } 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_ci len = le32_to_cpu(head->data_len) - 9428c2ecf20Sopenharmony_ci sizeof(struct hmdfs_head_cmd); 9438c2ecf20Sopenharmony_ci min = message_length[flag][cmd][HMDFS_MESSAGE_MIN_INDEX]; 9448c2ecf20Sopenharmony_ci if (head->operations.command == F_ITERATE && flag == C_RESPONSE) 9458c2ecf20Sopenharmony_ci max = sizeof(struct slice_descriptor) + PAGE_SIZE; 9468c2ecf20Sopenharmony_ci else 9478c2ecf20Sopenharmony_ci max = message_length[flag][cmd][HMDFS_MESSAGE_MAX_INDEX]; 9488c2ecf20Sopenharmony_ci len_type = 9498c2ecf20Sopenharmony_ci message_length[flag][cmd][HMDFS_MESSAGE_LEN_JUDGE_INDEX]; 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci if (len_type == MESSAGE_LEN_JUDGE_RANGE) { 9528c2ecf20Sopenharmony_ci if (len < min || len > max) { 9538c2ecf20Sopenharmony_ci hmdfs_err( 9548c2ecf20Sopenharmony_ci "cmd %d -> %d message verify fail, len = %zu", 9558c2ecf20Sopenharmony_ci cmd, flag, len); 9568c2ecf20Sopenharmony_ci err = -EINVAL; 9578c2ecf20Sopenharmony_ci goto handle_bad_msg; 9588c2ecf20Sopenharmony_ci } 9598c2ecf20Sopenharmony_ci } else { 9608c2ecf20Sopenharmony_ci if (len != min && len != max) { 9618c2ecf20Sopenharmony_ci hmdfs_err( 9628c2ecf20Sopenharmony_ci "cmd %d -> %d message verify fail, len = %zu", 9638c2ecf20Sopenharmony_ci cmd, flag, len); 9648c2ecf20Sopenharmony_ci err = -EINVAL; 9658c2ecf20Sopenharmony_ci goto handle_bad_msg; 9668c2ecf20Sopenharmony_ci } 9678c2ecf20Sopenharmony_ci } 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci if (message_verify[cmd]) 9708c2ecf20Sopenharmony_ci err = message_verify[cmd](flag, len, data); 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci if (err) 9738c2ecf20Sopenharmony_ci goto handle_bad_msg; 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci return err; 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_cihandle_bad_msg: 9788c2ecf20Sopenharmony_ci handle_bad_message(con, head, &err); 9798c2ecf20Sopenharmony_ci return err; 9808c2ecf20Sopenharmony_ci} 981