aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Windsor <dave@nullcore.net>2017-08-24 19:57:57 -0400
committerKees Cook <keescook@chromium.org>2018-01-15 15:08:00 -0500
commitab9ee8e38b292f9a6698a4fedbb6ff8d08ce2012 (patch)
tree48ed5e335b8495d83cd2c6fbd6bb64889f567649
parent93070d339d7bc6f6b07b64faf5134fd144e8ec48 (diff)
sctp: Define usercopy region in SCTP proto slab cache
The SCTP socket event notification subscription information need to be copied to/from userspace. In support of usercopy hardening, this patch defines a region in the struct proto slab cache in which userspace copy operations are allowed. Additionally moves the usercopy fields to be adjacent for the region to cover both. example usage trace: net/sctp/socket.c: sctp_getsockopt_events(...): ... copy_to_user(..., &sctp_sk(sk)->subscribe, len) sctp_setsockopt_events(...): ... copy_from_user(&sctp_sk(sk)->subscribe, ..., optlen) sctp_getsockopt_initmsg(...): ... copy_to_user(..., &sctp_sk(sk)->initmsg, len) This region is known as the slab cache's usercopy region. Slab caches can now check that each dynamically sized copy operation involving cache-managed memory falls entirely within the slab's usercopy region. This patch is modified from Brad Spengler/PaX Team's PAX_USERCOPY whitelisting code in the last public patch of grsecurity/PaX based on my understanding of the code. Changes or omissions from the original code are mine and don't reflect the original grsecurity/PaX code. Signed-off-by: David Windsor <dave@nullcore.net> [kees: split from network patch, move struct members adjacent] [kees: add SCTPv6 struct whitelist, provide usage trace] Cc: Vlad Yasevich <vyasevich@gmail.com> Cc: Neil Horman <nhorman@tuxdriver.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: linux-sctp@vger.kernel.org Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org>
-rw-r--r--include/net/sctp/structs.h9
-rw-r--r--net/sctp/socket.c8
2 files changed, 15 insertions, 2 deletions
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 16f949eef52f..6168e3449131 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -202,12 +202,17 @@ struct sctp_sock {
202 /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */ 202 /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
203 __u32 param_flags; 203 __u32 param_flags;
204 204
205 struct sctp_initmsg initmsg;
206 struct sctp_rtoinfo rtoinfo; 205 struct sctp_rtoinfo rtoinfo;
207 struct sctp_paddrparams paddrparam; 206 struct sctp_paddrparams paddrparam;
208 struct sctp_event_subscribe subscribe;
209 struct sctp_assocparams assocparams; 207 struct sctp_assocparams assocparams;
210 208
209 /*
210 * These two structures must be grouped together for the usercopy
211 * whitelist region.
212 */
213 struct sctp_event_subscribe subscribe;
214 struct sctp_initmsg initmsg;
215
211 int user_frag; 216 int user_frag;
212 217
213 __u32 autoclose; 218 __u32 autoclose;
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 014847e25648..efbc8f52c531 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -8470,6 +8470,10 @@ struct proto sctp_prot = {
8470 .unhash = sctp_unhash, 8470 .unhash = sctp_unhash,
8471 .get_port = sctp_get_port, 8471 .get_port = sctp_get_port,
8472 .obj_size = sizeof(struct sctp_sock), 8472 .obj_size = sizeof(struct sctp_sock),
8473 .useroffset = offsetof(struct sctp_sock, subscribe),
8474 .usersize = offsetof(struct sctp_sock, initmsg) -
8475 offsetof(struct sctp_sock, subscribe) +
8476 sizeof_field(struct sctp_sock, initmsg),
8473 .sysctl_mem = sysctl_sctp_mem, 8477 .sysctl_mem = sysctl_sctp_mem,
8474 .sysctl_rmem = sysctl_sctp_rmem, 8478 .sysctl_rmem = sysctl_sctp_rmem,
8475 .sysctl_wmem = sysctl_sctp_wmem, 8479 .sysctl_wmem = sysctl_sctp_wmem,
@@ -8509,6 +8513,10 @@ struct proto sctpv6_prot = {
8509 .unhash = sctp_unhash, 8513 .unhash = sctp_unhash,
8510 .get_port = sctp_get_port, 8514 .get_port = sctp_get_port,
8511 .obj_size = sizeof(struct sctp6_sock), 8515 .obj_size = sizeof(struct sctp6_sock),
8516 .useroffset = offsetof(struct sctp6_sock, sctp.subscribe),
8517 .usersize = offsetof(struct sctp6_sock, sctp.initmsg) -
8518 offsetof(struct sctp6_sock, sctp.subscribe) +
8519 sizeof_field(struct sctp6_sock, sctp.initmsg),
8512 .sysctl_mem = sysctl_sctp_mem, 8520 .sysctl_mem = sysctl_sctp_mem,
8513 .sysctl_rmem = sysctl_sctp_rmem, 8521 .sysctl_rmem = sysctl_sctp_rmem,
8514 .sysctl_wmem = sysctl_sctp_wmem, 8522 .sysctl_wmem = sysctl_sctp_wmem,