On 09/01/18(Tue) 00:42, Alexander Bluhm wrote:
> On Mon, Jan 08, 2018 at 03:50:14PM +0100, Martin Pieuchot wrote:
> > ok?
> 
> OK bluhm@ with a few remarks.

visa@ pointed out that since all the writes are done under the socket
lock it is enough to use an aligned int32 variable.  So here's an
updated diff that address your comments.

Index: kern/kern_pledge.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_pledge.c,v
retrieving revision 1.227
diff -u -p -r1.227 kern_pledge.c
--- kern/kern_pledge.c  8 Jan 2018 11:54:28 -0000       1.227
+++ kern/kern_pledge.c  9 Jan 2018 10:17:28 -0000
@@ -1337,7 +1337,7 @@ pledge_sockopt(struct proc *p, int set, 
 }
 
 int
-pledge_socket(struct proc *p, int domain, int state)
+pledge_socket(struct proc *p, int domain, unsigned int state)
 {
        if (! ISSET(p->p_p->ps_flags, PS_PLEDGE))
                return 0;
Index: kern/uipc_socket.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_socket.c,v
retrieving revision 1.213
diff -u -p -r1.213 uipc_socket.c
--- kern/uipc_socket.c  2 Jan 2018 12:54:07 -0000       1.213
+++ kern/uipc_socket.c  9 Jan 2018 10:14:21 -0000
@@ -1248,7 +1248,7 @@ somove(struct socket *so, int wait)
        u_long           len, off, oobmark;
        long             space;
        int              error = 0, maxreached = 0;
-       short            state;
+       unsigned int     state;
 
        soassertlocked(so);
 
Index: kern/uipc_syscalls.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v
retrieving revision 1.161
diff -u -p -r1.161 uipc_syscalls.c
--- kern/uipc_syscalls.c        2 Jan 2018 06:38:45 -0000       1.161
+++ kern/uipc_syscalls.c        9 Jan 2018 10:17:39 -0000
@@ -83,7 +83,8 @@ sys_socket(struct proc *p, void *v, regi
        struct file *fp;
        int type = SCARG(uap, type);
        int domain = SCARG(uap, domain);
-       int fd, error, ss = 0;
+       int fd, error;
+       unsigned int ss = 0;
 
        if ((type & SOCK_DNS) && !(domain == AF_INET || domain == AF_INET6))
                return (EINVAL);
Index: netinet/tcp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
retrieving revision 1.162
diff -u -p -r1.162 tcp_usrreq.c
--- netinet/tcp_usrreq.c        1 Dec 2017 10:33:33 -0000       1.162
+++ netinet/tcp_usrreq.c        9 Jan 2018 10:15:30 -0000
@@ -583,7 +583,7 @@ tcp_attach(struct socket *so, int proto)
        inp = sotoinpcb(so);
        tp = tcp_newtcpcb(inp);
        if (tp == NULL) {
-               int nofd = so->so_state & SS_NOFDREF;   /* XXX */
+               unsigned int nofd = so->so_state & SS_NOFDREF;  /* XXX */
 
                so->so_state &= ~SS_NOFDREF;    /* don't free the socket yet */
                in_pcbdetach(inp);
Index: netinet6/ip6_output.c
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_output.c,v
retrieving revision 1.232
diff -u -p -r1.232 ip6_output.c
--- netinet6/ip6_output.c       1 Sep 2017 15:05:31 -0000       1.232
+++ netinet6/ip6_output.c       9 Jan 2018 10:16:10 -0000
@@ -1033,12 +1033,12 @@ int
 ip6_ctloutput(int op, struct socket *so, int level, int optname,
     struct mbuf *m)
 {
-       int privileged, optdatalen, uproto;
+       int optdatalen, uproto;
        void *optdata;
        struct inpcb *inp = sotoinpcb(so);
        int error, optval;
        struct proc *p = curproc; /* For IPSec and rdomain */
-       u_int rtid = 0;
+       u_int privileged, rtid = 0;
 
        error = optval = 0;
 
Index: sys/pledge.h
===================================================================
RCS file: /cvs/src/sys/sys/pledge.h,v
retrieving revision 1.33
diff -u -p -r1.33 pledge.h
--- sys/pledge.h        12 Dec 2017 01:12:34 -0000      1.33
+++ sys/pledge.h        9 Jan 2018 10:17:45 -0000
@@ -126,7 +126,7 @@ int pledge_chown(struct proc *p, uid_t, 
 int    pledge_adjtime(struct proc *p, const void *v);
 int    pledge_sendit(struct proc *p, const void *to);
 int    pledge_sockopt(struct proc *p, int set, int level, int optname);
-int    pledge_socket(struct proc *p, int domain, int state);
+int    pledge_socket(struct proc *p, int domain, unsigned int state);
 int    pledge_ioctl(struct proc *p, long com, struct file *);
 int    pledge_ioctl_drm(struct proc *p, long com, dev_t device);
 int    pledge_ioctl_vmm(struct proc *p, long com);
Index: sys/socketvar.h
===================================================================
RCS file: /cvs/src/sys/sys/socketvar.h,v
retrieving revision 1.81
diff -u -p -r1.81 socketvar.h
--- sys/socketvar.h     2 Jan 2018 12:54:07 -0000       1.81
+++ sys/socketvar.h     9 Jan 2018 10:08:53 -0000
@@ -51,12 +51,12 @@ TAILQ_HEAD(soqhead, socket);
  * private data and error information.
  */
 struct socket {
+       const struct protosw *so_proto; /* protocol handle */
+       void    *so_pcb;                /* protocol control block */
+       u_int   so_state;               /* internal state flags SS_*, below */
        short   so_type;                /* generic type, see socket.h */
        short   so_options;             /* from socket call, see socket.h */
        short   so_linger;              /* time to linger while closing */
-       short   so_state;               /* internal state flags SS_*, below */
-       void    *so_pcb;                /* protocol control block */
-       const struct protosw *so_proto; /* protocol handle */
 /*
  * Variables for connection queueing.
  * Socket where accepts occur is so_head in all subsidiary sockets.
@@ -77,7 +77,7 @@ struct socket {
        short   so_qlen;                /* number of connections on so_q */
        short   so_qlimit;              /* max number queued connections */
        short   so_timeo;               /* connection timeout */
-       u_short so_error;               /* error affecting connection */
+       u_int   so_error;               /* error affecting connection */
        pid_t   so_pgid;                /* pgid for signals */
        uid_t   so_siguid;              /* uid of process who set so_pgid */
        uid_t   so_sigeuid;             /* euid of process who set so_pgid */
@@ -190,10 +190,6 @@ static inline long
 sbspace(struct socket *so, struct sockbuf *sb)
 {
        KASSERT(sb == &so->so_rcv || sb == &so->so_snd);
-#if 0
-       /* XXXSMP kqueue_scan() calling filt_sowrite() cannot sleep. */
-       soassertlocked(so);
-#endif
        return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
 }
 

Reply via email to