Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5253609imu; Tue, 15 Jan 2019 14:09:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN41IJdbGx0/6LUevQHCZYJSjQhJgDdjeuC7v7l/WcTm+MSCIn/IS6rGqvZEBTvQE24Sq5S7 X-Received: by 2002:a17:902:b118:: with SMTP id q24mr6421155plr.209.1547590147620; Tue, 15 Jan 2019 14:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547590147; cv=none; d=google.com; s=arc-20160816; b=b8N/LydKljennYTs6+K4f2qmDNFtE0K35mKQwQkAwrUfYfPofaxgYB5FoFlSHCggtI NRXVwdkgxTmBagxcu5aNNTZbY76JdclwRJMke+M5q2g3Tl4W9C/Eu6M1wzL0AE6KGuir NrbwhXQUnng/T66LvjdiHn/3CiuqROAvq3N4Lnac13sf9kPuApWiuiUpVrzzPZzMZ7ac TnnZjkkbKV+riHH+S7/Dae/rUEfmX+Y7DyVmAXT1gevdYSjRRB71QD9jmeD8D9WLx523 wrDnCdv1If7g21LGZEvHa9lX0NsISjuFFLCTlxl7UdX/iCNoI6Y6b6pMeAs2qlqYhhxJ CSgw== 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=isyJHVpNJXv0bOAbcPg2kUBjp3xxVS+LpoksiityWMw=; b=ncdmScx6bDWaJDRfCGzNi/Hx4t+832S0pK2Tz+Ct6xmjKULdBUqrDlqNO4Tg0+NW75 5eFYqh1iVDZXNGc5K/8nlybet7fipP5lE5sVev4lY4N4/hdRmfaJz8WbPpc1d+SapHYF 46wzq99DGty5kYaqoyXBItgTnWsCPXHFmKcHuAPTBT0XhZO3nIyVc6YDhTmuslNNU99t EssYAIit2WhPTkZ87476QhjoVcGk1Eo1191FkYZjvcak7fxFdwWNu9dD7XvnYRGtiajt Hx5sVbnyepO1ew1YYImBajqeObw7blbWv/W85equOsPho8oQa7T3KMNfNqhgRjmWLzDn zw0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a7ajgVkd; 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 w1si4091911pgi.66.2019.01.15.14.08.51; Tue, 15 Jan 2019 14:09:07 -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=a7ajgVkd; 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 S2387896AbfAOQp7 (ORCPT + 99 others); Tue, 15 Jan 2019 11:45:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:35644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387859AbfAOQp4 (ORCPT ); Tue, 15 Jan 2019 11:45:56 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 A753020645; Tue, 15 Jan 2019 16:45:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547570756; bh=36zHSWZ2LZKV7MnaoNIxTbFmx72I29rNkFJv3owyPgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a7ajgVkd5jBXCdN0ai0+Xath/ec/W9YbWjA9a/ph35sJE1PUsdNw4xFz5Ii4SqqEV AQDeFLSssIFFCEOxi84TxRzD+WSEVPCAmZe6RHF2MRO1fLOugj5uRlwpG0bKs89jfH AhQj8y+Z/u4oo6SIEUCcWKdlDXsl3TaXN8+P6Wkw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yi Zeng , Wolfram Sang , stable@kernel.org Subject: [PATCH 4.20 34/57] i2c: dev: prevent adapter retries and timeout being set as minus value Date: Tue, 15 Jan 2019 17:36:15 +0100 Message-Id: <20190115154912.649215053@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115154910.734892368@linuxfoundation.org> References: <20190115154910.734892368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yi Zeng commit 6ebec961d59bccf65d08b13fc1ad4e6272a89338 upstream. If adapter->retries is set to a minus value from user space via ioctl, it will make __i2c_transfer and __i2c_smbus_xfer skip the calling to adapter->algo->master_xfer and adapter->algo->smbus_xfer that is registered by the underlying bus drivers, and return value 0 to all the callers. The bus driver will never be accessed anymore by all users, besides, the users may still get successful return value without any error or information log print out. If adapter->timeout is set to minus value from user space via ioctl, it will make the retrying loop in __i2c_transfer and __i2c_smbus_xfer always break after the the first try, due to the time_after always returns true. Signed-off-by: Yi Zeng [wsa: minor grammar updates to commit message] Signed-off-by: Wolfram Sang Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-dev.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -470,9 +470,15 @@ static long i2cdev_ioctl(struct file *fi data_arg.data); } case I2C_RETRIES: + if (arg > INT_MAX) + return -EINVAL; + client->adapter->retries = arg; break; case I2C_TIMEOUT: + if (arg > INT_MAX) + return -EINVAL; + /* For historical reasons, user-space sets the timeout * value in units of 10 ms. */