Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp237259pxj; Tue, 18 May 2021 02:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8H2yBtezwZm5qwLTrnxOYLwOijnlxy/5tgRGQox+pmvt0r1A5K2RhCmI55kUB9xvanz6t X-Received: by 2002:aa7:cd46:: with SMTP id v6mr5705926edw.16.1621328866817; Tue, 18 May 2021 02:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621328866; cv=none; d=google.com; s=arc-20160816; b=YFSwl6K6yicKF3f6xWPBGsyekEU2jXWejO9kIcrTHIvHUejh/SGspJZB8qGEWX6jam hKDIhHZ17XKIN6Csn1Qgecu7DkZJOlFi7UWEsKl46c2TtiJNbFWRJcfs9gQSJLOA3Fs/ Ww8jdUIUM/MQ+o8+d8fMi+/teqX/SfcNHFCkXr2fz9F/ZXSrpx3YR4F5OPo4SBjxfvwG OL8tjD5yXl9oh5rYm/rTmEeWwbMj44uxsGrLcjn49j75PkKVkMwt4u/pYoFS9BdGnNFN BKSSx4JZXWfjhMt2inUAeE6gFynWw2Mfpo8krUMjLcglQzxEcDdLvtEVsyooz2Bkv5Wc j+cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mhJNtjIjh4RxRQaMdNlHUCv26BBt/Hig1FeYjjYr3+s=; b=bZfAsU6nB+N5orOE4Zm/iXp9WTNuZIlSKYGU7KxaUEm+qXdF2l35G1Le0V9g1ukG5A lPNIab6P4Sqwgcpuzy3u2vTismcXVHEidNbL6dbo7IeHnAhuwv7RE3+WEYBqG6XQvq6v y4ar4yP+IKgVNGqjHvmo7mQe1z+z6LMJF7VeSo9DFFp10ZYGP3b/bGtVlKccQM3uQjz9 rSbEOHpe1K1S9ZQRj8NII3o9bvtZw+t080C6JKj4AF9qosqO0D9sjly72d6gwOMSO/c3 jpjBPko5c8I8UQuSH19RptaUEE7S1nvbG2jk5HarSu4F7pxDHQs4ardtHAvB9FRMLqgt ZyUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mn8mkZMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w24si8243932eje.665.2021.05.18.02.07.23; Tue, 18 May 2021 02:07:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mn8mkZMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242930AbhEQPFA (ORCPT + 99 others); Mon, 17 May 2021 11:05:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:51038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241772AbhEQOx4 (ORCPT ); Mon, 17 May 2021 10:53:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A8AE619A3; Mon, 17 May 2021 14:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261458; bh=fxnDPLlPWYLf9/KzTkxHvikDC9lWN6ga0dBvtKr5d2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mn8mkZMHuj59bkLXOiQ+vfjRcmuir6Yui/QO15RbPntNlsEfUplb7G51owUHg1faN iNVMHvRW/Rz586uUti9y3qUuS2Ci1L4kV7ufMrgtdY4YgKGTBJgvqZpURuKUhkjczR aCffUlfitXt/6IYl87bfk0plPimFUyjMOgzWD/+o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+ffb0b3ffa6cfbc7d7b3f@syzkaller.appspotmail.com, Wolfram Sang , Wolfram Sang , Sasha Levin Subject: [PATCH 5.10 022/289] i2c: bail out early when RDWR parameters are wrong Date: Mon, 17 May 2021 15:59:07 +0200 Message-Id: <20210517140305.924508510@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wolfram Sang [ Upstream commit 71581562ee36032d2d574a9b23ad4af6d6a64cf7 ] The buggy parameters currently get caught later, but emit a noisy WARN. Userspace should not be able to trigger this, so add similar checks much earlier. Also avoids some unneeded code paths, of course. Apply kernel coding stlye to a comment while here. Reported-by: syzbot+ffb0b3ffa6cfbc7d7b3f@syzkaller.appspotmail.com Tested-by: syzbot+ffb0b3ffa6cfbc7d7b3f@syzkaller.appspotmail.com Signed-off-by: Wolfram Sang Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/i2c-dev.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 6ceb11cc4be1..6ef38a8ee95c 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -440,8 +440,13 @@ static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) sizeof(rdwr_arg))) return -EFAULT; - /* Put an arbitrary limit on the number of messages that can - * be sent at once */ + if (!rdwr_arg.msgs || rdwr_arg.nmsgs == 0) + return -EINVAL; + + /* + * Put an arbitrary limit on the number of messages that can + * be sent at once + */ if (rdwr_arg.nmsgs > I2C_RDWR_IOCTL_MAX_MSGS) return -EINVAL; -- 2.30.2