Skip to content

Commit ab9ee8e

Browse files
dwindsorkees
authored andcommitted
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>
1 parent 93070d3 commit ab9ee8e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

include/net/sctp/structs.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,17 @@ struct sctp_sock {
202202
/* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */
203203
__u32 param_flags;
204204

205-
struct sctp_initmsg initmsg;
206205
struct sctp_rtoinfo rtoinfo;
207206
struct sctp_paddrparams paddrparam;
208-
struct sctp_event_subscribe subscribe;
209207
struct sctp_assocparams assocparams;
210208

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+
211216
int user_frag;
212217

213218
__u32 autoclose;

net/sctp/socket.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8470,6 +8470,10 @@ struct proto sctp_prot = {
84708470
.unhash = sctp_unhash,
84718471
.get_port = sctp_get_port,
84728472
.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),
84738477
.sysctl_mem = sysctl_sctp_mem,
84748478
.sysctl_rmem = sysctl_sctp_rmem,
84758479
.sysctl_wmem = sysctl_sctp_wmem,
@@ -8509,6 +8513,10 @@ struct proto sctpv6_prot = {
85098513
.unhash = sctp_unhash,
85108514
.get_port = sctp_get_port,
85118515
.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),
85128520
.sysctl_mem = sysctl_sctp_mem,
85138521
.sysctl_rmem = sysctl_sctp_rmem,
85148522
.sysctl_wmem = sysctl_sctp_wmem,

0 commit comments

Comments
 (0)