From nobody Wed Sep 14 17:27:17 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MSS2G2Cmtz4bfwt; Wed, 14 Sep 2022 17:27:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MSS2G1bgjz3RR1; Wed, 14 Sep 2022 17:27:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663176438; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lh1n9/AyqUnej9dZJot/vTbTCf4Pv4yOJlcZ9kc4lzA=; b=rwm7FB83vGupDW7qNASnZS7PGdLAgBxvHDVjqxxTS4wv/A39iLcmFlaHLoS3OKUT9lEHfu ANVAaHbnF0W3liatsg8/NnPFa566kGnPg8ltmQGrhHJfXgkRLw7YrV669gSVrLzHFs6mL1 xuxBDspz9Uh85u53Wcf6xGuorw7j96L9m9j6L+g3FEkS8CZdlMlLhq7yWgvAavBpyCuJPT EeDoq7uW1S/maxPhqYqjuQ0t48fHpTqp/YMSIIpes4FTE2emCrfDfbq3aiSkRgkMlEXR3L NLRGkNo640mj9nu7QcUonL7MN88fbsSQ8tw4UI/yKBOYLa86klvpm9XulcxKqg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MSS2G0Xcdzkn2; Wed, 14 Sep 2022 17:27:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28EHRHil022236; Wed, 14 Sep 2022 17:27:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28EHRHDF022235; Wed, 14 Sep 2022 17:27:17 GMT (envelope-from git) Date: Wed, 14 Sep 2022 17:27:17 GMT Message-Id: <202209141727.28EHRHDF022235@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: c48d0754a053 - stable/13 - CTL: Validate IOCTL parameters. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c48d0754a05334cacbe6cd34871c10f3ef6f4d56 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663176438; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lh1n9/AyqUnej9dZJot/vTbTCf4Pv4yOJlcZ9kc4lzA=; b=PhmmZzQfpjKDE9hjlD2drNIrYgglTLodMAM1mHW3dSZsdJcc+nqbo3l21viNsntxdsmcPI X2qk+fing4/cU+4DKYr4aAWWstFRWdCG9PC286UVD0dqMjEm6jit/DwhlfFItHnXqC+LpT F52zhRG9jDZe43EIGjULvczgwAYU/+2DZd9c81VMS8yJ+zb1W410Nnzqc+mxEIp7g8U7DJ em874MTpkmmJv06/fFzYuKnMuD96+rxmKohjnZWKz1R2pxl6A2BZlzXDpkOBkbFw7515GE 48IedLjhE9clV4m7iyfj+xb24oVHyhKG4uC0YPiPdw/ldMbSsaGsqyaazibYXQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663176438; a=rsa-sha256; cv=none; b=A7/82ar1JlvBIgC84qrCpwAYyHBmZeaDOp4mApnhW7QKjCnEgp7w8eXUdJ9pwvVMaZKhLj nRJ0eVILikMI11vTZvI4LMzHRl7gZtoAZXiQ8r9KBm7KMjkKAtWB5m8lrpxTUDbiVhL4E7 tPiyilKvN33x1ygqHjc3pVk0tYvLzJdcvJkkh1LX310sOo+keM1lOW6GjDkwgQ4nloA1da ma5F/9/qltIX2R63VLQIOAttkh3nodTlSxRKFGZXjNGzNGhBoxXX2mbrL5vH809xdpMUQr +4cu6lBYGfHml+GZU6aisXHUlr0Qhp0hgtokFvOPdZLjrl3D11hAkGmhFKd4kA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=c48d0754a05334cacbe6cd34871c10f3ef6f4d56 commit c48d0754a05334cacbe6cd34871c10f3ef6f4d56 Author: Alexander Motin AuthorDate: 2022-09-07 01:58:27 +0000 Commit: Alexander Motin CommitDate: 2022-09-14 17:27:04 +0000 CTL: Validate IOCTL parameters. It was possible to cause kernel panic by passing too large args_len or non-NULL result_nvl. Though since the /dev/cam/ctl device is accessible only by root and used only by limited number of tools it was not a big problem. PR: 266115 PR: 266136 Reported by: Robert Morris MFC after: 1 week (cherry picked from commit 0586be48a97c5af50ba4f578d33211f81cc57016) --- sys/cam/ctl/ctl.c | 14 ++++++++++++++ sys/cam/ctl/ctl_ioctl.h | 1 + 2 files changed, 15 insertions(+) diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 2083059c6aee..097a5942650e 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -2977,6 +2977,12 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } if (lun_req->args != NULL) { + if (lun_req->args_len > CTL_MAX_ARGS_LEN) { + lun_req->status = CTL_LUN_ERROR; + snprintf(lun_req->error_str, sizeof(lun_req->error_str), + "Too big args."); + break; + } packed = malloc(lun_req->args_len, M_CTL, M_WAITOK); if (copyin(lun_req->args, packed, lun_req->args_len) != 0) { free(packed, M_CTL); @@ -2998,6 +3004,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } else lun_req->args_nvl = nvlist_create(0); + lun_req->result_nvl = NULL; retval = backend->ioctl(dev, cmd, addr, flag, td); nvlist_destroy(lun_req->args_nvl); lun_req->args_nvl = tmp_args_nvl; @@ -3254,6 +3261,12 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } if (req->args != NULL) { + if (req->args_len > CTL_MAX_ARGS_LEN) { + req->status = CTL_LUN_ERROR; + snprintf(req->error_str, sizeof(req->error_str), + "Too big args."); + break; + } packed = malloc(req->args_len, M_CTL, M_WAITOK); if (copyin(req->args, packed, req->args_len) != 0) { free(packed, M_CTL); @@ -3275,6 +3288,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } else req->args_nvl = nvlist_create(0); + req->result_nvl = NULL; if (fe->ioctl) retval = fe->ioctl(dev, cmd, addr, flag, td); else diff --git a/sys/cam/ctl/ctl_ioctl.h b/sys/cam/ctl/ctl_ioctl.h index 49c48afbd766..e9caa3f0982b 100644 --- a/sys/cam/ctl/ctl_ioctl.h +++ b/sys/cam/ctl/ctl_ioctl.h @@ -460,6 +460,7 @@ struct ctl_lun_req { union ctl_lunreq_data reqdata; void * args; nvlist_t * args_nvl; +#define CTL_MAX_ARGS_LEN (1024 * 1024) size_t args_len; void * result; nvlist_t * result_nvl;