Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2725484pxj; Mon, 31 May 2021 09:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqrMa9fimfOmSyRuGENf1NmofErdis/oX3ZqQO/PYsRCiuMXmPhoTXbfSA9Ep1+6B0VdfL X-Received: by 2002:a6b:5c18:: with SMTP id z24mr16945006ioh.127.1622477437959; Mon, 31 May 2021 09:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622477437; cv=none; d=google.com; s=arc-20160816; b=LENjb0/E7tr3SwgK+usXgsUAkebs1XOfo/cQTftOec4cwk3bgs38Q2yXzKxo/8F3FT 9ldiMboo/uzWlEJ+RbjaVW/3SMSSvuaDHVsHHgQwRYIh8o2LNh0fphFPZUYLbNWtuVff 5FfzWiIAPyG1RdeEq9M+Jpojd8b/aaMoeI8sD78zhZw8x1Ve77cjBoJQ/Uf1PqHWgvKI pkylGEfOTw7k42FV6PL5tRjMCE/MIY4ABybHxFbFHfX9R53AruRNSsK2Z1LdcXt9mrQX 0rD1VPqIDst8bZzJE83WWs0jh290xPoehsgkeAojnxL5Fl1zYFF1FM/DCAe28XjR9Ky1 FxjA== 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=ob/y6xw09EiOkN+E0gsDy9DyueViXURQuOF1+RQ9pQ8=; b=HYy90XFrgiYEwGdkAlKBiyd9BQCs9koQPK7EmcU/WtdV6UIdtM9PKKpPzVV0IVRQi3 E1pGiV640AaEwJaziLK2OPdsvYmNpe0maSaoOC+6DfuL2rYF1/hO21UGuYDJnQDO1+KF zAKuEvWE6XT+GoZS8lOVBZ+X07HsETDeTbtcs+c7jKhDXOlGQbZQ/FsHsObFIXEjVtqL fRD2fQpY8JM9YCIkjynhVYWni6242hWrcX4BIsqXeejyg46Ggs6KB8IlLf0UdXlMtJ/k 26fi22LyVdnkd6/pngYvnJgh/W+972HCbXp2fAzsNFNv/KPyaf191tVTwhiLkPexRLMl xP0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="R/emltDw"; 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 g4si3091231ilj.40.2021.05.31.09.10.24; Mon, 31 May 2021 09:10:37 -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="R/emltDw"; 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 S232862AbhEaQLL (ORCPT + 99 others); Mon, 31 May 2021 12:11:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:33126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232875AbhEaOha (ORCPT ); Mon, 31 May 2021 10:37:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B77160FE5; Mon, 31 May 2021 13:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469097; bh=krfTaxbOyWqugdtfCJBtYWS9/Y9DDZMOs09uCkuPDQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R/emltDwHG8D3a3Ig1AhQtE1/dvPz+faLHt3dqCt64JsdYPIY1NbhEjRNwamW6BPC NFMzua0idGZICEwSkxgjnrd8seACyYLN3Zo+FisDmsw5SuwXcNkP2v17MPUW56ZFNB H8i/OghnvEDmXEMYLd6RIYawLi56hfE1l1LL0k+0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathias Nyman , Mika Westerberg Subject: [PATCH 5.12 069/296] thunderbolt: dma_port: Fix NVM read buffer bounds and offset issue Date: Mon, 31 May 2021 15:12:04 +0200 Message-Id: <20210531130706.168432752@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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: Mathias Nyman commit b106776080a1cf953a1b2fd50cb2a995db4732be upstream. Up to 64 bytes of data can be read from NVM in one go. Read address must be dword aligned. Data is read into a local buffer. If caller asks to read data starting at an unaligned address then full dword is anyway read from NVM into a local buffer. Data is then copied from the local buffer starting at the unaligned offset to the caller buffer. In cases where asked data length + unaligned offset is over 64 bytes we need to make sure we don't read past the 64 bytes in the local buffer when copying to caller buffer, and make sure that we don't skip copying unaligned offset bytes from local buffer anymore after the first round of 64 byte NVM data read. Fixes: 3e13676862f9 ("thunderbolt: Add support for DMA configuration based mailbox") Cc: stable@vger.kernel.org Signed-off-by: Mathias Nyman Signed-off-by: Mika Westerberg Signed-off-by: Greg Kroah-Hartman --- drivers/thunderbolt/dma_port.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/drivers/thunderbolt/dma_port.c +++ b/drivers/thunderbolt/dma_port.c @@ -366,15 +366,15 @@ int dma_port_flash_read(struct tb_dma_po void *buf, size_t size) { unsigned int retries = DMA_PORT_RETRIES; - unsigned int offset; - - offset = address & 3; - address = address & ~3; do { - u32 nbytes = min_t(u32, size, MAIL_DATA_DWORDS * 4); + unsigned int offset; + size_t nbytes; int ret; + offset = address & 3; + nbytes = min_t(size_t, size + offset, MAIL_DATA_DWORDS * 4); + ret = dma_port_flash_read_block(dma, address, dma->buf, ALIGN(nbytes, 4)); if (ret) { @@ -386,6 +386,7 @@ int dma_port_flash_read(struct tb_dma_po return ret; } + nbytes -= offset; memcpy(buf, dma->buf + offset, nbytes); size -= nbytes;