From patchwork Thu Sep 5 16:17:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 173170 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp936610ilq; Thu, 5 Sep 2019 09:19:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkXK2/tt/IOL2eSjYK3+hI5YPzL5snQLXUeo0GQw1ASYX04vGgRbypkJn2zfLp63OSkTrs X-Received: by 2002:aa7:8481:: with SMTP id u1mr4941641pfn.3.1567700365615; Thu, 05 Sep 2019 09:19:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567700365; cv=none; d=google.com; s=arc-20160816; b=X3jejoNbti4HRyoRCktWMU8lkljP0b2EI6LkF+Dd7af84dKJdzjYjCR5B5zMOO+x3d RZxqa9Ygr6nAko8/pa/v6QcmpG8zlP/zPK42WcFIEScuvVRBLpbCkCgMXEYjzinQD/XE pjZQnVkyVYJURwPBOR1ioODEKAXhVC42gbZXzEGoTksXjpXhA3wIuGwsHmvHLAQyMgD/ Ko09q+42pfg4/1SKE1ZmDDhGK0b/zz0SFwNBDSIYiN0+t0JhOP1L7gEPk2JPjTJ9A7WC IMljnJLKldbkjyNpkEJitOhbhZIArfYDtV6DVuKtNQLmC+WzmmSNKCZ6fGxO35Y37UUI rBiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=zGhRU3CF0nckn4q3RpFyAUKnMAipsfpJ2Ggo67IAKJc=; b=MkHLXNDWzvqn4COAWX1WtWsZytUtHkE4N1i1C2XxEKR1ebKOTw8ISUnnFm8fMOFplA gQKaTvOP9V0oPmjm/pVs6vgXLAjlVJ8H2FRUdvtthmvqR2Lm3up/FiYff4IQ8odXIrbi JBWDtPk9CZ3tw5KWwzGbU9LWqV4YhlK8CrzGsUqaiblHyu04dheU4LNcRIBWK9EyN9t+ E2k1I45zfXZIwYM1icPNXw9OB6VLzqSlcgaYZmlrU3PJr8MS8eopLQ8Ku2LO21beX2oh CC8U3NsGsKOSvE5rAPc/JVox/W4gLhSHXylNpwclgcSox/hHo7Pt8E6YoObnUl+/puqm hgMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Esj7f4QN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z2si2147873pgv.417.2019.09.05.09.19.25; Thu, 05 Sep 2019 09:19:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Esj7f4QN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388834AbfIEQTY (ORCPT + 28 others); Thu, 5 Sep 2019 12:19:24 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36080 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388173AbfIEQSN (ORCPT ); Thu, 5 Sep 2019 12:18:13 -0400 Received: by mail-pf1-f196.google.com with SMTP id y22so2082709pfr.3 for ; Thu, 05 Sep 2019 09:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zGhRU3CF0nckn4q3RpFyAUKnMAipsfpJ2Ggo67IAKJc=; b=Esj7f4QN25ld+Ovd4UPXhi2gSS9+Lzc1VVLMSaLedss00TUu/574n7510/KARXCZI3 7W6vE5cd7uARf9ipf0Ags1oPwG3CFAYVMe29Tybo5a64c/5svbgUNtDOdTUTjtzJgzsk BBVG0AUZqbY2eMEesm9XN02filAWjn0hrxTZtIA6mzGsPfn9CVvXwJMErc9ztNrFDZlQ hSJdg6l4K5XNAYyr1Od0KnturBe85nLy/GTao8rjSvtfT1nPC/0vFWd+7bbID+jHlLNF uVWRzrdTujIrO+oTLdms5SAw0eB7uKDL1CNjQPdxf+8SUROE+hX1TvIpDFBHgWNZSiuB ++TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zGhRU3CF0nckn4q3RpFyAUKnMAipsfpJ2Ggo67IAKJc=; b=U9h1IAg1u/ZKNm4i0vUAstheCvN6rlN/f4ECDCClb+VlvznpmxsqXtRV0DW/MsIcCg AdbveNx4Yb8g5zEnnaJduFDLFrOaXOpK3Q5JKdLvbKSwjnHpgeboEi6At6rQaMamwPSc nkZxeJDEQia2XG8kwets89FuWt9C//X7IMb90eEQLVeIJIATzcBYlzoHo2LtdjBN8fGy HOQGht9YqjWHGW7GXOLVa2oWA/bf+CiU4Mzk8OI6fR4QYB4bBVi3UYrtf5zNJ52Xv7gF D/DaPDqyVBhkiaMYLFt9Y/7ZPZoqZX5MUgOro12so1CQdqWbusZ2tNHL1hJVMlGT2gm4 7HDw== X-Gm-Message-State: APjAAAUisvglXK+u7uHG+rudAbnzkBbpNi+Z70/tx/wTw8Pm5OJYCfuR CaTPmI3YMvIeaLxK/lPaGEIaCA== X-Received: by 2002:a63:5f01:: with SMTP id t1mr3605020pgb.200.1567700292199; Thu, 05 Sep 2019 09:18:12 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id m129sm6324005pga.39.2019.09.05.09.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2019 09:18:11 -0700 (PDT) From: Mathieu Poirier To: stable@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pci@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [BACKPORT 4.14.y 09/18] misc: pci_endpoint_test: Prevent some integer overflows Date: Thu, 5 Sep 2019 10:17:50 -0600 Message-Id: <20190905161759.28036-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190905161759.28036-1-mathieu.poirier@linaro.org> References: <20190905161759.28036-1-mathieu.poirier@linaro.org> 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 --- drivers/misc/pci_endpoint_test.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.17.1 diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c index 9849bf183299..504fa680825d 100644 --- a/drivers/misc/pci_endpoint_test.c +++ b/drivers/misc/pci_endpoint_test.c @@ -226,6 +226,9 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size) 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(struct pci_endpoint_test *test, size_t size) 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(struct pci_endpoint_test *test, size_t size) 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) {