Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp861929pxb; Wed, 3 Nov 2021 13:44:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8X/eacC5sVw9O0pwMv1ulT6kt2jEbz4PPUVWE5hl7tZbfNQiTSHIxROdkd2Kppc+iEs5S X-Received: by 2002:a05:6e02:1a07:: with SMTP id s7mr2748724ild.290.1635972250360; Wed, 03 Nov 2021 13:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635972250; cv=none; d=google.com; s=arc-20160816; b=PZ9F9Y8ei5tNqDDwM0u2VPWyp02t1teNsa9NC+N85olutGNk9WJWwXBsw+rtn4iUBP 3/Mcfu8sp2uC2aHNuvoIUT3lVWtZrt9AHK0dZ2Xv5nJ22yLXXRMm44ddozPMtZ1oofG/ eLOfsXePyV19cVJxadRjJE//R7/cYmYU2Ts/ZcLFkHpBQ3dGeewibX/By38wu/Wu7z2y /+9bUXXWCsYGFNJWc2/GdZJdpab4qvTdSGeH1Cu9XWZNUEAaGWdMfCazSw9Kbz2XIbEX YThOvfO9Z410Whdx5Fej9KrToF4yQGa+v/7ak8t+1zYuJyxRL1DR1vjBMq16nsb4f+SN 8n+Q== 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=Iy8BcW2yEN81eZ9A3QB8U2rJKIihcJ4l+Ba/l49vmfg=; b=KNneqxbnmKGwIL+vvN/XjOW6fwvTb/kLankJ4xcuvsrb6+F+UN3dDFsBM3O5FbK1aO xEdwS0aGOxh0UJzCTrrVrs0f+XRFraJq/lSjyk94SmPC5qSnz7lxP68HUF6TrykaTfh2 Nfu7JZU6wze3qwSHs1r6MbNSiseWKPtJo5BEwf31iwL+QdTvoqxYyR6UUQWMmXXQSmYb f+VRZoam58OHc9JHUxkEu9Ho+LpERzpvLbLSrJll6IxJN2PtWEVtIy+CP0Jpj2+eY8WW jcfWeZW2R/Cq/6hAsNFWFbYUAYF5ei/o7L9PvjyNwXd0TV7FOC9BmG30aFlnRCBVxLFr fJOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bky6sLPd; 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 g9si6470201iow.41.2021.11.03.13.43.56; Wed, 03 Nov 2021 13:44:10 -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=Bky6sLPd; 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 S231388AbhKCTMd (ORCPT + 99 others); Wed, 3 Nov 2021 15:12:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31426 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231419AbhKCTMa (ORCPT ); Wed, 3 Nov 2021 15:12:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635966593; 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=Iy8BcW2yEN81eZ9A3QB8U2rJKIihcJ4l+Ba/l49vmfg=; b=Bky6sLPdIXFTfV2s6sMfAvBMn0h+PL4Qy9GbCY48HqSIXgNeVGYZeQqoDBtK+wrTx2v6UJ tG3HaoiuGhpF1WoXpIMPFhSR/A8O/abuUKoAhnqGviE0e5U1Lk/S/LATIi1eWCaad6gYA5 j/DL+sPDGzhjriB+lfJ8jjFa9Vg3Lqc= 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-482-x9HWEJP8M26GlRngDfDrxA-1; Wed, 03 Nov 2021 15:09:52 -0400 X-MC-Unique: x9HWEJP8M26GlRngDfDrxA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E14958799F1; Wed, 3 Nov 2021 19:09:50 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B5733197FC; Wed, 3 Nov 2021 19:09:48 +0000 (UTC) Date: Wed, 3 Nov 2021 20:09:46 +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 v2 2/2] mctp: handle the struct sockaddr_mctp_ext padding field Message-ID: <09f02206829d8595b8c2794686c9b7bdb007fe8a.1635965993.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.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org struct sockaddr_mctp_ext.__smctp_paddin0 has to be checked for being set to zero, otherwise it cannot be utilised in the future. Fixes: 99ce45d5e7dbde39 ("mctp: Implement extended addressing") Signed-off-by: Eugene Syromiatnikov --- net/mctp/af_mctp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/mctp/af_mctp.c b/net/mctp/af_mctp.c index bc88159..871cf62 100644 --- a/net/mctp/af_mctp.c +++ b/net/mctp/af_mctp.c @@ -39,6 +39,13 @@ static bool mctp_sockaddr_is_ok(const struct sockaddr_mctp *addr) return !addr->__smctp_pad0 && !addr->__smctp_pad1; } +static bool mctp_sockaddr_ext_is_ok(const struct sockaddr_mctp_ext *addr) +{ + return !addr->__smctp_pad0[0] && + !addr->__smctp_pad0[1] && + !addr->__smctp_pad0[2]; +} + static int mctp_bind(struct socket *sock, struct sockaddr *addr, int addrlen) { struct sock *sk = sock->sk; @@ -135,7 +142,8 @@ static int mctp_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) DECLARE_SOCKADDR(struct sockaddr_mctp_ext *, extaddr, msg->msg_name); - if (extaddr->smctp_halen > sizeof(cb->haddr)) { + if (!mctp_sockaddr_ext_is_ok(extaddr) || + extaddr->smctp_halen > sizeof(cb->haddr)) { rc = -EINVAL; goto err_free; } @@ -224,6 +232,7 @@ static int mctp_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, msg->msg_namelen = sizeof(*ae); ae->smctp_ifindex = cb->ifindex; ae->smctp_halen = cb->halen; + memset(ae->__smctp_pad0, 0x0, sizeof(ae->__smctp_pad0)); memset(ae->smctp_haddr, 0x0, sizeof(ae->smctp_haddr)); memcpy(ae->smctp_haddr, cb->haddr, cb->halen); } -- 2.1.4