linux-sctp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Kees Cook <kees@kernel.org>
Cc: linux-sctp@vger.kernel.org
Subject: [bug report] sctp: Replace sockaddr with sockaddr_inet in sctp_addr union
Date: Tue, 28 Oct 2025 14:02:43 +0300	[thread overview]
Message-ID: <aQCi09SH9OJtgkXc@stanley.mountain> (raw)

Hello Kees Cook,

Commit 511d10b4c2f9 ("sctp: Replace sockaddr with sockaddr_inet in
sctp_addr union") from Jul 22, 2025 (linux-next), leads to the
following Smatch static checker warnings:

net/sctp/socket.c:396 sctp_do_bind() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
net/sctp/socket.c:851 sctp_send_asconf_del_ip() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
net/sctp/protocol.c:642 sctp_addr_wq_timeout_handler() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
net/sctp/protocol.c:761 sctp_addr_wq_mgmt() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
net/sctp/protocol.c:781 sctp_addr_wq_mgmt() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
net/sctp/sm_sideeffect.c:602 sctp_do_8_2_transport_strike() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
net/sctp/associola.c:489 sctp_assoc_rm_peer() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
net/sctp/associola.c:597 sctp_assoc_add_peer() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
net/sctp/associola.c:1291 sctp_assoc_update_retran_path() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/socket.c:76 send4() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'
drivers/net/wireguard/socket.c:143 send6() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'
drivers/net/wireguard/peer.c:204 kref_release() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/timers.c:47 wg_expired_retransmit_handshake() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/timers.c:65 wg_expired_retransmit_handshake() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/timers.c:97 wg_expired_new_handshake() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/timers.c:130 wg_queued_expired_zero_key_material() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/send.c:30 wg_packet_send_handshake_initiation() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/send.c:90 wg_packet_send_handshake_response() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/send.c:116 wg_packet_send_handshake_cookie() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'
drivers/net/wireguard/send.c:234 wg_packet_send_keepalive() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:105 wg_receive_handshake_packet() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:129 wg_receive_handshake_packet() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:146 wg_receive_handshake_packet() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:151 wg_receive_handshake_packet() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:168 wg_receive_handshake_packet() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:173 wg_receive_handshake_packet() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:359 wg_packet_consume_data_done() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:416 wg_packet_consume_data_done() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:416 wg_packet_consume_data_done() error: '%pIS' expects argument of type struct sockaddr *, argument 6 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:423 wg_packet_consume_data_done() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:429 wg_packet_consume_data_done() error: '%pIS' expects argument of type struct sockaddr *, argument 5 has type 'struct sockaddr_inet*'
drivers/net/wireguard/receive.c:563 wg_packet_receive() error: '%pIS' expects argument of type struct sockaddr *, argument 4 has type 'struct sockaddr_inet*'

net/sctp/socket.c
    850 
--> 851                         pr_debug("%s: keep the last address asoc:%p %pISc at %p\n",
    852                                  __func__, asoc, &asoc->asconf_addr_del_pending->sa,
    853                                  asoc->asconf_addr_del_pending);
    854 

The "asoc->asconf_addr_del_pending" variable is a sctp_addr union defined
like this.

include/net/sctp/structs.h
    51  /* A convenience structure for handling sockaddr structures.
    52   * We should wean ourselves off this.
    53   */
    54  union sctp_addr {
    55          struct sockaddr_inet sa;        /* Large enough for both address families */
    56          struct sockaddr_in v4;
    57          struct sockaddr_in6 v6;
    58  };

Before it was sockaddr but the patch changed it to sockaddr_inet. I think
the 'c' in "%pISc" means it should actually be the sockaddr_in6...  It's
a union so this is all fine...  Should I just silence the warning for
sockaddr_inet?  The code to print it is in lib/vsprintf.c.

lib/vsprintf.c
  1622  static noinline_for_stack
  1623  char *ip_addr_string(char *buf, char *end, const void *ptr,
  1624                       struct printf_spec spec, const char *fmt)
  1625  {
  1626          char *err_fmt_msg;
  1627  
  1628          if (check_pointer(&buf, end, ptr, spec))
  1629                  return buf;
  1630  
  1631          switch (fmt[1]) {
  1632          case '6':
  1633                  return ip6_addr_string(buf, end, ptr, spec, fmt);
  1634          case '4':
  1635                  return ip4_addr_string(buf, end, ptr, spec, fmt);
  1636          case 'S': {
  1637                  const union {
  1638                          struct sockaddr         raw;
  1639                          struct sockaddr_in      v4;
  1640                          struct sockaddr_in6     v6;
  1641                  } *sa = ptr;
  1642  
  1643                  switch (sa->raw.sa_family) {
  1644                  case AF_INET:
  1645                          return ip4_addr_string_sa(buf, end, &sa->v4, spec, fmt);
  1646                  case AF_INET6:
  1647                          return ip6_addr_string_sa(buf, end, &sa->v6, spec, fmt);
  1648                  default:
  1649                          return error_string(buf, end, "(einval)", spec);
  1650                  }}
  1651          }
  1652  
  1653          err_fmt_msg = fmt[0] == 'i' ? "(%pi?)" : "(%pI?)";
  1654          return error_string(buf, end, err_fmt_msg, spec);
  1655  }

regards,
dan carpenter

                 reply	other threads:[~2025-10-28 11:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aQCi09SH9OJtgkXc@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=kees@kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).