<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Apr 8, 2018 at 12:50 AM, Dmitry V. Levin <span dir="ltr"><<a href="mailto:ldv@altlinux.org" target="_blank">ldv@altlinux.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Sun, Apr 08, 2018 at 12:10:14AM +0800, Zhibin Li wrote:<br>
> *tests/fcntl.c (test_f_owner_ex_type_pid)<br>
> (test_f_owner_ex_umove, test_f_owner_ex_printaddr)<br>
> (test_f_owner_ex): New functions.<br>
> (main): Use test_f_owner_ex.<br>
> ---<br>
> tests/fcntl.c | 45 ++++++++++++++++++++++++++++++<wbr>+++++++++++++++<br>
> 1 file changed, 45 insertions(+)<br>
><br>
> diff --git a/tests/fcntl.c b/tests/fcntl.c<br>
> index 4f62ca2a..e9db81ef 100644<br>
> --- a/tests/fcntl.c<br>
> +++ b/tests/fcntl.c<br>
> @@ -69,12 +69,57 @@ test_flock64(void)<br>
> #endif<br>
> }<br>
><br>
> +static long<br>
> +test_f_owner_ex_type_pid(<wbr>const int cmd, const char *const cmd_name,<br>
> + const int type, const char *const type_name,<br>
> + const pid_t pid)<br>
> +{<br>
> + struct f_owner_ex fo = { .type = type, .pid = pid };<br>
<br>
</span>What if you used TAIL_ALLOC_OBJECT_CONST_PTR to create an object<br>
that cannot be read beyond its end?<br>
<span class="gmail-"><br></span></blockquote><div> Why using TAIL_ALLOC_OBJECT_CONST_PTR here? The purpose seems not</div><div>so explicit to me. Is it about optimization or something else?</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
> +<br>
> + long rc = invoke_test_syscall(cmd, &fo);<br>
> + printf("%s(0, %s, {type=%s, pid=%d}) = %s\n",<br>
> + TEST_SYSCALL_STR, cmd_name, type_name, pid, sprintrc(rc));<br>
> + return rc;<br>
> +}<br>
> +<br>
> +static void<br>
> +test_f_owner_ex_umove(const int type, const char *const type_name, pid_t pid)<br>
> +{<br>
> + long rc = test_f_owner_ex_type_pid(ARG_<wbr>STR(F_SETOWN_EX),<br>
> + type, type_name, pid);<br>
> + if (!rc)<br>
> + test_f_owner_ex_type_pid(ARG_<wbr>STR(F_GETOWN_EX),<br>
> + type, type_name, pid);<br>
> +}<br>
> +<br>
> +static void<br>
> +test_f_owner_ex_printaddr(<wbr>const int cmd, const char *const cmd_name)<br>
> +{<br>
> + long rc = invoke_test_syscall(cmd, (void *const)0x7ffde503d9e8);<br>
> + printf("%s(0, %s, 0x7ffde503d9e8) = %s\n",<br>
> + TEST_SYSCALL_STR, cmd_name, sprintrc(rc));<br>
> +}<br>
<br>
</span>Why this magic constant? What guarantees that it doesn't reference<br>
to a valid mapped memory? How is it expected to work on 32-bit systems?<br>
<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></blockquote><div>I was thinking about using NULL because in some cases the output of printaddr is NULL.</div><div>But when the umoven function can't fetch the specific data from the given address,</div><div> printaddr should print the memory address instead of NULL. I'm a little confused about </div><div>what is expected. Just an invalid mapped memory is OK? As Dmitry mentioned above, what if </div><div>I use TAIL_ALLOC_OBJECT_CONST_PTR here to get a piece of memory at the end and then</div><div>plus a constant(e.g. <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">TAIL_ALLOC_OBJECT_CONST_PTR(struct f_owner_ex, fo); fo + 1)</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">so that it will not be a valid address to fetch the data(in this case, it's struct f_owner_ex).</span></div><div>I'm not so sure about the feasibility of my idea and I'd be thankful if anyone can answer</div><div>my questions.</div><div><br></div><div>By the way, in the file strace/fcntl.c, I found some assignments like const unsigned int cmd = tcp->u_arg[1];</div><div>But I noticed the type of u_arg in struct tcb is kernel_ulong_t. Does this need type casting? If not,</div><div>why is that?</div><div><br></div><div>Thanks,</div><div>Zhibin Li</div></div><br></div></div>