RDMA/netlink: OOPs in rdma_nl_rcv_msg() from misinterpreted flag
PATCH 1/1 RDMA/netlink: OOPs in rdma_nl_rcv_msg() from misinterpreted flag
I was playing with the ibacm service and discovered an issue the other day.
If no provider library is present (I removed libacmp.so, and the provider keyword in the opts.cfg file is libacmp), when a resolve request is posted, the kernel will crash with the following Oops:
BUG: unable to handle kernel NULL pointer dereference at (null) IP: (null) PGD 10543f1067 P4D 10543f1067 PUD 1033f93067 PMD 0 Oops: 0010 [#1] SMP Modules linked in: rpcrdma ib_isert iscsi_target_mod target_core_mod ib_iser libiscsi scsi_transport_iscsi ib_ipoib rdma_ucm ib_u ib_uverbs ib_umad rdma_cm ib_cm iw_cm dm_mirror dm_region_hash dm_log dm_mod dax sb_edac x86_pkg_temp_thermal intel_powerclamp coretemp kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel pcbc aesni_intel crypto_si glue_helper cryptd hfi1 rdmavt iTCO_wdt iTCO_vendor_support ib_core mei_me lpc_ich pcspkr mei ioatdma sg shpchp i2c_i801 mfd_core wmi ipmi_si ipmi_devi ipmi_msghandler acpi_power_meter acpi_pad nfsd auth_rpcgss nfs_acl lockd gra sunrpc ip_tables ext4 mbcache jbd2 sd_mod mgag200 drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops ttm igb ahci crc32c_intel ptp libahci pps_core drm dca libata i2c_algo_bit i2c_core CPU: 54 PID: 9841 Comm: ibacm Tainted: G I 4.14.0-rc2+ #6 Hardware name: Intel Corporation S2600WT2/S2600WT2, BIOS SE5C610.86B.01.01.0008.021120151325 02/11/2015 task: ffff880855f42d00 task.stack: ffffc900246b4000 RIP: 0010: (null) RSP: 0018:ffffc900246b7bc8 EFLAGS: 00010246 RAX: ffffffff81dbe9e0 RBX: ffff881058bb1000 RCX: 0000000000000000 RDX: 0000000000001100 RSI: ffff881058bb1320 RDI: ffff881056362000 RBP: ffffc900246b7bf8 R08: 0000000000000ec0 R09: 0000000000001100 R10: ffff8810573a5000 R11: 0000000000000000 R12: ffff881056362000 R13: 0000000000000ec0 R14: ffff881058bb1320 R15: 0000000000000ec0 FS: 00007fe0ba5a38c0(0000) GS:ffff88105f080000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000001056f5d003 CR4: 00000000001606e0 Call Trace: ? netlink_dump+0x12c/0x290 __netlink_dump_start+0x186/0x1f0 rdma_nl_rcv_msg+0x193/0x1b0 [ib_core] rdma_nl_rcv+0xdc/0x130 [ib_core] netlink_unicast+0x181/0x240 netlink_sendmsg+0x2c2/0x3b0 sock_sendmsg+0x38/0x50 SYSC_sendto+0x102/0x190 ? __audit_syscall_entry+0xaf/0x100 ? syscall_trace_enter+0x1d0/0x2b0 ? __audit_syscall_exit+0x209/0x290 SyS_sendto+0xe/0x10 do_syscall_64+0x67/0x1b0 entry_SYSCALL64_slow_path+0x25/0x25 RIP: 0033:0x7fe0b9db2a63 RSP: 002b:00007ffc55edc260 EFLAGS: 00000293 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 0000000000000010 RCX: 00007fe0b9db2a63 RDX: 0000000000000010 RSI: 00007ffc55edc280 RDI: 000000000000000d RBP: 00007ffc55edc670 R08: 00007ffc55edc270 R09: 000000000000000c R10: 0000000000000000 R11: 0000000000000293 R12: 00007ffc55edc280 R13: 000000000260b400 R14: 000000000000000d R15: 0000000000000001 Code: Bad RIP value. RIP: (null) RSP: ffffc900246b7bc8 CR2: 0000000000000000 ---[ end trace 8d67abcfd10ec209 ]--- Kernel panic - not syncing: Fatal exception Kernel Offset: disabled ---[ end Kernel panic - not syncing: Fatal exception ------------[ cut here ]------------
The issue is that in rdma_nl_rcv_msg(), the check 'if (flags & NLM_F_DUMP)' is not completely correct.
NLM_F_DUMP is two bits NLM_F_ROOT | NLM_F_MATCH.
ibacm sends a RDMA_NL_LS response with the RDMA_NL_LS_F_ERR bit set if an error occurs in the service (like no provider being available, or ACM_STATUS_ENODATA, etc.).
NLM_F_ROOT == (0x100) == RDMA_NL_LS_F_ERR.
The current code thinks that it sees a NLM_F_DUMP flag and incorrectly calls the .dump() callback.
The included patch is an atempt to fix this issue. This patch fixes the issue that I am seeing, but I am not sure how to test the messages for RDMA_NL_RDMA_CM or RDMA_NL_IWCM (or any message that uses the NLM_F_DUMP bits).
If anyone has some knowledge of these services, any extra testing would be welcomed.
If the patch has no issues or comments, I will formally re-submit it (through my usual channel Denny).
Thanks,
Mike
---
Michael J. Ruhl (1):
RDMA/netlink: OOPs in rdma_nl_rcv_msg() from misinterpreted flag
drivers/infiniband/core/netlink.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
Signature · 4 lines
-- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 RDMA/netlink: OOPs in rdma_nl_rcv_msg() from misinterpreted flag
In reply to a message not in the archiveFrom: Michael J. Ruhl <[email protected]>
rdma_nl_rcv_msg() checks to see if it should use the .dump() callback or the .doit() callback. The check is done with this check:
if (flags & NLM_F_DUMP) ...
The NLM_F_DUMP flag is two bits (NLM_F_ROOT | NLM_F_MATCH).
When an RDMA_NL_LS messages is received, the bit used for indicating an error is the same bit as NLM_F_ROOT.
NLM_F_ROOT == (0x100) == RDMA_NL_LS_F_ERR.
ibacm sends a response with the RDMA_NL_LS_F_ERR bit set if an error occurs in the service. The current code then misinterprets the NLM_F_DUMP bit and trys to call the .dump() callback.
If the .dump() callback for the specified request is not available (which is true for the RDMA_NL_LS messages) the following Oops occurs:
[ 4555.960256] BUG: unable to handle kernel NULL pointer dereference at (null) [ 4555.969046] IP: (null) [ 4555.972664] PGD 10543f1067 P4D 10543f1067 PUD 1033f93067 PMD 0 [ 4555.979287] Oops: 0010 [#1] SMP [ 4555.982809] Modules linked in: rpcrdma ib_isert iscsi_target_mod
target_core_mod ib_iser libiscsi scsi_transport_iscsi ib_ipoib rdma_ucm ib_ucm ib_uverbs ib_umad rdma_cm ib_cm iw_cm dm_mirror dm_region_hash dm_log dm_mod dax sb_edac x86_pkg_temp_thermal intel_powerclamp coretemp kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel pcbc aesni_intel crypto_simd glue_helper cryptd hfi1 rdmavt iTCO_wdt iTCO_vendor_support ib_core mei_me lpc_ich pcspkr mei ioatdma sg shpchp i2c_i801 mfd_core wmi ipmi_si ipmi_devintf ipmi_msghandler acpi_power_meter acpi_pad nfsd auth_rpcgss nfs_acl lockd grace sunrpc ip_tables ext4 mbcache jbd2 sd_mod mgag200 drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops ttm igb ahci crc32c_intel ptp libahci pps_core drm dca libata i2c_algo_bit i2c_core
[ 4556.061190] CPU: 54 PID: 9841 Comm: ibacm Tainted: G I 4.14.0-rc2+ #6 [ 4556.069667] Hardware name: Intel Corporation S2600WT2/S2600WT2, BIOS SE5C610.86B.01.01.0008.021120151325 02/11/2015 [ 4556.081339] task: ffff880855f42d00 task.stack: ffffc900246b4000 [ 4556.087967] RIP: 0010: (null) [ 4556.092166] RSP: 0018:ffffc900246b7bc8 EFLAGS: 00010246 [ 4556.098018] RAX: ffffffff81dbe9e0 RBX: ffff881058bb1000 RCX: 0000000000000000 [ 4556.105997] RDX: 0000000000001100 RSI: ffff881058bb1320 RDI: ffff881056362000 [ 4556.113984] RBP: ffffc900246b7bf8 R08: 0000000000000ec0 R09: 0000000000001100 [ 4556.121971] R10: ffff8810573a5000 R11: 0000000000000000 R12: ffff881056362000 [ 4556.129957] R13: 0000000000000ec0 R14: ffff881058bb1320 R15: 0000000000000ec0 [ 4556.137945] FS: 00007fe0ba5a38c0(0000) GS:ffff88105f080000(0000) knlGS:0000000000000000 [ 4556.147000] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 4556.153433] CR2: 0000000000000000 CR3: 0000001056f5d003 CR4: 00000000001606e0 [ 4556.161419] Call Trace: [ 4556.164167] ? netlink_dump+0x12c/0x290 [ 4556.168468] __netlink_dump_start+0x186/0x1f0 [ 4556.173357] rdma_nl_rcv_msg+0x193/0x1b0 [ib_core] [ 4556.178724] rdma_nl_rcv+0xdc/0x130 [ib_core] [ 4556.183604] netlink_unicast+0x181/0x240 [ 4556.187998] netlink_sendmsg+0x2c2/0x3b0 [ 4556.192392] sock_sendmsg+0x38/0x50 [ 4556.196299] SYSC_sendto+0x102/0x190 [ 4556.200308] ? __audit_syscall_entry+0xaf/0x100 [ 4556.205387] ? syscall_trace_enter+0x1d0/0x2b0 [ 4556.210366] ? __audit_syscall_exit+0x209/0x290 [ 4556.215442] SyS_sendto+0xe/0x10 [ 4556.219060] do_syscall_64+0x67/0x1b0 [ 4556.223165] entry_SYSCALL64_slow_path+0x25/0x25 [ 4556.228328] RIP: 0033:0x7fe0b9db2a63 [ 4556.232333] RSP: 002b:00007ffc55edc260 EFLAGS: 00000293 ORIG_RAX: 000000000000002c [ 4556.240808] RAX: ffffffffffffffda RBX: 0000000000000010 RCX: 00007fe0b9db2a63 [ 4556.248796] RDX: 0000000000000010 RSI: 00007ffc55edc280 RDI: 000000000000000d [ 4556.256782] RBP: 00007ffc55edc670 R08: 00007ffc55edc270 R09: 000000000000000c [ 4556.265321] R10: 0000000000000000 R11: 0000000000000293 R12: 00007ffc55edc280 [ 4556.273846] R13: 000000000260b400 R14: 000000000000000d R15: 0000000000000001 [ 4556.282368] Code: Bad RIP value. [ 4556.286629] RIP: (null) RSP: ffffc900246b7bc8 [ 4556.293013] CR2: 0000000000000000 [ 4556.297292] ---[ end trace 8d67abcfd10ec209 ]--- [ 4556.305465] Kernel panic - not syncing: Fatal exception [ 4556.313786] Kernel Offset: disabled [ 4556.321563] ---[ end Kernel panic - not syncing: Fatal exception [ 4556.328960] ------------[ cut here ]------------
Only check for NLM_F_DUMP bits if the index != RDMA_NL_LS.
Additionally, make sure that the .dump() callback is not NULL before calling it.
INTERNAL: PR 140882 - Machine unusable after doing ping
--- drivers/infiniband/core/netlink.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/infiniband/core/netlink.c +5 -2
@@ -176,11 +176,14 @@ static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,return -EPERM ;/* FIXME: Convert IWCM to properly handle doit callbacks */ -if ((nlh->nlmsg_flags &NLM_F_DUMP ) || index ==RDMA_NL_RDMA_CM || - index ==RDMA_NL_IWCM ) { +if ((index !=RDMA_NL_LS ) && + ((nlh->nlmsg_flags &NLM_F_DUMP ) || index ==RDMA_NL_RDMA_CM || + index ==RDMA_NL_IWCM )) {struct netlink_dump_control c = { .dump = cb_table[op].dump, }; +if (!c.dump) +return 0 ;return netlink_dump_start (nls, skb, nlh, &c); }
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 71 lines · Michael J. Ruhl
I was playing with the ibacm service and discovered an issue the other day.
If no provider library is present (I removed libacmp.so, and the provider keyword in the opts.cfg file is libacmp), when a resolve request is posted, the kernel will crash with the following Oops:
BUG: unable to handle kernel NULL pointer dereference at (null) IP: (null) PGD 10543f1067 P4D 10543f1067 PUD 1033f93067 PMD 0 Oops: 0010 [#1] SMP Modules linked in: rpcrdma ib_isert iscsi_target_mod target_core_mod ib_iser libiscsi scsi_transport_iscsi ib_ipoib rdma_ucm ib_u ib_uverbs ib_umad rdma_cm ib_cm iw_cm dm_mirror dm_region_hash dm_log dm_mod dax sb_edac x86_pkg_temp_thermal intel_powerclamp coretemp kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel pcbc aesni_intel crypto_si glue_helper cryptd hfi1 rdmavt iTCO_wdt iTCO_vendor_support ib_core mei_me lpc_ich pcspkr mei ioatdma sg shpchp i2c_i801 mfd_core wmi ipmi_si ipmi_devi ipmi_msghandler acpi_power_meter acpi_pad nfsd auth_rpcgss nfs_acl lockd gra sunrpc ip_tables ext4 mbcache jbd2 sd_mod mgag200 drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops ttm igb ahci crc32c_intel ptp libahci pps_core drm dca libata i2c_algo_bit i2c_core CPU: 54 PID: 9841 Comm: ibacm Tainted: G I 4.14.0-rc2+ #6 Hardware name: Intel Corporation S2600WT2/S2600WT2, BIOS SE5C610.86B.01.01.0008.021120151325 02/11/2015 task: ffff880855f42d00 task.stack: ffffc900246b4000 RIP: 0010: (null) RSP: 0018:ffffc900246b7bc8 EFLAGS: 00010246 RAX: ffffffff81dbe9e0 RBX: ffff881058bb1000 RCX: 0000000000000000 RDX: 0000000000001100 RSI: ffff881058bb1320 RDI: ffff881056362000 RBP: ffffc900246b7bf8 R08: 0000000000000ec0 R09: 0000000000001100 R10: ffff8810573a5000 R11: 0000000000000000 R12: ffff881056362000 R13: 0000000000000ec0 R14: ffff881058bb1320 R15: 0000000000000ec0 FS: 00007fe0ba5a38c0(0000) GS:ffff88105f080000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000001056f5d003 CR4: 00000000001606e0 Call Trace: ? netlink_dump+0x12c/0x290 __netlink_dump_start+0x186/0x1f0 rdma_nl_rcv_msg+0x193/0x1b0 [ib_core] rdma_nl_rcv+0xdc/0x130 [ib_core] netlink_unicast+0x181/0x240 netlink_sendmsg+0x2c2/0x3b0 sock_sendmsg+0x38/0x50 SYSC_sendto+0x102/0x190 ? __audit_syscall_entry+0xaf/0x100 ? syscall_trace_enter+0x1d0/0x2b0 ? __audit_syscall_exit+0x209/0x290 SyS_sendto+0xe/0x10 do_syscall_64+0x67/0x1b0 entry_SYSCALL64_slow_path+0x25/0x25 RIP: 0033:0x7fe0b9db2a63 RSP: 002b:00007ffc55edc260 EFLAGS: 00000293 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 0000000000000010 RCX: 00007fe0b9db2a63 RDX: 0000000000000010 RSI: 00007ffc55edc280 RDI: 000000000000000d RBP: 00007ffc55edc670 R08: 00007ffc55edc270 R09: 000000000000000c R10: 0000000000000000 R11: 0000000000000293 R12: 00007ffc55edc280 R13: 000000000260b400 R14: 000000000000000d R15: 0000000000000001 Code: Bad RIP value. RIP: (null) RSP: ffffc900246b7bc8 CR2: 0000000000000000 ---[ end trace 8d67abcfd10ec209 ]--- Kernel panic - not syncing: Fatal exception Kernel Offset: disabled ---[ end Kernel panic - not syncing: Fatal exception ------------[ cut here ]------------The issue is that in
rdma_nl_rcv_msg(), the check 'if (flags &NLM_F_DUMP)' is not completely correct.
NLM_F_DUMPis two bitsNLM_F_ROOT|NLM_F_MATCH.
Quoted 8 lines
ibacm sends a
RDMA_NL_LSresponse with theRDMA_NL_LS_F_ERRbit set if an error occurs in the service (like no provider being available, orACM_STATUS_ENODATA, etc.).
NLM_F_ROOT== (0x100) ==RDMA_NL_LS_F_ERR.The current code thinks that it sees a
NLM_F_DUMPflag and incorrectly calls the .dump() callback.
Hi Michael,
Thanks for the report and for excellent analysis, You are right that RDMA_NL_LS_F_ERR has the same value as NLM_F_ROOT and it is bad, but I just think that it is not the final root cause.
In case of errors, the LS was supposed to send NLMSG_ERROR message and not overload general nlmsg_flags, which is awful. However I don't know if it is feasible to fix current implementation without breaking UAPI contract.
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse ib_nl_is_good_ip_resp?
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the LS-relevant code.
And returning 0 in absence of dumpit function as a response with NLM_F_DUMP flag is wrong. User should be aware of the fact that something wrong was with his request.
Thanks
Quoted 32 lines
The included patch is an atempt to fix this issue. This patch fixes the issue that I am seeing, but I am not sure how to test the messages for
RDMA_NL_RDMA_CMorRDMA_NL_IWCM(or any message that uses theNLM_F_DUMPbits).If anyone has some knowledge of these services, any extra testing would be welcomed.
If the patch has no issues or comments, I will formally re-submit it (through my usual channel Denny).
Thanks,
Mike
---
Michael J. Ruhl (1):
RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagdrivers/infiniband/core/netlink.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)--
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 28 lines
-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Leon Romanovsky
Sent: Friday, October 20, 2017 3:37 AM
To: Ruhl, Michael J
Cc: [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagQuoted 7 lines
The issue is that in
rdma_nl_rcv_msg(), the check 'if (flags &NLM_F_DUMP)' is not completely correct.
NLM_F_DUMPis two bitsNLM_F_ROOT|NLM_F_MATCH.ibacm sends a
RDMA_NL_LSresponse with theRDMA_NL_LS_F_ERRbit setif
Quoted 7 lines
an error occurs in the service (like no provider being available, or
ACM_STATUS_ENODATA, etc.).
NLM_F_ROOT== (0x100) ==RDMA_NL_LS_F_ERR.The current code thinks that it sees a
NLM_F_DUMPflag and incorrectly calls the .dump() callback.Hi Michael,
Quoted 7 lines
Thanks for the report and for excellent analysis, You are right that
RDMA_NL_LS_F_ERRhas the same value asNLM_F_ROOTand it is bad, but I just think that it is not the final root cause.In case of errors, the LS was supposed to send
NLMSG_ERRORmessage and not overload generalnlmsg_flags, which is awful. However I don't know if it is feasible to fix current implementation without breaking UAPI contract.
The nlmsg_flags from 0x100 and up have always been overloaded for different requests, as shown in include/uapi/linux/netlink.h:
* Modifiers to GET request */
#define NLM_F_ROOT 0x100 /* specify tree root */
#define NLM_F_MATCH 0x200 /* return all matching */
#define NLM_F_ATOMIC 0x400 /* atomic GET */
#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
/* Modifiers to NEW request */
#define NLM_F_REPLACE 0x100 /* Override existing */
#define NLM_F_EXCL 0x200 /* Do not touch, if it exists */
#define NLM_F_CREATE 0x400 /* Create, if it does not exist */
#define NLM_F_APPEND 0x800 /* Add to end of list */
/* Modifiers to DELETE request */
#define NLM_F_NONREC 0x100 /* Do not delete recursively */
/* Flags for ACK message */
#define NLM_F_CAPPED 0x100 /* request was capped */
#define NLM_F_ACK_TLVS 0x200 /* extended ACK TVLs were included *
The NLM_F_DUMP flag is supposed to be used for the GET request only, not as a general flag for all netlink requests.
Quoted 3 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?
Why do you want to jump all the dump hoops instead of directly calling the response handler? LS is different from other netlink channels in that it sends request from kernel to user space and receives responses from it instead of the other way around. Consequently, the handling of netlink responses may be different from handing requests from user space.
Quoted 10 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the LS-relevant code.
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 32 lines · Kaike
Quoted 32 lines
-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Leon Romanovsky
Sent: Friday, October 20, 2017 3:37 AM
To: Ruhl, Michael J
Cc: [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagQuoted 7 lines
The issue is that in
rdma_nl_rcv_msg(), the check 'if (flags &NLM_F_DUMP)' is not completely correct.
NLM_F_DUMPis two bitsNLM_F_ROOT|NLM_F_MATCH.ibacm sends a
RDMA_NL_LSresponse with theRDMA_NL_LS_F_ERRbit setif
Quoted 7 lines
an error occurs in the service (like no provider being available, or
ACM_STATUS_ENODATA, etc.).
NLM_F_ROOT== (0x100) ==RDMA_NL_LS_F_ERR.The current code thinks that it sees a
NLM_F_DUMPflag and incorrectly calls the .dump() callback.Hi Michael,
Thanks for the report and for excellent analysis, You are right that
RDMA_NL_LS_F_ERRhas the same value asNLM_F_ROOTand it is bad, but I just think that it is not the final root cause.
Quoted 5 lines
Quoted 3 lines
In case of errors, the LS was supposed to send
NLMSG_ERRORmessage and not overload generalnlmsg_flags, which is awful. However I don't know if it is feasible to fix current implementation without breaking UAPI contract.The
nlmsg_flagsfrom0x100and up have always been overloaded for different requests, as shown ininclude/uapi/linux/netlink.h:
Exactly, they are overloaded in include/uapi/linux/netlink.h where all nlmsg flags are declared and not in some random rdma*.h file.
But it is not my main point.
My main point is lack of usage of NLMSG_ERROR messages to inform about errors, exactly as kernel informs users about errors in netlink, but in the opposite direction.
Quoted 20 lines
* Modifiers to GET request */
#defineNLM_F_ROOT0x100/* specify tree root */
#defineNLM_F_MATCH0x200/* return all matching */
#defineNLM_F_ATOMIC0x400/* atomic GET */
#defineNLM_F_DUMP(NLM_F_ROOT|NLM_F_MATCH)/* Modifiers to NEW request */
#defineNLM_F_REPLACE0x100/* Override existing */
#defineNLM_F_EXCL0x200/* Do not touch, if it exists */
#defineNLM_F_CREATE0x400/* Create, if it does not exist */
#defineNLM_F_APPEND0x800/* Add to end of list *//* Modifiers to DELETE request */
#defineNLM_F_NONREC0x100/* Do not delete recursively *//* Flags for ACK message */
#defineNLM_F_CAPPED0x100/* request was capped */
#defineNLM_F_ACK_TLVS0x200/* extended ACK TVLs were included *
Quoted 8 lines
The
NLM_F_DUMPflag is supposed to be used for the GET request only, not as a general flag for all netlink requests.Quoted 3 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?Why do you want to jump all the dump hoops instead of directly calling the response handler? LS is different from other netlink channels in that it sends request from kernel to user space and receives responses from it instead of the other way around. Consequently, the handling of netlink responses may be different from handing requests from user space.
Doesn't the part of email below answers on the question "why"?
Quoted 13 lines
Quoted 12 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the LS-relevant code.
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.Thanks
Quoted 48 lines
-----Original Message-----
From: Leon Romanovsky [mailto:[email protected]]
Sent: Friday, October 20, 2017 3:37 AM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagQuoted 28 lines · Michael J. Ruhl
I was playing with the ibacm service and discovered an issue the other day.
If no provider library is present (I removed libacmp.so, and the provider keyword in the opts.cfg file is libacmp), when a resolve request is posted, the kernel will crash with the following Oops:
Call Trace: ? netlink_dump+0x12c/0x290 __netlink_dump_start+0x186/0x1f0 rdma_nl_rcv_msg+0x193/0x1b0 [ib_core] rdma_nl_rcv+0xdc/0x130 [ib_core] netlink_unicast+0x181/0x240 netlink_sendmsg+0x2c2/0x3b0 sock_sendmsg+0x38/0x50 SYSC_sendto+0x102/0x190 ? __audit_syscall_entry+0xaf/0x100 ? syscall_trace_enter+0x1d0/0x2b0 ? __audit_syscall_exit+0x209/0x290 SyS_sendto+0xe/0x10 do_syscall_64+0x67/0x1b0 entry_SYSCALL64_slow_path+0x25/0x25The issue is that in
rdma_nl_rcv_msg(), the check 'if (flags &NLM_F_DUMP)' is not completely correct.
NLM_F_DUMPis two bitsNLM_F_ROOT|NLM_F_MATCH.Quoted 8 lines
ibacm sends a
RDMA_NL_LSresponse with theRDMA_NL_LS_F_ERRbit set if an error occurs in the service (like no provider being available, orACM_STATUS_ENODATA, etc.).
NLM_F_ROOT== (0x100) ==RDMA_NL_LS_F_ERR.The current code thinks that it sees a
NLM_F_DUMPflag and incorrectly calls the .dump() callback.Hi Michael,
Quoted 7 lines
Thanks for the report and for excellent analysis, You are right that
RDMA_NL_LS_F_ERRhas the same value asNLM_F_ROOTand it is bad, but I just think that it is not the final root cause.In case of errors, the LS was supposed to send
NLMSG_ERRORmessage and not overload generalnlmsg_flags, which is awful. However I don't know if it is feasible to fix current implementation without breaking UAPI contract.
I agree this is probably something that needs to get followed up on.
Quoted 2 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?
The original code does not call the netlink_dump_start() code for this path, so if we create a dummy dump function we will have to add code to special case this and call it directly.
So maybe we could just go back to the original code and call .doit rather than .dump in the non netlink_dump_start() path?
i.e.:
if (!(nlh->nlmsg_flags & NLM_F_REQUEST) ||
(index == RDMA_NL_LS && op == RDMA_NL_LS_OP_SET_TIMEOUT)) {
cb.skb = skb;
cb.nlh = nlh;
cb.dump = cb_table[op].dump;
- return cb.dump(skb, &cb);
+ return cb.doit(skb, &cb);
} else {
c.dump = cb_table[op].dump;Quoted 2 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the LS-relevant code.
The problem with this is that the code has to take into consideration the LS anomalies either before the this function is called, or has to deal with them here.
The other thought would be to special case the LS stuff before this decision and call the .doit function there (and then return).
Quoted 3 lines
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.
This was the value that the function returns if .dump and .doit are NOT selected, so I thought that this was appropriate. Should that value (the final return 0) be changed to something different?
Mike
Quoted 34 lines
Thanks
Quoted 32 lines
The included patch is an atempt to fix this issue. This patch fixes the issue that I am seeing, but I am not sure how to test the messages for
RDMA_NL_RDMA_CMorRDMA_NL_IWCM(or any message that uses theNLM_F_DUMPbits).If anyone has some knowledge of these services, any extra testing would be welcomed.
If the patch has no issues or comments, I will formally re-submit it (through my usual channel Denny).
Thanks,
Mike
---
Michael J. Ruhl (1):
RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagdrivers/infiniband/core/netlink.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)--
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Leon Romanovsky
Sent: Friday, October 20, 2017 12:20 PM
To: Wan, Kaike
Cc: Ruhl, Michael J; [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flag
Quoted 6 lines
Quoted 1 line · Kaike
The
nlmsg_flagsfrom0x100and up have always been overloaded fordifferent requests, as shown in
include/uapi/linux/netlink.h:Exactly, they are overloaded in
include/uapi/linux/netlink.hwhere all nlmsg flags are declared and not in some random rdma*.h file.
Since they are known to be overloaded, how could you depend on the flags to make decision for all requests/responses?
The reason for defining RDMA_NL_LS_F_ERR in include/uapi/rdma/rdma_netlink is that all LS related defines and structures are defined in the file. It is true that it can lead to misuse, just like the current code. However, the defines in include/uapi/linux/netlink.h un-mistakenly indicate that those bits can be overloaded.
Quoted 6 lines
But it is not my main point.
My main point is lack of usage of
NLMSG_ERRORmessages to inform about errors, exactly as kernel informs users about errors in netlink, but in the opposite direction.
The difference is that the LS needs all the original information (request type, client index, msg_seq, etc) to match the response with the original request. Therefore, the easiest thing to do is to return the response with the original info plus an error flag, instead of using the NLMSG_ERROR message.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?
Quoted 8 lines
Quoted 1 line
Why do you want to jump all the dump hoops instead of directly calling the
response handler? LS is different from other netlink channels in that it sends request from kernel to user space and receives responses from it instead of the other way around. Consequently, the handling of netlink responses may be different from handing requests from user space.
Quoted 1 line
Doesn't the part of email below answers on the question "why"?
No. A response should not necessarily be processed the same as a request.
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the
LS-relevant code.
Quoted 8 lines
Quoted 7 lines
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Kaike
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Leon Romanovsky
Sent: Friday, October 20, 2017 12:20 PM
To: Wan, Kaike
Cc: Ruhl, Michael J; [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flag
Quoted 8 lines
Quoted 6 lines · Kaike
Quoted 1 line
The
nlmsg_flagsfrom0x100and up have always been overloaded fordifferent requests, as shown in
include/uapi/linux/netlink.h:Exactly, they are overloaded in
include/uapi/linux/netlink.hwhere all nlmsg flags are declared and not in some random rdma*.h file.Since they are known to be overloaded, how could you depend on the flags to make decision for all requests/responses?
Sorry for applying common sense for the RDMA subsystem. The netlink structures are declared and exported to users in one specific file, the structure, flags and defines belong to netdev subsystem and were not supposed to be overwritten by other users.
Quoted 2 lines
The reason for defining
RDMA_NL_LS_F_ERRininclude/uapi/rdma/rdma_netlinkis that all LS related defines and structures are defined in the file. It is true that it can lead to misuse, just like the current code. However, the defines ininclude/uapi/linux/netlink.hun-mistakenly indicate that those bits can be overloaded.
We are talking about theoretical case, the current LS implementation will stay as is, so no worries.
Quoted 10 lines
Quoted 7 lines
But it is not my main point.
My main point is lack of usage of
NLMSG_ERRORmessages to inform about errors, exactly as kernel informs users about errors in netlink, but in the opposite direction.The difference is that the LS needs all the original information (request type, client index,
msg_seq, etc) to match the response with the original request. Therefore, the easiest thing to do is to return the response with the original info plus an error flag, instead of using theNLMSG_ERRORmessage.
Just wanted to mention that NLMSG_ERROR is netlink message type and it carries all other information except message type.
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?Why do you want to jump all the dump hoops instead of directly calling the
response handler? LS is different from other netlink channels in that it sends request from kernel to user space and receives responses from it instead of the other way around. Consequently, the handling of netlink responses may be different from handing requests from user space.
Quoted 1 line
Quoted 3 lines
Quoted 1 line
Doesn't the part of email below answers on the question "why"?
No. A response should not necessarily be processed the same as a request.
Right, and I expected to see complete mirror of kernel-to-user communication in respect to LS user-to-kernel communication.
Quoted 16 lines
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the
LS-relevant code.
Quoted 8 lines
Quoted 7 lines
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.Thanks
Quoted 77 lines · Michael J
Quoted 48 lines
-----Original Message-----
From: Leon Romanovsky [mailto:[email protected]]
Sent: Friday, October 20, 2017 3:37 AM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagQuoted 28 lines · Michael J. Ruhl
I was playing with the ibacm service and discovered an issue the other day.
If no provider library is present (I removed libacmp.so, and the provider keyword in the opts.cfg file is libacmp), when a resolve request is posted, the kernel will crash with the following Oops:
Call Trace: ? netlink_dump+0x12c/0x290 __netlink_dump_start+0x186/0x1f0 rdma_nl_rcv_msg+0x193/0x1b0 [ib_core] rdma_nl_rcv+0xdc/0x130 [ib_core] netlink_unicast+0x181/0x240 netlink_sendmsg+0x2c2/0x3b0 sock_sendmsg+0x38/0x50 SYSC_sendto+0x102/0x190 ? __audit_syscall_entry+0xaf/0x100 ? syscall_trace_enter+0x1d0/0x2b0 ? __audit_syscall_exit+0x209/0x290 SyS_sendto+0xe/0x10 do_syscall_64+0x67/0x1b0 entry_SYSCALL64_slow_path+0x25/0x25The issue is that in
rdma_nl_rcv_msg(), the check 'if (flags &NLM_F_DUMP)' is not completely correct.
NLM_F_DUMPis two bitsNLM_F_ROOT|NLM_F_MATCH.Quoted 8 lines
ibacm sends a
RDMA_NL_LSresponse with theRDMA_NL_LS_F_ERRbit set if an error occurs in the service (like no provider being available, orACM_STATUS_ENODATA, etc.).
NLM_F_ROOT== (0x100) ==RDMA_NL_LS_F_ERR.The current code thinks that it sees a
NLM_F_DUMPflag and incorrectly calls the .dump() callback.Hi Michael,
Quoted 7 lines
Thanks for the report and for excellent analysis, You are right that
RDMA_NL_LS_F_ERRhas the same value asNLM_F_ROOTand it is bad, but I just think that it is not the final root cause.In case of errors, the LS was supposed to send
NLMSG_ERRORmessage and not overload generalnlmsg_flags, which is awful. However I don't know if it is feasible to fix current implementation without breaking UAPI contract.I agree this is probably something that needs to get followed up on.
Quoted 2 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?The original code does not call the
netlink_dump_start()code for this path, so if we create a dummy dump function we will have to add code to special case this and call it directly.So maybe we could just go back to the original code and call .doit rather than .dump in the non
netlink_dump_start()path?i.e.:
if (!(nlh->nlmsg_flags & NLM_F_REQUEST) || (index == RDMA_NL_LS && op == RDMA_NL_LS_OP_SET_TIMEOUT)) { cb.skb = skb; cb.nlh = nlh; cb.dump = cb_table[op].dump;(quoted diff) +1
-1- return cb.dump(skb, &cb); + return cb.doit(skb, &cb); } else { c.dump = cb_table[op].dump;
Quoted 6 lines
Quoted 2 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the LS-relevant code.
The problem with this is that the code has to take into consideration the LS anomalies either before the this function is called, or has to deal with them here.
The other thought would be to special case the LS stuff before this decision and call the .doit function there (and then return).
What about such code?
drivers/infiniband/core/netlink.c +8 -0
@@ -175,6 +175,14 @@ static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, !netlink_capable(skb, CAP_NET_ADMIN))return -EPERM ; +/* +* LS is special because it runs backward communication +* and it overloads NLM_F_DUMP flag with RDMA_NL_LS_F_ERR +* So we are calling to .doit before processing .dumpit call. +*/ +if (index ==RDMA_NL_LS ) +return cb_table[op].doit (skb, nlh, extack); +/* FIXME: Convert IWCM to properly handle doit callbacks */ if ((nlh->nlmsg_flags &NLM_F_DUMP ) || index ==RDMA_NL_RDMA_CM || index ==RDMA_NL_IWCM ) {
Quoted 6 lines
Quoted 4 lines
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.This was the value that the function returns if .dump and .doit are NOT selected, so I thought that this was appropriate. Should that value (the final return 0) be changed to something different?
The is_nl_valid() should return "false" If no .dumpit/.doit functions exist. In such case, we are supposed to return EINVAL.
Thanks
Quoted 37 lines
Mike
Quoted 34 lines
Thanks
Quoted 32 lines
The included patch is an atempt to fix this issue. This patch fixes the issue that I am seeing, but I am not sure how to test the messages for
RDMA_NL_RDMA_CMorRDMA_NL_IWCM(or any message that uses theNLM_F_DUMPbits).If anyone has some knowledge of these services, any extra testing would be welcomed.
If the patch has no issues or comments, I will formally re-submit it (through my usual channel Denny).
Thanks,
Mike
---
Michael J. Ruhl (1):
RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagdrivers/infiniband/core/netlink.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)--
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 102 lines
-----Original Message-----
From: Leon Romanovsky [mailto:[email protected]]
Sent: Monday, October 23, 2017 4:11 AM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagQuoted 29 lines · Michael J
Quoted 29 lines · Michael J. Ruhl
Quoted 28 lines
I was playing with the ibacm service and discovered an issue the other day.
If no provider library is present (I removed libacmp.so, and the provider keyword in the opts.cfg file is libacmp), when a resolve request is posted, the kernel will crash with the following Oops:
Call Trace: ? netlink_dump+0x12c/0x290 __netlink_dump_start+0x186/0x1f0 rdma_nl_rcv_msg+0x193/0x1b0 [ib_core] rdma_nl_rcv+0xdc/0x130 [ib_core] netlink_unicast+0x181/0x240 netlink_sendmsg+0x2c2/0x3b0 sock_sendmsg+0x38/0x50 SYSC_sendto+0x102/0x190 ? __audit_syscall_entry+0xaf/0x100 ? syscall_trace_enter+0x1d0/0x2b0 ? __audit_syscall_exit+0x209/0x290 SyS_sendto+0xe/0x10 do_syscall_64+0x67/0x1b0 entry_SYSCALL64_slow_path+0x25/0x25The issue is that in
rdma_nl_rcv_msg(), the check 'if (flags &NLM_F_DUMP)' is not completely correct.
NLM_F_DUMPis two bitsNLM_F_ROOT|NLM_F_MATCH.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
ibacm sends a
RDMA_NL_LSresponse with theRDMA_NL_LS_F_ERRbit set if an error occurs in the service (like no provider being available, orACM_STATUS_ENODATA, etc.).
NLM_F_ROOT== (0x100) ==RDMA_NL_LS_F_ERR.The current code thinks that it sees a
NLM_F_DUMPflag and incorrectlycalls
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
the .dump() callback.
Hi Michael,
Thanks for the report and for excellent analysis, You are right that
RDMA_NL_LS_F_ERRhas the same value asNLM_F_ROOTand it is bad, but I just think that it is not the final root cause.In case of errors, the LS was supposed to send
NLMSG_ERRORmessage andnot
Quoted 9 lines
Quoted 2 lines
overload general
nlmsg_flags, which is awful. However I don't know if it is feasible to fix current implementation without breaking UAPI contract.I agree this is probably something that needs to get followed up on.
Quoted 2 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?The original code does not call the
netlink_dump_start()code for this path, soif we create a dummy dump function we will have to add code to special case this and call it directly.
Quoted 2 lines
So maybe we could just go back to the original code and call .doit rather than
.dump in the non
netlink_dump_start()path?Quoted 13 lines
i.e.:
if (!(nlh->nlmsg_flags & NLM_F_REQUEST) || (index == RDMA_NL_LS && op == RDMA_NL_LS_OP_SET_TIMEOUT)) { cb.skb = skb; cb.nlh = nlh; cb.dump = cb_table[op].dump;(quoted diff) +1
-1- return cb.dump(skb, &cb); + return cb.doit(skb, &cb); } else { c.dump = cb_table[op].dump;Quoted 4 lines
Quoted 2 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the LS-relevant code.
The problem with this is that the code has to take into consideration the LS
anomalies either before the this function is called, or has to deal with them here.
Quoted 2 lines
The other thought would be to special case the LS stuff before this decision
and call the .doit function there (and then return).
What about such code?
drivers/infiniband/core/netlink.c +0
-0@@ -175,6 +175,14 @@ static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, !netlink_capable(skb, CAP_NET_ADMIN))
drivers/infiniband/core/netlink.c static int rdma_nl_rcv_msg(struct sk_buff *skb, struct · line 186
Quoted 10 lines
drivers/infiniband/core/netlink.c +8
-0return -EPERM ; +/* +* LS is special because it runs backward communication +* and it overloads NLM_F_DUMP flag with RDMA_NL_LS_F_ERR +* So we are calling to .doit before processing .dumpit call. +*/ +if (index ==RDMA_NL_LS ) +return cb_table[op].doit (skb, nlh, extack); +
Hi Leon,
That works for me (I am going to wordsmith the comment slightly). A new patch will be forthcoming shortly.
Mike
Quoted 10 lines
drivers/infiniband/core/netlink.c +0
-0/* FIXME: Convert IWCM to properly handle doit callbacks */ if ((nlh->nlmsg_flags & NLM_F_DUMP) || index ==
RDMA_NL_RDMA_CM||
index ==RDMA_NL_IWCM) {Quoted 5 lines
Quoted 4 lines
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.
Quoted 45 lines
Quoted 1 line
This was the value that the function returns if .dump and .doit are NOT
selected, so I thought that this was appropriate. Should that value (the final return 0) be changed to something different?
The
is_nl_valid()should return "false" If no .dumpit/.doit functions exist. In such case, we are supposed to return EINVAL.
ThanksQuoted 37 lines
Mike
Quoted 34 lines
Thanks
Quoted 32 lines
The included patch is an atempt to fix this issue. This patch fixes the issue that I am seeing, but I am not sure how to test the messages for
RDMA_NL_RDMA_CMorRDMA_NL_IWCM(or any message that uses theNLM_F_DUMPbits).If anyone has some knowledge of these services, any extra testing would be welcomed.
If the patch has no issues or comments, I will formally re-submit it (through my usual channel Denny).
Thanks,
Mike
---
Michael J. Ruhl (1):
RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagdrivers/infiniband/core/netlink.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)--
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 108 lines · Leon Romanovsky
Quoted 77 lines · Michael J
Quoted 48 lines
-----Original Message-----
From: Leon Romanovsky [mailto:[email protected]]
Sent: Friday, October 20, 2017 3:37 AM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagQuoted 28 lines · Michael J. Ruhl
I was playing with the ibacm service and discovered an issue the other day.
If no provider library is present (I removed libacmp.so, and the provider keyword in the opts.cfg file is libacmp), when a resolve request is posted, the kernel will crash with the following Oops:
Call Trace: ? netlink_dump+0x12c/0x290 __netlink_dump_start+0x186/0x1f0 rdma_nl_rcv_msg+0x193/0x1b0 [ib_core] rdma_nl_rcv+0xdc/0x130 [ib_core] netlink_unicast+0x181/0x240 netlink_sendmsg+0x2c2/0x3b0 sock_sendmsg+0x38/0x50 SYSC_sendto+0x102/0x190 ? __audit_syscall_entry+0xaf/0x100 ? syscall_trace_enter+0x1d0/0x2b0 ? __audit_syscall_exit+0x209/0x290 SyS_sendto+0xe/0x10 do_syscall_64+0x67/0x1b0 entry_SYSCALL64_slow_path+0x25/0x25The issue is that in
rdma_nl_rcv_msg(), the check 'if (flags &NLM_F_DUMP)' is not completely correct.
NLM_F_DUMPis two bitsNLM_F_ROOT|NLM_F_MATCH.Quoted 8 lines
ibacm sends a
RDMA_NL_LSresponse with theRDMA_NL_LS_F_ERRbit set if an error occurs in the service (like no provider being available, orACM_STATUS_ENODATA, etc.).
NLM_F_ROOT== (0x100) ==RDMA_NL_LS_F_ERR.The current code thinks that it sees a
NLM_F_DUMPflag and incorrectly calls the .dump() callback.Hi Michael,
Quoted 7 lines
Thanks for the report and for excellent analysis, You are right that
RDMA_NL_LS_F_ERRhas the same value asNLM_F_ROOTand it is bad, but I just think that it is not the final root cause.In case of errors, the LS was supposed to send
NLMSG_ERRORmessage and not overload generalnlmsg_flags, which is awful. However I don't know if it is feasible to fix current implementation without breaking UAPI contract.I agree this is probably something that needs to get followed up on.
Quoted 2 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?The original code does not call the
netlink_dump_start()code for this path, so if we create a dummy dump function we will have to add code to special case this and call it directly.So maybe we could just go back to the original code and call .doit rather than .dump in the non
netlink_dump_start()path?i.e.:
if (!(nlh->nlmsg_flags & NLM_F_REQUEST) || (index == RDMA_NL_LS && op == RDMA_NL_LS_OP_SET_TIMEOUT)) { cb.skb = skb; cb.nlh = nlh; cb.dump = cb_table[op].dump;(quoted diff) +1
-1- return cb.dump(skb, &cb); + return cb.doit(skb, &cb); } else { c.dump = cb_table[op].dump;Quoted 6 lines
Quoted 2 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the LS-relevant code.
The problem with this is that the code has to take into consideration the LS anomalies either before the this function is called, or has to deal with them here.
The other thought would be to special case the LS stuff before this decision and call the .doit function there (and then return).
What about such code?
drivers/infiniband/core/netlink.c +8
-0@@ -175,6 +175,14 @@ static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, !netlink_capable(skb, CAP_NET_ADMIN))return -EPERM ; +/* +* LS is special because it runs backward communication +* and it overloads NLM_F_DUMP flag with RDMA_NL_LS_F_ERR +* So we are calling to .doit before processing .dumpit call. +*/ +if (index ==RDMA_NL_LS ) +return cb_table[op].doit (skb, nlh, extack); +/* FIXME: Convert IWCM to properly handle doit callbacks */ if ((nlh->nlmsg_flags &NLM_F_DUMP ) || index ==RDMA_NL_RDMA_CM || index ==RDMA_NL_IWCM ) {Quoted 2 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.This was the value that the function returns if .dump and .doit are NOT selected, so I thought that this was appropriate. Should that value (the final return 0) be changed to something different?
The
is_nl_valid()should return "false" If no .dumpit/.doit functions exist. In such case, we are supposed to return EINVAL.
My comment here is not specifically related to this issue alone, but to the overall netlink changes in general. I just want to make sure people are aware that this qualifies as a security fix, it *would* need to be addressed in stable if we weren't still in the same devel cycle that the overall netlink changes were introduced, and because this exposed the fact that we could call a routine that does not exist and oops the kernel, I think we need a quick audit of the netlink code to make sure there isn't another way for this to happen. Since this is user input directing the kernel to jump to a specific callback, this netlink code must be hardened against intentional attacks (and I haven't looked to see if this patch is sufficient to do that yet, I'm just trying to set expectations of what really needs to be done so I can send a complete pull request to Linus for this).
Cc: Linus to make him aware of the issue and to expect a fix from us sometime this week.
Signature · 3 lines
Doug Ledford <[email protected]> GPG Key ID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
Quoted 118 lines · Doug Ledford
Quoted 108 lines · Leon Romanovsky
Quoted 77 lines · Michael J
Quoted 48 lines
-----Original Message-----
From: Leon Romanovsky [mailto:[email protected]]
Sent: Friday, October 20, 2017 3:37 AM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from misinterpreted flagQuoted 28 lines · Michael J. Ruhl
I was playing with the ibacm service and discovered an issue the other day.
If no provider library is present (I removed libacmp.so, and the provider keyword in the opts.cfg file is libacmp), when a resolve request is posted, the kernel will crash with the following Oops:
Call Trace: ? netlink_dump+0x12c/0x290 __netlink_dump_start+0x186/0x1f0 rdma_nl_rcv_msg+0x193/0x1b0 [ib_core] rdma_nl_rcv+0xdc/0x130 [ib_core] netlink_unicast+0x181/0x240 netlink_sendmsg+0x2c2/0x3b0 sock_sendmsg+0x38/0x50 SYSC_sendto+0x102/0x190 ? __audit_syscall_entry+0xaf/0x100 ? syscall_trace_enter+0x1d0/0x2b0 ? __audit_syscall_exit+0x209/0x290 SyS_sendto+0xe/0x10 do_syscall_64+0x67/0x1b0 entry_SYSCALL64_slow_path+0x25/0x25The issue is that in
rdma_nl_rcv_msg(), the check 'if (flags &NLM_F_DUMP)' is not completely correct.
NLM_F_DUMPis two bitsNLM_F_ROOT|NLM_F_MATCH.Quoted 8 lines
ibacm sends a
RDMA_NL_LSresponse with theRDMA_NL_LS_F_ERRbit set if an error occurs in the service (like no provider being available, orACM_STATUS_ENODATA, etc.).
NLM_F_ROOT== (0x100) ==RDMA_NL_LS_F_ERR.The current code thinks that it sees a
NLM_F_DUMPflag and incorrectly calls the .dump() callback.Hi Michael,
Quoted 7 lines
Thanks for the report and for excellent analysis, You are right that
RDMA_NL_LS_F_ERRhas the same value asNLM_F_ROOTand it is bad, but I just think that it is not the final root cause.In case of errors, the LS was supposed to send
NLMSG_ERRORmessage and not overload generalnlmsg_flags, which is awful. However I don't know if it is feasible to fix current implementation without breaking UAPI contract.I agree this is probably something that needs to get followed up on.
Quoted 2 lines
In meanwhile, can we implement dummy dumpit functions for the LS, which reuse
ib_nl_is_good_ip_resp?The original code does not call the
netlink_dump_start()code for this path, so if we create a dummy dump function we will have to add code to special case this and call it directly.So maybe we could just go back to the original code and call .doit rather than .dump in the non
netlink_dump_start()path?i.e.:
if (!(nlh->nlmsg_flags & NLM_F_REQUEST) || (index == RDMA_NL_LS && op == RDMA_NL_LS_OP_SET_TIMEOUT)) { cb.skb = skb; cb.nlh = nlh; cb.dump = cb_table[op].dump;(quoted diff) +1
-1- return cb.dump(skb, &cb); + return cb.doit(skb, &cb); } else { c.dump = cb_table[op].dump;Quoted 6 lines
Quoted 2 lines
I prefer this solution over yours, because it doesn't mix LS-specifics with general decision function and leaves LS anomalies in the LS-relevant code.
The problem with this is that the code has to take into consideration the LS anomalies either before the this function is called, or has to deal with them here.
The other thought would be to special case the LS stuff before this decision and call the .doit function there (and then return).
What about such code?
drivers/infiniband/core/netlink.c +8
-0@@ -175,6 +175,14 @@ static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, !netlink_capable(skb, CAP_NET_ADMIN))return -EPERM ; +/* +* LS is special because it runs backward communication +* and it overloads NLM_F_DUMP flag with RDMA_NL_LS_F_ERR +* So we are calling to .doit before processing .dumpit call. +*/ +if (index ==RDMA_NL_LS ) +return cb_table[op].doit (skb, nlh, extack); +/* FIXME: Convert IWCM to properly handle doit callbacks */ if ((nlh->nlmsg_flags &NLM_F_DUMP ) || index ==RDMA_NL_RDMA_CM || index ==RDMA_NL_IWCM ) {Quoted 2 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
And returning 0 in absence of dumpit function as a response with
NLM_F_DUMPflag is wrong. User should be aware of the fact that something wrong was with his request.This was the value that the function returns if .dump and .doit are NOT selected, so I thought that this was appropriate. Should that value (the final return 0) be changed to something different?
The
is_nl_valid()should return "false" If no .dumpit/.doit functions exist. In such case, we are supposed to return EINVAL.
Quoted 13 lines
My comment here is not specifically related to this issue alone, but to the overall netlink changes in general. I just want to make sure people are aware that this qualifies as a security fix, it *would* need to be addressed in stable if we weren't still in the same devel cycle that the overall netlink changes were introduced, and because this exposed the fact that we could call a routine that does not exist and oops the kernel, I think we need a quick audit of the netlink code to make sure there isn't another way for this to happen. Since this is user input directing the kernel to jump to a specific callback, this netlink code must be hardened against intentional attacks (and I haven't looked to see if this patch is sufficient to do that yet, I'm just trying to set expectations of what really needs to be done so I can send a complete pull request to Linus for this).
Doug,
It has very little related to security here. The RDMA_NL_LS netlink operations require CAP_NET_ADMIN capability set and it is checked before calling any callback.
Quoted 9 lines
Cc: Linus to make him aware of the issue and to expect a fix from us sometime this week.
--
Doug Ledford <[email protected]>GPG Key ID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
Quoted 8 lines · Leon Romanovsky
Quoted 1 line · Doug Ledford
On 10/23/2017 4:11 AM, Leon Romanovsky wrote:
Doug,
It has very little related to security here. The
RDMA_NL_LSnetlink operations requireCAP_NET_ADMINcapability set and it is checked before
calling any callback.
I disagree. In this particular case, it wasn't a nefarious user, it was a simple misconfiguration that cause the kernel to oops. So even if you have CAP_NET_ADMIN, you still don't want a user space issue to oops the kernel. If you simply don't allow it to happen, then whether the CAP_NET_ADMIN program has been compromised by a black hat user is irrelevant. That seems the right way to be to me.
Signature · 8 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Doug Ledford
Quoted 8 lines · Leon Romanovsky
Quoted 1 line · Doug Ledford
On 10/23/2017 4:11 AM, Leon Romanovsky wrote:
Doug,
It has very little related to security here. The
RDMA_NL_LSnetlink operations requireCAP_NET_ADMINcapability set and it is checked before
calling any callback.
Quoted 6 lines
I disagree. In this particular case, it wasn't a nefarious user, it was a simple misconfiguration that cause the kernel to oops. So even if you have
CAP_NET_ADMIN, you still don't want a user space issue to oops the kernel. If you simply don't allow it to happen, then whether theCAP_NET_ADMINprogram has been compromised by a black hat user is irrelevant. That seems the right way to be to me.
OK, fix exists and if you want to call it "security issue", let's call it so.
Despite the fact that root misconfigured the system, root run the program, root crashed the system, like all over kernel oops we are seeing in linux kernel.
Thanks
Quoted 6 lines
--
Doug Ledford <[email protected]>GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
Quoted 27 lines
-----Original Message-----
From: Leon Romanovsky [mailto:[email protected]]
Sent: Monday, October 23, 2017 2:04 PM
To: Doug Ledford <[email protected]>
Cc: Ruhl, Michael J <[email protected]>; Torvalds, Linus <torvalds@linux- foundation.org>; [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from
misinterpreted flagQuoted 10 lines · Doug Ledford
Quoted 8 lines · Leon Romanovsky
Quoted 1 line · Doug Ledford
On 10/23/2017 4:11 AM, Leon Romanovsky wrote:
Doug,
It has very little related to security here. The
RDMA_NL_LSnetlink operations requireCAP_NET_ADMINcapability set and it is checked before
calling any callback.Quoted 6 lines
I disagree. In this particular case, it wasn't a nefarious user, it was a simple misconfiguration that cause the kernel to oops. So even if you have
CAP_NET_ADMIN, you still don't want a user space issue to oops the kernel. If you simply don't allow it to happen, then whether theCAP_NET_ADMINprogram has been compromised by a black hat user is irrelevant. That seems the right way to be to me.
Quoted 6 lines
OK, fix exists and if you want to call it "security issue", let's call it so.
Despite the fact that root misconfigured the system, root run the program, root crashed the system, like all over kernel oops we are seeing in linux kernel.
Thanks
I did repeat this once without the misconfiguration.
The scenario was that I had that a local (ibacm client 0) did a look up, got an error, and the system crashed.
I have been trying to remember what I did, but haven't repeated it a second time. I will see if I can figure out how to make it happen again.
M
Quoted 6 lines
Quoted 6 lines
--
Doug Ledford <[email protected]>GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 32 lines · Michael J
Quoted 32 lines
-----Original Message-----
From: Leon Romanovsky [mailto:[email protected]]
Sent: Monday, October 23, 2017 2:04 PM
To: Doug Ledford <[email protected]>
Cc: Ruhl, Michael J <[email protected]>; Torvalds, Linus <torvalds@linux- foundation.org>; [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from
misinterpreted flagQuoted 10 lines · Doug Ledford
Quoted 8 lines · Leon Romanovsky
Quoted 1 line · Doug Ledford
On 10/23/2017 4:11 AM, Leon Romanovsky wrote:
Doug,
It has very little related to security here. The
RDMA_NL_LSnetlink operations requireCAP_NET_ADMINcapability set and it is checked before
calling any callback.Quoted 6 lines
I disagree. In this particular case, it wasn't a nefarious user, it was a simple misconfiguration that cause the kernel to oops. So even if you have
CAP_NET_ADMIN, you still don't want a user space issue to oops the kernel. If you simply don't allow it to happen, then whether theCAP_NET_ADMINprogram has been compromised by a black hat user is irrelevant. That seems the right way to be to me.OK, fix exists and if you want to call it "security issue", let's call it so.
Despite the fact that root misconfigured the system, root run the program, root crashed the system, like all over kernel oops we are seeing in linux kernel.
Quoted 7 lines
Quoted 1 line
Thanks
I did repeat this once without the misconfiguration.
The scenario was that I had that a local (ibacm client 0) did a look up, got an error, and the system crashed.
I have been trying to remember what I did, but haven't repeated it a second time. I will see if I can figure out how to make it happen again.
Actually, you need to cause an error from ibacm side.
Just send a fix with stable tag.
Thanks for doing that.
Quoted 11 lines
M
Quoted 6 lines
Quoted 6 lines
--
Doug Ledford <[email protected]>GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD
Quoted 15 lines
-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Leon Romanovsky
Sent: Monday, October 23, 2017 2:25 PM
To: Ruhl, Michael J <[email protected]>
Cc: Doug Ledford <[email protected]>; Torvalds, Linus <torvalds@linux- foundation.org>; [email protected]
Subject: Re: [PATCH] RDMA/netlink: OOPs inrdma_nl_rcv_msg()from
misinterpreted flagQuoted 4 lines
I did repeat this once without the misconfiguration.
The scenario was that I had that a local (ibacm client 0) did a look up, got an
error, and the system crashed.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
I have been trying to remember what I did, but haven't repeated it a second
time. I will see if I can figure out how to make it happen again.
Actually, you need to cause an error from ibacm side.
Just send a fix with stable tag.
Thanks for doing that.
The patch is working its way through our internal process. Once that is done, I will post it.
Thanks,
Mike
Quoted 7 lines
Quoted 7 lines
M
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
--
Doug Ledford <[email protected]>GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E572FDD
Quoted 1 line
Quoted 1 line
Quoted 1 line
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html