From owner-svn-src-all@freebsd.org Sun May 29 07:14:53 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4B18CB51D43; Sun, 29 May 2016 07:14:53 +0000 (UTC) (envelope-from jah@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 024A31DBA; Sun, 29 May 2016 07:14:52 +0000 (UTC) (envelope-from jah@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4T7EqVs024080; Sun, 29 May 2016 07:14:52 GMT (envelope-from jah@FreeBSD.org) Received: (from jah@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4T7Eq8L024078; Sun, 29 May 2016 07:14:52 GMT (envelope-from jah@FreeBSD.org) Message-Id: <201605290714.u4T7Eq8L024078@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jah set sender to jah@FreeBSD.org using -f From: "Jason A. Harmening" Date: Sun, 29 May 2016 07:14:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r300948 - stable/10/sys/dev/iicbus X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 May 2016 07:14:53 -0000 Author: jah Date: Sun May 29 07:14:51 2016 New Revision: 300948 URL: https://svnweb.freebsd.org/changeset/base/300948 Log: MFC r300258: iic_rdwr_data->nmsgs is uint32_t, so limit the allowable number of messages to prevent memory exhaustion and short allocations on 32-bit systems. Since iicrdwr is intended to be a workalike of a Linux i2c-dev call, use the same limit of 42 that Linux uses. Also check the return value of copyin(9) to prevent unnecessary allocation in the failure case. Modified: stable/10/sys/dev/iicbus/iic.c stable/10/sys/dev/iicbus/iic.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/iicbus/iic.c ============================================================================== --- stable/10/sys/dev/iicbus/iic.c Sun May 29 07:01:12 2016 (r300947) +++ stable/10/sys/dev/iicbus/iic.c Sun May 29 07:14:51 2016 (r300948) @@ -299,9 +299,16 @@ iicrdwr(struct iic_cdevpriv *priv, struc parent = device_get_parent(iicdev); error = 0; + if (d->nmsgs > IIC_RDRW_MAX_MSGS) + return (EINVAL); + buf = malloc(sizeof(*d->msgs) * d->nmsgs, M_IIC, M_WAITOK); error = copyin(d->msgs, buf, sizeof(*d->msgs) * d->nmsgs); + if (error != 0) { + free(buf, M_IIC); + return (error); + } /* Alloc kernel buffers for userland data, copyin write data */ usrbufs = malloc(sizeof(void *) * d->nmsgs, M_IIC, M_WAITOK | M_ZERO); @@ -317,6 +324,8 @@ iicrdwr(struct iic_cdevpriv *priv, struc m->buf = NULL; if (error != 0) continue; + + /* m->len is uint16_t, so allocation size is capped at 64K. */ m->buf = malloc(m->len, M_IIC, M_WAITOK); if (!(m->flags & IIC_M_RD)) error = copyin(usrbufs[i], m->buf, m->len); Modified: stable/10/sys/dev/iicbus/iic.h ============================================================================== --- stable/10/sys/dev/iicbus/iic.h Sun May 29 07:01:12 2016 (r300947) +++ stable/10/sys/dev/iicbus/iic.h Sun May 29 07:14:51 2016 (r300948) @@ -56,6 +56,8 @@ struct iic_rdwr_data { uint32_t nmsgs; }; +#define IIC_RDRW_MAX_MSGS 42 + #define I2CSTART _IOW('i', 1, struct iiccmd) /* start condition */ #define I2CSTOP _IO('i', 2) /* stop condition */ #define I2CRSTCARD _IOW('i', 3, struct iiccmd) /* reset the card */