Chunwei Chen 9470cbd4f9 Fix race in trace point in zrl_add_impl
We hit an illegal memory access in the zrlock trace point. The problem
is that zrl->zr_owner and zrl->zr_caller are assigned locklessly. And if
zrl->zr_owner got assigned a longer string between when __string()
calculate the strlen, and when __assign_str() does strcpy. The copy will
overflow the buffer.

==
For example:

Initial condition:
zrl->zr_owner = A
zrl->zr_caller = "abc"

Thread A                                 Thread B
-------------------------------------------------
if (zrl->zr_owner == A) {
  DTRACE_PROBE2() {
    __string() {
      strlen(zrl->zr_caller) -> 3
      allocate buf[4]
    }

                                        zrl->zr_owner = B
				        zrl->zr_caller = "abcd"

    __assign_str() {
      strcpy(buf, zrl->zr_caller) <- buffer overflow
==

Dereferencing zrl->zr_owner->pid may also be problematic, in that the
zrl->zr_owner got changed to other task, and that task exits, freeing
the task_struct. This should be very unlikely, as the other task need to
zrl_remove and exit between the dereferencing zr->zr_owner and
zr->zr_owner->pid. Nevertheless, we'll deal with it as well.

To fix the zrl->zr_caller issue, instead of copy the string content, we
just copy the pointer, this is safe because it always points to
__func__, which is static. As for the zrl->zr_owner issue, we pass in
curthread instead of using zrl->zr_owner.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7291
2018-03-12 11:27:02 -07:00
..
2018-01-25 13:40:38 -08:00
2018-02-13 14:54:54 -08:00
2017-06-30 11:11:01 -07:00
2018-01-08 09:52:36 -08:00
2017-10-05 19:28:00 -07:00
2016-01-08 15:08:19 -08:00
2018-02-13 14:54:54 -08:00
2018-02-13 14:54:54 -08:00
2014-07-29 10:55:29 -07:00
2018-02-13 14:54:54 -08:00
2018-02-08 15:28:18 -08:00
2017-11-15 17:27:01 -08:00
2017-11-15 17:27:01 -08:00
2013-11-04 11:17:48 -08:00
2017-01-03 11:31:18 -06:00
2017-12-07 10:28:50 -08:00
2017-10-11 16:54:48 -04:00
2018-02-13 14:54:54 -08:00
2014-08-13 10:35:00 -07:00
2016-04-21 09:49:25 -07:00
2016-06-07 09:16:52 -07:00
2017-11-15 17:27:01 -08:00
2016-06-24 13:13:21 -07:00
2018-02-13 14:54:54 -08:00
2018-01-25 13:40:38 -08:00
2015-01-06 16:53:24 -08:00
2017-01-03 11:31:18 -06:00
2017-07-13 13:54:00 -04:00
2011-02-10 09:21:43 -08:00
2013-11-04 10:55:25 -08:00
2018-01-25 13:40:38 -08:00
2018-02-13 14:54:54 -08:00
2018-02-08 15:28:18 -08:00
2018-02-08 15:28:18 -08:00
2018-02-13 14:54:54 -08:00
2017-03-10 09:51:33 -08:00
2013-12-18 16:46:35 -08:00
2017-03-10 09:51:33 -08:00
2017-03-10 09:51:33 -08:00
2018-02-13 14:54:54 -08:00
2017-03-10 09:51:33 -08:00
2018-02-13 14:54:54 -08:00
2017-03-10 09:51:35 -08:00
2018-02-13 14:54:54 -08:00
2017-03-29 12:24:51 -07:00
2017-08-14 10:36:48 -07:00
2016-12-12 10:46:26 -08:00
2017-07-12 13:05:37 -07:00