Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1931764ybv; Fri, 14 Feb 2020 08:26:24 -0800 (PST) X-Google-Smtp-Source: APXvYqz3iCLMHAg69aVWF/bbOxdfWb5qYnUhCan66d1PsBTICCkuShCTDjPs7bFPZdzxivG2DBX8 X-Received: by 2002:a05:6830:1615:: with SMTP id g21mr3039682otr.49.1581697584642; Fri, 14 Feb 2020 08:26:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581697584; cv=none; d=google.com; s=arc-20160816; b=raBNEE1aNQ48jlG0LolH4cTQYh2kH/1d8XR29LN/OOLxR5KoOTGouOqcFXQ/VQ0uiu y0RwGjbNPbbfj47TAZ1ZZGpnr0QebkAfoIDrQDrRFNiXGbWSNhX/jvE6axXBEOM43NQH WFrvQr3xFGP8afu+WH1xDqaLcVd2x14pfOxG7Z2+qZTtiAl4POLJPYCDMQOxN0p3AXxY mJyGMwM4FFYOi8tDZzPrD8Af0nm+hRylGDMAlfBn6EUEVcvCc3crUwsKh+0JULNG+dSe saQ37xnJjpQtHApdMyygPypbfJhSTyKKOgrlZaFfI2pQbbNAjfigVc2lQ0Nv1f/do76o DBDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DBOUSRjHB5+fAq4R4SBM0PnLwkCTu7VWabgkDmdgVNo=; b=v/Q2eLdBHC34xWBbgtMW0ZE6//kvFwGOG2TRxOHfZ9JXaOGeozsKR+bBBMi5HhFoH7 c70R5TpRMBK5YXrDAOD6HH93yNeBVNxAANaD4HSkKwAJ4O/RNdpE60WD4hvOd2UvaLC7 /ZnUst47GeFAa/btB2ckwa7GojI0Uh3s5DANzjp9WLWpOCfp0qsxUyjctJ4XsKAj04y1 xJn4KbunOWwE2SxQTbpDAEK1Hr2Lv0Cm373CjN7a9WAyprTZAgDlWG8sOOLzlVem8Jko knqi6CUT9y6c3bF8aEa0e410V3jSd/a4duCDEXlJkp6kNVlYHodQuI8iy9KfWZC6YmC+ dUAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AhqjtSdk; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v3si3150447otn.140.2020.02.14.08.26.12; Fri, 14 Feb 2020 08:26:24 -0800 (PST) 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=@kernel.org header.s=default header.b=AhqjtSdk; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406211AbgBNQZr (ORCPT + 99 others); Fri, 14 Feb 2020 11:25:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:60082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405688AbgBNQXi (ORCPT ); Fri, 14 Feb 2020 11:23:38 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 954D924779; Fri, 14 Feb 2020 16:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697418; bh=rjrhQW09Vso9tajVY7leCL9tNge/xnc21nLf2tfe578=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AhqjtSdk9vtlA1mDoy+m2l8bMI2Yu3EKlYrAFIMMrUDaeVdqAyt+IOdQ+S8LZjy1u Omu95gBWUdPTMGDs+mYG/t2toiy6dmA3gzUGh4zEjtkOPEbE0YDpRXXQICgEtEJIst tVT9II/CuPXAJmYWpKFUeIYgtog0zxzzE0W7mGwk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dan Carpenter , "David S . Miller" , Sasha Levin , linux-ide@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 108/141] ide: serverworks: potential overflow in svwks_set_pio_mode() Date: Fri, 14 Feb 2020 11:20:48 -0500 Message-Id: <20200214162122.19794-108-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 [ Upstream commit ce1f31b4c0b9551dd51874dd5364654ed4ca13ae ] The "drive->dn" variable is a u8 controlled by root. Signed-off-by: Dan Carpenter Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/ide/serverworks.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c index a97affca18abe..0f57d45484d1d 100644 --- a/drivers/ide/serverworks.c +++ b/drivers/ide/serverworks.c @@ -114,6 +114,9 @@ static void svwks_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) struct pci_dev *dev = to_pci_dev(hwif->dev); const u8 pio = drive->pio_mode - XFER_PIO_0; + if (drive->dn >= ARRAY_SIZE(drive_pci)) + return; + pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]); if (svwks_csb_check(dev)) { @@ -140,6 +143,9 @@ static void svwks_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive) u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0; + if (drive->dn >= ARRAY_SIZE(drive_pci2)) + return; + pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing); pci_read_config_byte(dev, 0x54, &ultra_enable); -- 2.20.1