History

block: ublk: switch to ioctl command encoding

All ublk commands(control, IO) should have taken ioctl command encoding from the beginning, because ioctl command encoding defines each code uniquely, so driver can figure out wrong command sent from userspace easily; 2) it might help security subsystem for audit uring cmd[1]. Unfortunately we didn't do that way, and it could be one lesson for ublk driver. So switch to ioctl command encoding now, we still support commands encoded in old way, but they become legacy definition. Any new command should take ioctl encoding. See ublksrv code for switching to ioctl command encoding in [2]. [1] https://lore.kernel.org/io-uring/CAHC9VhSVzujW9LOj5Km80AjU0EfAuukoLrxO6BEfnXeK_s6bAg@mail.gmail.com/ [2] https://github.com/ming1/ubdsrv/commits/ioctl_cmd_encoding

Ming Lei committed 3 years ago

Commit 2d786e61 parent 26a42b63 files · +94 −13Browse files

Showing the changes to include/uapi (1 of 3 files). Show all

Unified · Split

include/uapi/linux/ublk_cmd.h+43−0
@@ -8,6 +8,9 @@ · 7 unmodified lines
8 8
9/*9/*
10 * Admin commands, issued by ublk server, and handled by ublk driver.10 * Admin commands, issued by ublk server, and handled by ublk driver.
11 *
12 * Legacy command definition, don't use in new application, and don't
13 * add new such definition any more
11 */14 */
12#define UBLK_CMD_GET_QUEUE_AFFINITY 0x0115#define UBLK_CMD_GET_QUEUE_AFFINITY 0x01
13#define UBLK_CMD_GET_DEV_INFO 0x0216#define UBLK_CMD_GET_DEV_INFO 0x02
@@ -21,6 +24,30 @@ · 7 unmodified lines
21#define UBLK_CMD_END_USER_RECOVERY 0x1124#define UBLK_CMD_END_USER_RECOVERY 0x11
22#define UBLK_CMD_GET_DEV_INFO2 0x1225#define UBLK_CMD_GET_DEV_INFO2 0x12
23 26
27/* Any new ctrl command should encode by __IO*() */
28#define UBLK_U_CMD_GET_QUEUE_AFFINITY \
29 _IOR('u', UBLK_CMD_GET_QUEUE_AFFINITY, struct ublksrv_ctrl_cmd)
30#define UBLK_U_CMD_GET_DEV_INFO \
31 _IOR('u', UBLK_CMD_GET_DEV_INFO, struct ublksrv_ctrl_cmd)
32#define UBLK_U_CMD_ADD_DEV \
33 _IOWR('u', UBLK_CMD_ADD_DEV, struct ublksrv_ctrl_cmd)
34#define UBLK_U_CMD_DEL_DEV \
35 _IOWR('u', UBLK_CMD_DEL_DEV, struct ublksrv_ctrl_cmd)
36#define UBLK_U_CMD_START_DEV \
37 _IOWR('u', UBLK_CMD_START_DEV, struct ublksrv_ctrl_cmd)
38#define UBLK_U_CMD_STOP_DEV \
39 _IOWR('u', UBLK_CMD_STOP_DEV, struct ublksrv_ctrl_cmd)
40#define UBLK_U_CMD_SET_PARAMS \
41 _IOWR('u', UBLK_CMD_SET_PARAMS, struct ublksrv_ctrl_cmd)
42#define UBLK_U_CMD_GET_PARAMS \
43 _IOR('u', UBLK_CMD_GET_PARAMS, struct ublksrv_ctrl_cmd)
44#define UBLK_U_CMD_START_USER_RECOVERY \
45 _IOWR('u', UBLK_CMD_START_USER_RECOVERY, struct ublksrv_ctrl_cmd)
46#define UBLK_U_CMD_END_USER_RECOVERY \
47 _IOWR('u', UBLK_CMD_END_USER_RECOVERY, struct ublksrv_ctrl_cmd)
48#define UBLK_U_CMD_GET_DEV_INFO2 \
49 _IOR('u', UBLK_CMD_GET_DEV_INFO2, struct ublksrv_ctrl_cmd)
50
24/*51/*
25 * IO commands, issued by ublk server, and handled by ublk driver.52 * IO commands, issued by ublk server, and handled by ublk driver.
26 *53 *
@@ -41,10 +68,23 @@ · 14 unmodified lines
41 * It is only used if ublksrv set UBLK_F_NEED_GET_DATA flag68 * It is only used if ublksrv set UBLK_F_NEED_GET_DATA flag
42 * while starting a ublk device.69 * while starting a ublk device.
43 */70 */
71
72/*
73 * Legacy IO command definition, don't use in new application, and don't
74 * add new such definition any more
75 */
44#define UBLK_IO_FETCH_REQ 0x2076#define UBLK_IO_FETCH_REQ 0x20
45#define UBLK_IO_COMMIT_AND_FETCH_REQ 0x2177#define UBLK_IO_COMMIT_AND_FETCH_REQ 0x21
46#define UBLK_IO_NEED_GET_DATA 0x2278#define UBLK_IO_NEED_GET_DATA 0x22
47 79
80/* Any new IO command should encode by __IOWR() */
81#define UBLK_U_IO_FETCH_REQ \
82 _IOWR('u', UBLK_IO_FETCH_REQ, struct ublksrv_io_cmd)
83#define UBLK_U_IO_COMMIT_AND_FETCH_REQ \
84 _IOWR('u', UBLK_IO_COMMIT_AND_FETCH_REQ, struct ublksrv_io_cmd)
85#define UBLK_U_IO_NEED_GET_DATA \
86 _IOWR('u', UBLK_IO_NEED_GET_DATA, struct ublksrv_io_cmd)
87
48/* only ABORT means that no re-fetch */88/* only ABORT means that no re-fetch */
49#define UBLK_IO_RES_OK 089#define UBLK_IO_RES_OK 0
50#define UBLK_IO_RES_NEED_GET_DATA 190#define UBLK_IO_RES_NEED_GET_DATA 1
@@ -102,6 +142,9 @@ · 51 unmodified lines
102 */142 */
103#define UBLK_F_UNPRIVILEGED_DEV (1UL << 5)143#define UBLK_F_UNPRIVILEGED_DEV (1UL << 5)
104 144
145/* use ioctl encoding for uring command */
146#define UBLK_F_CMD_IOCTL_ENCODE (1UL << 6)
147
105/* device state */148/* device state */
106#define UBLK_S_DEV_DEAD 0149#define UBLK_S_DEV_DEAD 0
107#define UBLK_S_DEV_LIVE 1150#define UBLK_S_DEV_LIVE 1

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t