Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2196079pxb; Fri, 25 Mar 2022 12:50:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGv9yjEjTHxnuACzkJb02pccRltnbXTqGhT8Hzm3s115Xe7p7jB+nntkgwMIkpI8RO2O96 X-Received: by 2002:a05:6a00:8cc:b0:4cb:b981:2676 with SMTP id s12-20020a056a0008cc00b004cbb9812676mr11320531pfu.5.1648237810223; Fri, 25 Mar 2022 12:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648237810; cv=none; d=google.com; s=arc-20160816; b=0EgURky0sTp86IErQZ6dP3gK8+sQJfWySXFtsPI7PHhEGREj+9rGDV/S9kaCjfizPX aqV6zIi99OG4UX1mCgFRPTElxSSYyepyp9NEKcT1BXxq7pZzNdokRtdfkc+ulSlCQHH9 MsXnqdVEnYtjvlZWZL8RtJqUSilZhVCmrKa2e3kHA7BAf3VfHx0Opr2wbEhSAYGnnsap wWVcfTL23TbfDaBKTdc46TlKsxNFvAMKJg3IOdx2u16vK+J35PsWQ7mkPyMSsvuE5j82 D+ADKzl5C3KswdOf0kPgGeiMuI2amfziDi/8pkMr0XNQ8Vy2xpXuu9f9tG5vfves2867 SrGg== 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=2nMvhfEeCRkmencpfloxPj6Dpb+Trt3GwxH0HhubS4I=; b=eBjojhAvseGvVL1bpLZ0g9GDjh/i2aAqNzsZ3Ktz4xInUapqkEJZddeb1Cq3/A9LIw lsavH8HoE80I+zeN8+6GDDocfKAUwkUlhBrSR0fb+gfIe/DrnRW5m6+BmfRNucbVQ5R3 NyDjWd9zOW+rAdAIapuEXEiD2sRhQhire5WDrnBqUx2hPJcltwGMJ5E2K8kPdXyJNTTc JrZ2jgbgYpzpPvbiA0mX5EBYc3jWNrg5XzB+4jGTCSgasMdPK+cKdF5M4pP9L/RJeyQ+ 7kF+Fzc7CLJOL3b6AuLg/AqME4Iqq1YTWTv0IC3YflkqmUy5tPSmw1SFUuB/qu0+w6B5 e2Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bSleGilv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j2-20020a17090aeb0200b001c61582eda2si6198097pjz.165.2022.03.25.12.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:50:10 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bSleGilv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 59A87197FBD; Fri, 25 Mar 2022 11:39:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359471AbiCYPG0 (ORCPT + 99 others); Fri, 25 Mar 2022 11:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359468AbiCYPGX (ORCPT ); Fri, 25 Mar 2022 11:06:23 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B09EA7743; Fri, 25 Mar 2022 08:04:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 7F4CECE2919; Fri, 25 Mar 2022 15:04:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8313DC340E9; Fri, 25 Mar 2022 15:04:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1648220685; bh=Ade0smQZ+bCgusLLhxdZ5bpFPwEb/r/6d9CpN5k5V98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bSleGilvCxrUfUEEq5nmEhNO6JgGZMC083hLBGOy2hnYbS2mzEzbZNyqprd4OKxrw kDcHpp62sBDckZVlmehwtqdlyArCpfTNkchRkLIKFHwdatfayA9/KOXAxr4/qDdE5c E71Q/5leYmazUJrYgc/bkB/oud2im6cOSShOkAfY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jordy Zomer , Krzysztof Kozlowski , "David S. Miller" , Denis Efremov Subject: [PATCH 4.9 01/14] nfc: st21nfca: Fix potential buffer overflows in EVT_TRANSACTION Date: Fri, 25 Mar 2022 16:04:29 +0100 Message-Id: <20220325150415.740148596@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220325150415.694544076@linuxfoundation.org> References: <20220325150415.694544076@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jordy Zomer commit 4fbcc1a4cb20fe26ad0225679c536c80f1648221 upstream. It appears that there are some buffer overflows in EVT_TRANSACTION. This happens because the length parameters that are passed to memcpy come directly from skb->data and are not guarded in any way. Signed-off-by: Jordy Zomer Reviewed-by: Krzysztof Kozlowski Signed-off-by: David S. Miller Signed-off-by: Denis Efremov Signed-off-by: Greg Kroah-Hartman --- drivers/nfc/st21nfca/se.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/drivers/nfc/st21nfca/se.c +++ b/drivers/nfc/st21nfca/se.c @@ -330,6 +330,11 @@ int st21nfca_connectivity_event_received return -ENOMEM; transaction->aid_len = skb->data[1]; + + /* Checking if the length of the AID is valid */ + if (transaction->aid_len > sizeof(transaction->aid)) + return -EINVAL; + memcpy(transaction->aid, &skb->data[2], transaction->aid_len); @@ -339,6 +344,11 @@ int st21nfca_connectivity_event_received return -EPROTO; transaction->params_len = skb->data[transaction->aid_len + 3]; + + /* Total size is allocated (skb->len - 2) minus fixed array members */ + if (transaction->params_len > ((skb->len - 2) - sizeof(struct nfc_evt_transaction))) + return -EINVAL; + memcpy(transaction->params, skb->data + transaction->aid_len + 4, transaction->params_len);