Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp220143pxb; Mon, 13 Sep 2021 17:29:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylbYB2CzRgNsM1yZTfntmF4vjCfFxvOPiWR2XENmXSkpheHKeaWhZCBUxGD3r/kAAbUbj4 X-Received: by 2002:a17:906:f74f:: with SMTP id jp15mr13211257ejb.423.1631579394145; Mon, 13 Sep 2021 17:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631579394; cv=none; d=google.com; s=arc-20160816; b=kuZdx79xIApBRHJG8C80q0DvhFJXezIGU1eeptqQOoKnG1D4ZIoQMXKSP5aKZsQlWP Frmf7wlNAZuNyfKrTq+cj426Ccyaa/532bPzSh9jSFyMEba7fSVDevuXMQBFqIVP4qo4 WluGdAUWrpawjxuKWQZalEm5ZTAxt7tcvDH7QhK+nO9EsOrJrNaiRtDfdXP/orlLf1B6 MDFEwIET27lPQDqZ02TmOPDhfBlKUsxOhFttXgz+szTG7p3iQwnGwdccGc9OL2NC9h4Z U+fwVa6XPgQJMiJwcdyD294QVm3LVh67z5ffAUb1RMdEUq0p/w/95ojAzorFviF01h+L MAIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JgMGUaM7SYiWw7/TqQRWDLESI0Nr04e4nCRPILvpb+8=; b=BYum02InuFAYWA7M6y8SXLCj3KGhtZTkeWAy0hqKVvxG8uvH5ZtbBmgiwZVXjnBf50 IHTsTnt+cP5YF/vaaRIkuTXOgbOSaflVEsKLvqCPlUKHZIk7ajrHQBRQ/XfEZHTcKvX8 HaQGg79xRQc9lmUsoLJatNrKBHvpGiFjvY3E4gpVAjqxnYSphYNeRz8lZVfLHrk1KpJ4 qpZpbxnmlii9nfD9D5W4WQ4OVntiuMtrqkrHy0t8fW+AoP6+Fy1qOaYMYq5ArTF1mN/y 0H8oJTX/ULkSwWNACAtdzGTZUYtZptm4fHN76xBoimdXLYz5VPIkJrZLqTgicPzFVTlJ m4xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JNR2pr3F; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g4si8787170edb.272.2021.09.13.17.29.29; Mon, 13 Sep 2021 17:29:54 -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=@linuxfoundation.org header.s=korg header.b=JNR2pr3F; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244959AbhIMOQW (ORCPT + 99 others); Mon, 13 Sep 2021 10:16:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:60358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241402AbhIMONS (ORCPT ); Mon, 13 Sep 2021 10:13:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F86461354; Mon, 13 Sep 2021 13:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540587; bh=1SzleJ2zTAGKhV/CRYpfEc03b9xHuP+Ub5N/JYZLyXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JNR2pr3Fg/QrENcbuel35xM1g5epBzw/KRenzjQZn6yErvaL4uUfWVMFtIwjRPOjj rF+HzcAENf+fUH6AN1a1re5yPvvwLBiHePQ3Aj/rNuIgQFhKfjfedplzboZMjjZC1E R6AvDMjyVSn5FqMeL4PsMLBdZQ5ScrfBkr58G/pI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "David S. Miller" , Sasha Levin Subject: [PATCH 5.13 254/300] net: qrtr: make checks in qrtr_endpoint_post() stricter Date: Mon, 13 Sep 2021 15:15:15 +0200 Message-Id: <20210913131117.930610395@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit aaa8e4922c887ff47ad66ef918193682bccc1905 ] These checks are still not strict enough. The main problem is that if "cb->type == QRTR_TYPE_NEW_SERVER" is true then "len - hdrlen" is guaranteed to be 4 but we need to be at least 16 bytes. In fact, we can reject everything smaller than sizeof(*pkt) which is 20 bytes. Also I don't like the ALIGN(size, 4). It's better to just insist that data is needs to be aligned at the start. Fixes: 0baa99ee353c ("net: qrtr: Allow non-immediate node routing") Signed-off-by: Dan Carpenter Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/qrtr/qrtr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 52b7f6490d24..2e732ea2b82f 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -493,7 +493,7 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) goto err; } - if (!size || len != ALIGN(size, 4) + hdrlen) + if (!size || size & 3 || len != size + hdrlen) goto err; if (cb->dst_port != QRTR_PORT_CTRL && cb->type != QRTR_TYPE_DATA && @@ -506,8 +506,12 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) if (cb->type == QRTR_TYPE_NEW_SERVER) { /* Remote node endpoint can bridge other distant nodes */ - const struct qrtr_ctrl_pkt *pkt = data + hdrlen; + const struct qrtr_ctrl_pkt *pkt; + if (size < sizeof(*pkt)) + goto err; + + pkt = data + hdrlen; qrtr_node_assign(node, le32_to_cpu(pkt->server.node)); } -- 2.30.2