• Johannes Berg's avatar
    decnet: fix DN_IFREQ_SIZE · c914523a
    Johannes Berg authored
    BugLink: https://bugs.launchpad.net/bugs/1855313
    
    [ Upstream commit 50c29366 ]
    
    Digging through the ioctls with Al because of the previous
    patches, we found that on 64-bit decnet's dn_dev_ioctl()
    is wrong, because struct ifreq::ifr_ifru is actually 24
    bytes (not 16 as expected from struct sockaddr) due to the
    ifru_map and ifru_settings members.
    
    Clearly, decnet expects the ioctl to be called with a struct
    like
      struct ifreq_dn {
        char ifr_name[IFNAMSIZ];
        struct sockaddr_dn ifr_addr;
      };
    
    since it does
      struct ifreq *ifr = ...;
      struct sockaddr_dn *sdn = (struct sockaddr_dn *)&ifr->ifr_addr;
    
    This means that DN_IFREQ_SIZE is too big for what it wants on
    64-bit, as it is
      sizeof(struct ifreq) - sizeof(struct sockaddr) +
      sizeof(struct sockaddr_dn)
    
    This assumes that sizeof(struct sockaddr) is the size of ifr_ifru
    but that isn't true.
    
    Fix this to use offsetof(struct ifreq, ifr_ifru).
    
    This indeed doesn't really matter much - the result is that we
    copy in/out 8 bytes more than we should on 64-bit platforms. In
    case the "struct ifreq_dn" lands just on the end of a page though
    it might lead to faults.
    
    As far as I can tell, it has been like this forever, so it seems
    very likely that nobody cares.
    Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
    Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
    c914523a
dn_dev.c 32.3 KB