Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3277993pxb; Mon, 1 Nov 2021 11:00:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnV+GDcd6OyRj+86XEQl+69VhmZURDUqI2dtAZZuv/wvLz4eBW/RSNHSTUlc2t06CU7pTI X-Received: by 2002:a17:907:1c85:: with SMTP id nb5mr3475501ejc.502.1635789632915; Mon, 01 Nov 2021 11:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635789632; cv=none; d=google.com; s=arc-20160816; b=PntIiXY8P+LSSiFYe1YFbaOeIyhQSR6WNHXPnwnvBl5rFt0zDZBMZujZBA2vVpgrV7 8pXDF9zRc0RHnThcEjUhdJHzLU1rLdTUpO3sWoabxr/U39evZp8jPsxCq5jTCoNWxtwx 3BFQsOSuO1oykon9BycHdf3q72wUCOHTMHE9/XDY5kYHpCQ5w1lTFBLcXKSB98WVHqPg /7r7arLAhG5HDHGUmgrkWddCMfZPZEaysLluQHPMJznNxdxhW4xRp1d896wADuLwP9xE n/DvyCF3QzSMObmRc6kdWYmjj3F1qMPQJk6aLy0J162PT7pYCBMfRANb8OTlViQsCsKr 7+Fg== 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=cdA4HEi03IAhyS4b70T1LHDhUS3p0K2wOZ6l2OOPtzk=; b=r3X2lE6/Y1zl0YvkWJfL+CvNFDTAtHuSc9XgzbWmnaKTxGD/TxEd37HNeQ7Qlb5Grb Y88R4hUx3C0bqOG9WJzQ850MKOAQkvPkAD8521OsAGJw9b+Ou23sd6qfGMkf6/Err1NE JIBOSUrtgQCHsgiqkkJ6/ytJw7DaXKEIIyV0zqwfr9xs5ksNXoFsqNOktZ2QWjWbWwVP 7zBlY43KahxQb96DyNyCVkfJFSsCSOzYFKkjG6I055nzNetVlxWwOY+MtM6i2H5E1OW/ aMikcZqaNfsZ1SzfMsengwbnsDtQd5/4/sh5LM5TLkACYCoUCYGHVZucpO0rnE0AmnEJ AwoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IsMNYOGa; 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 z22si2800772edd.633.2021.11.01.11.00.08; Mon, 01 Nov 2021 11:00:32 -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=IsMNYOGa; 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 S231927AbhKAR5h (ORCPT + 99 others); Mon, 1 Nov 2021 13:57:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47631 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbhKAR5g (ORCPT ); Mon, 1 Nov 2021 13:57:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635789302; 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=cdA4HEi03IAhyS4b70T1LHDhUS3p0K2wOZ6l2OOPtzk=; b=IsMNYOGaxVpwJADNevMW4bf2Anm8d/tKjABn/ESYRVBglL+vVfscOq+ARunhPXziM3ExVx +RuLqwpJnl+PFMe6ay7gkJ8ucyWqqejsQcFR4L9OQ2AYeBtd67PReFSoKjvebCbqtV8vn/ hwYF5NS9Ca6mQWf0q0o12VaRkADOAqs= 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-161-FsODh18NP9CY1-GxhOsuuQ-1; Mon, 01 Nov 2021 13:54:58 -0400 X-MC-Unique: FsODh18NP9CY1-GxhOsuuQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8190010B3940; Mon, 1 Nov 2021 17:54:57 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D50E5D9D3; Mon, 1 Nov 2021 17:54:55 +0000 (UTC) Date: Mon, 1 Nov 2021 18:54:53 +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 2/2] mctp: handle the struct sockaddr_mctp_ext padding field Message-ID: 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.14 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. Complements: 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..6cd1308 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