]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - net/ipv4/raw.c
Merge tag 'usercopy-v4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
[linux.git] / net / ipv4 / raw.c
index 1b6fa4195ac952c8040f80d417cb26773fa6fe32..9b367fc48d7dde553ae5972481d813c7d313ddb9 100644 (file)
@@ -513,11 +513,18 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
        int err;
        struct ip_options_data opt_copy;
        struct raw_frag_vec rfv;
+       int hdrincl;
 
        err = -EMSGSIZE;
        if (len > 0xFFFF)
                goto out;
 
+       /* hdrincl should be READ_ONCE(inet->hdrincl)
+        * but READ_ONCE() doesn't work with bit fields.
+        * Doing this indirectly yields the same result.
+        */
+       hdrincl = inet->hdrincl;
+       hdrincl = READ_ONCE(hdrincl);
        /*
         *      Check the flags.
         */
@@ -593,7 +600,7 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
                /* Linux does not mangle headers on raw sockets,
                 * so that IP options + IP_HDRINCL is non-sense.
                 */
-               if (inet->hdrincl)
+               if (hdrincl)
                        goto done;
                if (ipc.opt->opt.srr) {
                        if (!daddr)
@@ -610,17 +617,30 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
                        ipc.oif = inet->mc_index;
                if (!saddr)
                        saddr = inet->mc_addr;
-       } else if (!ipc.oif)
+       } else if (!ipc.oif) {
                ipc.oif = inet->uc_index;
+       } else if (ipv4_is_lbcast(daddr) && inet->uc_index) {
+               /* oif is set, packet is to local broadcast and
+                * and uc_index is set. oif is most likely set
+                * by sk_bound_dev_if. If uc_index != oif check if the
+                * oif is an L3 master and uc_index is an L3 slave.
+                * If so, we want to allow the send using the uc_index.
+                */
+               if (ipc.oif != inet->uc_index &&
+                   ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk),
+                                                             inet->uc_index)) {
+                       ipc.oif = inet->uc_index;
+               }
+       }
 
        flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos,
                           RT_SCOPE_UNIVERSE,
-                          inet->hdrincl ? IPPROTO_RAW : sk->sk_protocol,
+                          hdrincl ? IPPROTO_RAW : sk->sk_protocol,
                           inet_sk_flowi_flags(sk) |
-                           (inet->hdrincl ? FLOWI_FLAG_KNOWN_NH : 0),
+                           (hdrincl ? FLOWI_FLAG_KNOWN_NH : 0),
                           daddr, saddr, 0, 0, sk->sk_uid);
 
-       if (!inet->hdrincl) {
+       if (!hdrincl) {
                rfv.msg = msg;
                rfv.hlen = 0;
 
@@ -645,7 +665,7 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
                goto do_confirm;
 back_from_confirm:
 
-       if (inet->hdrincl)
+       if (hdrincl)
                err = raw_send_hdrinc(sk, &fl4, msg, len,
                                      &rt, msg->msg_flags, &ipc.sockc);
 
@@ -1114,7 +1134,6 @@ static int raw_v4_seq_open(struct inode *inode, struct file *file)
 }
 
 static const struct file_operations raw_seq_fops = {
-       .owner   = THIS_MODULE,
        .open    = raw_v4_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,