From nobody Wed Sep 14 17:28:45 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 4MSS3x4fY5z4bfbf; Wed, 14 Sep 2022 17:28:45 +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 4MSS3x3tspz3S0L; Wed, 14 Sep 2022 17:28:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663176525; 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=8dQIpbj4DUPLFAC/TD0xb/9SPD0hrqieIqXYkMShBn8=; b=NldzaZn8GtdjEcrBeDvnYMGG2oEMS2N8YWFMNQdKsCkWkfFITZnYWiPVufVjQoX8Gjb6hM X0qpvvP6juWyLTHdpM1xg8vKjMN7ZT21v9RxMvJMtnWJIM+Ppp9IUPAWIBJy8GpWrEfjnQ mEk4DsjPEWAVDdBLVEm5n4SdoF+xYr+oqw7F3zZel1bCLu0DHakDVgeErDjp99XDD5Y/yG uJatHQAdEAKjRnSZ+JLUNh1pliG9P9ESpGglOGxP3E1+21KhOesYo3XR96Rle5Vn4F5i1f VnEFEpq1ZJ/2hFAtSYeI/ka6kp9vhd/XuYqYtEuTG9qLeomFeTc5ztx9QqM9vQ== 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 4MSS3x2xHlzkky; Wed, 14 Sep 2022 17:28:45 +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 28EHSj5m022532; Wed, 14 Sep 2022 17:28:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28EHSjgl022531; Wed, 14 Sep 2022 17:28:45 GMT (envelope-from git) Date: Wed, 14 Sep 2022 17:28:45 GMT Message-Id: <202209141728.28EHSjgl022531@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: ce1895b7248d - stable/12 - 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/12 X-Git-Reftype: branch X-Git-Commit: ce1895b7248d5601b34d0d6492539a7081a8d451 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663176525; 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=8dQIpbj4DUPLFAC/TD0xb/9SPD0hrqieIqXYkMShBn8=; b=x85NABmgIlGtu2UDkvkie2tTFs2gnspWinvvycNfATEuGcukyn9OYRp0UIBCvDzcnSi4HN Zgu1yvuU//WrQHXAs2+k/KlCgZt72MPa+rkhvxcBnG0XPfdWrNXtAVrIXPYwEOoMqyXFlE hj9spMbR5SMhzqtXTdEyNph92W4eZY+7EJ3A3XvPyrb7u1hJW2MihZ8NCMkMDVNLOFg/9s IUsTVo3++oN2wiWgb3dOJRLcwIK3FMnmD6DIrzkNvJHaOBLtwaydWi12OuMfWUxoSmmkuy OnworXOWJiokfbGsHTg7KxW88zBqsmgw20o+1b1nag2fUKNbr7mMswpojfKjMg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663176525; a=rsa-sha256; cv=none; b=uCNzvUpwW9ZbDpEUlLZxzSTrCcpsdT/YA9eZqQpvugbrzGUcDGSzRoPhLlL6rvG08o+qlF 1hc/hPvtO/rZV0gHbhAxlsEeGt8VU6UPSKD2i27Ey5JskQ5On6y/hatUrbV+qhRmOOpv5L eDwJvgACsR4XCaBMPLEWenXs/cqalcgY/07gqwrm8qssNk3TgR31VFIg6RXKyr92+NpT+5 RwtOyd0cVmNDNLoIPqE9ZZzQNv0vwLQ2PMZCyZlBw8QMo6rWd755GyeBaIx6BtxFHuoQjZ 0ntnIINSYgsLb/K1/TupQ8p2uSjbe1tcnH1JsovAkF29pLPXH02A3BN95FTmng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=ce1895b7248d5601b34d0d6492539a7081a8d451 commit ce1895b7248d5601b34d0d6492539a7081a8d451 Author: Alexander Motin AuthorDate: 2022-09-07 01:58:27 +0000 Commit: Alexander Motin CommitDate: 2022-09-14 17:28:18 +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 e909ccf70406..e0f30ebe1250 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -2904,6 +2904,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); @@ -2925,6 +2931,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; @@ -3181,6 +3188,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); @@ -3202,6 +3215,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;