Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1328096

Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code

From Rainer Weikusat <rweikusat@mobileactivedefense.com>
Newsgroups linux.kernel
Subject Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code
Date 2016-02-05 23:10 +0100
Message-ID <qYWJJ-67T-7@gated-at.bofh.it> (permalink)
References <qYTLQ-3XC-11@gated-at.bofh.it> <qYUHV-4BV-25@gated-at.bofh.it> <qYURz-4Vm-5@gated-at.bofh.it> <qYVXk-5zO-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Rainer Weikusat <rw@doppelsaurus.mobileactivedefense.com> writes:
> Joseph Salisbury <joseph.salisbury@canonical.com> writes:
>> On 02/05/2016 02:59 PM, Rainer Weikusat wrote:
>
> [recvmsg w/o iovecs returning ENOTSUP for CMSG requests]

[...]

> There are more problems wrt handling control-message only reads in this
> code.

[...]

> it will return without an error but also without credentials if the

[...]

> because the following
>
> mutex_lock(&u->readlock);
> continue;
>
> will cause the
>
> do {
> } while (size)
>
> loop condition to be evaluated and since size is 0 (AIUI), the loop will
> terminate immediately.

As I suspected, the test program included below doesn't really receive
the credentials (tested with a 4.5.0-rc2-net w/ the previous patch
applied). As that's a minor, additional problem, I'll fix that, too.

---
#define _GNU_SOURCE
    
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    enum { server, client, size };
    int socket_fd[size];
    int const opt = 1;

    assert(socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fd) == 0);
    assert(setsockopt(socket_fd[server], SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt)) != -1);

    char const msg[] = "A random message";

    if (fork() == 0) {
	sleep(1);
	send(socket_fd[client], msg, sizeof msg, MSG_DONTWAIT | MSG_NOSIGNAL);

	_exit(0);
    }

    union {
        struct cmsghdr cmh;
        char control[CMSG_SPACE(sizeof(struct ucred))];
    } control_un;

    control_un.cmh.cmsg_len = CMSG_LEN(sizeof(struct ucred));
    control_un.cmh.cmsg_level = SOL_SOCKET;
    control_un.cmh.cmsg_type = SCM_CREDENTIALS;

    struct msghdr msgh;
    msgh.msg_name = NULL;
    msgh.msg_namelen = 0;
    msgh.msg_iov = NULL;
    msgh.msg_iovlen = 0;
    msgh.msg_control = control_un.control;
    msgh.msg_controllen = sizeof(control_un.control);

    if (recvmsg(socket_fd[server], &msgh, MSG_PEEK) == -1)
    {
        printf("Error: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }
    else
    {
	struct ucred *ucred;
	
        printf("Success?\n");

	ucred = (void *)CMSG_DATA(&control_un.cmh);
	printf("...  pid %ld, uid %d, gid %d\n",
	       (long)ucred->pid, ucred->uid, ucred->gid);
    }

    return 0;
}

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream  receive code Joseph Salisbury <joseph.salisbury@canonical.com> - 2016-02-05 20:00 +0100
  Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-05 21:00 +0100
    Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in  stream receive code Joseph Salisbury <joseph.salisbury@canonical.com> - 2016-02-05 21:10 +0100
      Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-05 22:20 +0100
        Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-05 23:10 +0100
  Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-05 22:50 +0100
    Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in  stream receive code Eric Dumazet <eric.dumazet@gmail.com> - 2016-02-06 00:10 +0100
      Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-07 19:50 +0100
        Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-07 21:40 +0100
        Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-07 23:30 +0100
          Re: [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in  stream receive code Eric Dumazet <eric.dumazet@gmail.com> - 2016-02-08 04:40 +0100
  [PATCH] af_unix: Don't set err in unix_stream_read_generic unless there was an error Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-05 23:40 +0100
    Re: [PATCH] af_unix: Don't set err in unix_stream_read_generic unless there was an error Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-07 20:30 +0100
      [PATCH] af_unix: Don't set err in unix_stream_read_generic unless there was an error Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-08 16:40 +0100
        Re: [PATCH] af_unix: Don't set err in unix_stream_read_generic unless there was an error Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-08 19:10 +0100
          [PATCH] af_unix: Don't set err in unix_stream_read_generic unless there was an error Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2016-02-08 19:50 +0100
        Re: [PATCH] af_unix: Don't set err in unix_stream_read_generic unless  there was an error Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2016-02-08 19:40 +0100

csiph-web