Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3274981pxb; Mon, 1 Nov 2021 10:57:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHyhQ2WT+0vchQpqvuizLOPNm6Uf58dg1Jel5QoXrRSxQ/xZv+zdMmirQQW3uiyrPjGhpD X-Received: by 2002:a17:906:1815:: with SMTP id v21mr39056417eje.218.1635789435335; Mon, 01 Nov 2021 10:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635789435; cv=none; d=google.com; s=arc-20160816; b=qYXU0V5biPQVvN7KqaO8FqbU6qkcb7U0gbUroYVIgsr0HQXnCRGyfWkxLhW/9lf0gw R/N1QQhzmnAjqpa6HYH0CTJyqKpz/j14eQgiPbjCSF2xuJ0wNOYKyHEUjXPyA2xPGwd0 Oet7p1raOAw7JA6xikkFG067YEb+cjIT4DrmrCKqW6siojhg2Uf82WAsRlja2Qh6BwDF oQXTLEPneJgBXEqIGOsGRewJfs/PzJj4ZBM9CmkL3nwqTtRZcjuljTY6hU7uLZNUPfFZ pPLr9c+CLTvOfZxPRx/ldpjt6+pd5WmEz6fcZu+QnuimA4fGHhol5I7suLGZeQuyQmJq daFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=4Xb1aazRNBHuWw3ab+ZKK+D2hPPqz71WYrp6r2ZODTM=; b=CIYBiibXtMkGOy9eh5BIRhdlRNh2Lzggh5xVFfRemwS9PlU4SMBOdB7RTgIB/CEksm 0TGJJ7yQOtO+9ryhZghsGw1ELaoltG8bxv2DpSH5QYs569jTq6d8odqYmP5DeG9yiRn8 dgBxA9uVKCkiPqqvvWo9nQOAhWY7KmDmghkuEodY8wFwdhwd7KQuAmMDowLWyhAZw8G4 GWsFG+eHStLodQRYK89Po3/l/E8Fe6nvXYNhB0iHCl+MarV4MFG0Xd5JVRikL8K1iaUL /axgTAK6q4fD/2DCPw+k6vUSEmesuReEbyV9Zw16fZBrk6KBJJUgkwTSCuq+/5imBtdT rKlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BfV37DwE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s1si28639503ejn.348.2021.11.01.10.56.51; Mon, 01 Nov 2021 10:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BfV37DwE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231841AbhKAR5f (ORCPT + 99 others); Mon, 1 Nov 2021 13:57:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36090 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231826AbhKAR5e (ORCPT ); Mon, 1 Nov 2021 13:57:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635789300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4Xb1aazRNBHuWw3ab+ZKK+D2hPPqz71WYrp6r2ZODTM=; b=BfV37DwEbFYl2ud3sYvnki0p+1rVF9b45n3W0dOkcd2FS+yLz13mB0L5o+zQp73Oyc0b/5 rkwJRU/6e79tFAjZ3xrZY+jqnm05NkrpNhI3IjTc/Ivni9TWE71IkjBArYT9a0GU2956Yz Cl6xFJBuNy1vjtf4BZLyM8U16P5E1JE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-401-lT2rQFEMOBSVsuxq8GkDXw-1; Mon, 01 Nov 2021 13:54:55 -0400 X-MC-Unique: lT2rQFEMOBSVsuxq8GkDXw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30E7A802682; Mon, 1 Nov 2021 17:54:53 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3544A5C1C5; Mon, 1 Nov 2021 17:54:50 +0000 (UTC) Date: Mon, 1 Nov 2021 18:54:49 +0100 From: Eugene Syromiatnikov To: Jeremy Kerr , Matt Johnston Cc: "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/2] mctp: handle the struct sockaddr_mctp padding fields Message-ID: <28f36bbcecc5b28e56cb33ff449c3ae92adebb8c.1635788968.git.esyr@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to have the padding fields actually usable in the future, there have to be checks that user space doesn't supply non-zero garbage there. It is also worth setting these padding fields to zero, unless it is known that they have been already zeroed. Cc: stable@vger.kernel.org # v5.15 Complements: 5a20dd46b8b84593 ("mctp: Be explicit about struct sockaddr_mctp padding") Signed-off-by: Eugene Syromiatnikov --- net/mctp/af_mctp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/mctp/af_mctp.c b/net/mctp/af_mctp.c index d344b02..bc88159 100644 --- a/net/mctp/af_mctp.c +++ b/net/mctp/af_mctp.c @@ -33,6 +33,12 @@ static int mctp_release(struct socket *sock) return 0; } +/* Generic sockaddr checks, padding checks only so far */ +static bool mctp_sockaddr_is_ok(const struct sockaddr_mctp *addr) +{ + return !addr->__smctp_pad0 && !addr->__smctp_pad1; +} + static int mctp_bind(struct socket *sock, struct sockaddr *addr, int addrlen) { struct sock *sk = sock->sk; @@ -52,6 +58,9 @@ static int mctp_bind(struct socket *sock, struct sockaddr *addr, int addrlen) /* it's a valid sockaddr for MCTP, cast and do protocol checks */ smctp = (struct sockaddr_mctp *)addr; + if (!mctp_sockaddr_is_ok(smctp)) + return -EINVAL; + lock_sock(sk); /* TODO: allow rebind */ @@ -87,6 +96,8 @@ static int mctp_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) return -EINVAL; if (addr->smctp_family != AF_MCTP) return -EINVAL; + if (!mctp_sockaddr_is_ok(addr)) + return -EINVAL; if (addr->smctp_tag & ~(MCTP_TAG_MASK | MCTP_TAG_OWNER)) return -EINVAL; @@ -198,11 +209,13 @@ static int mctp_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, addr = msg->msg_name; addr->smctp_family = AF_MCTP; + addr->__smctp_pad0 = 0; addr->smctp_network = cb->net; addr->smctp_addr.s_addr = hdr->src; addr->smctp_type = type; addr->smctp_tag = hdr->flags_seq_tag & (MCTP_HDR_TAG_MASK | MCTP_HDR_FLAG_TO); + addr->__smctp_pad1 = 0; msg->msg_namelen = sizeof(*addr); if (msk->addr_ext) { -- 2.1.4