Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1618331ybv; Fri, 21 Feb 2020 00:23:35 -0800 (PST) X-Google-Smtp-Source: APXvYqxt2hJv9idu/6shXAPECDsRyXz1vOJ+V3sf9pzKmOGXudIXdE+ME9A2TLxckNwhwhg3lT5g X-Received: by 2002:a05:6830:c9:: with SMTP id x9mr27291445oto.345.1582273415778; Fri, 21 Feb 2020 00:23:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273415; cv=none; d=google.com; s=arc-20160816; b=QHFFArIF3z/Yj7MCh2AG4JQ5Std2bmA68toO+8skikovmfOOdISvyFS4CjZMhKvzqG tDyG5/gwiDtQq75+B1P/xJ0+/zu/ISnhfwATcMPIK0lTi4WpjTlNqbdrp2TRYBwBbitJ kj5k0K+mCldUj8UqPBJe8vxTTuwu1LOGCHm0uQJ2pigYc+EWc/mxdXUZTDXKGMowV4Li EQbXKh760AFzq6HC+yVnS0VXbRWKPfg/Z+uVYcfbgGxO8k/KTM2p5nqEqxk7NEJt6XIY yfxUZr0XcwwAteHYS3uUonHPU9iizbEgb7qBdhz9UNhqhWEA3J8Cbu/uBNNPLGDZDtRP +1uw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DBOUSRjHB5+fAq4R4SBM0PnLwkCTu7VWabgkDmdgVNo=; b=p3uCUQLoMmZpizBLtrDvhKXdZoId+y/FpUlvJVgcrJ4Fq+m/hVl06xMfGXnlm5R3Ut eCq+SuWKCulF+HHQ/raTWN5VWThI+o6PpRhqdLk9h3OCGOteg+/ojg5NncfSdBtiDMJH iMA1PujpT57+m/W/w/Hf0Gwb9pR/jxzL1yzwlg2u9117hIxwpStX0ReNKXKIWM26JCxI UL6RCGIq9hoNlh77dPw23mcrBzme4i8uJsF3bpAoxgmlJRPYd/zvwxoXhxm2ZVGiMtWV ybXVgj6GBTKpySWncqUezR3wsZMqEKsSCoxaJCobXn/hP1BV6wlzsQYJPhtO27jcr658 lsEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qf6AY+0V; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o7si1158828otk.185.2020.02.21.00.23.23; Fri, 21 Feb 2020 00:23:35 -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=qf6AY+0V; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388349AbgBUIWm (ORCPT + 99 others); Fri, 21 Feb 2020 03:22:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:34324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388343AbgBUIWk (ORCPT ); Fri, 21 Feb 2020 03:22:40 -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 3CA782467D; Fri, 21 Feb 2020 08:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273359; bh=rjrhQW09Vso9tajVY7leCL9tNge/xnc21nLf2tfe578=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qf6AY+0V9YVE/qIdl/dSTcOVOErmJoH9f/OFJx8EGVbqzktNEfBlJYAugt5jqMIwz 1JjOxL93eeCuGxW7bDGQird/fwqdmlMGgHebM9EtxTWQVFW9delfBjjCGWFq7D6J3B tOh2RUFlTYPFE1M7JCBacTkKGtp0gguOxVv+JKa0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 142/191] ide: serverworks: potential overflow in svwks_set_pio_mode() Date: Fri, 21 Feb 2020 08:41:55 +0100 Message-Id: <20200221072307.706109376@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@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 [ 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