From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47ADCC43331 for ; Mon, 11 Nov 2019 18:37:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 13175204FD for ; Mon, 11 Nov 2019 18:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497440; bh=71lSMN3s+ULUntBXqkytyqM8Ok4PqSN8px6hPOw24DU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=QIxTQa1DQHGwcYkL888PeQyaAcan1sNSmwj0oYwddqF+cBBoc4afNDJua3wDenj+d oylxnHmD6V3szuR94W5eMY3ePXRBhEy98RcqyvP24UJfUQCf2SqPmTziDBVrx03MeC 4ZsNidr5SL1Pa0o65wEs/gVsC+YtoFypQCAAHz6w= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728832AbfKKShS (ORCPT ); Mon, 11 Nov 2019 13:37:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:55784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727812AbfKKShI (ORCPT ); Mon, 11 Nov 2019 13:37:08 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A3C321925; Mon, 11 Nov 2019 18:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497427; bh=71lSMN3s+ULUntBXqkytyqM8Ok4PqSN8px6hPOw24DU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CM5fV89mreQq2xc9AU4Lz36DfNmJlv4JxfvOYkRKXQZRO/dYylR+svrDt2DTkUMNV E6odhEoY6sdSKjjyeVTa85mJ7pqW97fPXVtxlvjRmm+bmDGMCmPzlCH75e1YF4THbY DaLAI4MNInafVtxZ6qWR9/KbrFWhCI5XweiRsWfw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Dan Carpenter , Mathieu Poirier Subject: [PATCH 4.14 051/105] misc: pci_endpoint_test: Prevent some integer overflows Date: Mon, 11 Nov 2019 19:28:21 +0100 Message-Id: <20191111181442.731528689@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181421.390326245@linuxfoundation.org> References: <20191111181421.390326245@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter commit 378f79cab12b669928f3a4037f023837ead2ce0c upstream "size + max" can have an arithmetic overflow when we're allocating: orig_src_addr = dma_alloc_coherent(dev, size + alignment, ... I've added a few checks to prevent that. Fixes: 13107c60681f ("misc: pci_endpoint_test: Add support to provide aligned buffer addresses") Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman Signed-off-by: Mathieu Poirier Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pci_endpoint_test.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -226,6 +226,9 @@ static bool pci_endpoint_test_copy(struc u32 src_crc32; u32 dst_crc32; + if (size > SIZE_MAX - alignment) + goto err; + orig_src_addr = dma_alloc_coherent(dev, size + alignment, &orig_src_phys_addr, GFP_KERNEL); if (!orig_src_addr) { @@ -311,6 +314,9 @@ static bool pci_endpoint_test_write(stru size_t alignment = test->alignment; u32 crc32; + if (size > SIZE_MAX - alignment) + goto err; + orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, GFP_KERNEL); if (!orig_addr) { @@ -369,6 +375,9 @@ static bool pci_endpoint_test_read(struc size_t alignment = test->alignment; u32 crc32; + if (size > SIZE_MAX - alignment) + goto err; + orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr, GFP_KERNEL); if (!orig_addr) {