From nobody Wed Sep 07 02:07:55 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 4MMlyg40tnz4cCv2; Wed, 7 Sep 2022 02:07:55 +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 4MMlyg3Pq1z3K9W; Wed, 7 Sep 2022 02:07:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662516475; 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=Y7cPh7Y0jh4IX/1oeGzWoQc4iH6X3+KQETR313++avc=; b=w9ZPn4XKcKlcB1TFUriUE25nbT6h7m+FYZ6qZfRdgbFesLF1giNCDbWCyXDIByu+O5P0Vu 2sPAhVMZPCCEUMs1EHAhqnsbn7ZHRKWhCy8BqD6lLvoa0OipC8mlWZcjAc9SYu35NkV4As AM3n99utL7gXs0LqXgL71Ay5yVN16DtZ6lVrC0Eqb1B1qFS3AL180FYMa3aJzS0WR6UQam hG6BNqW35ErqbBZTC8KByspg41PaS6bf5+UgSzodwjs6TOnvMMUlTT4QNus46dhHRCcei0 LSDxn6fc2OU9jVYubzVyapFdQBIK2/D7J8+Dw5HmzSlU79kV1A/r5BFqFLGzTA== 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 4MMlyg2DlYzMtM; Wed, 7 Sep 2022 02:07:55 +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 28727tQc030194; Wed, 7 Sep 2022 02:07:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28727t0O030193; Wed, 7 Sep 2022 02:07:55 GMT (envelope-from git) Date: Wed, 7 Sep 2022 02:07:55 GMT Message-Id: <202209070207.28727t0O030193@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: 0586be48a97c - main - 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/main X-Git-Reftype: branch X-Git-Commit: 0586be48a97c5af50ba4f578d33211f81cc57016 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662516475; 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=Y7cPh7Y0jh4IX/1oeGzWoQc4iH6X3+KQETR313++avc=; b=Nb4nYNhRzq4YrWgvR3yEFjrRwZjhdO8Kw02Iy/Zo8KIy9/daRi/DFFIicLc2Lq5kvRvg9x zRLtxPX+WUtRxxsPBM7tmGjikJ1ySyTRTtQf06RHhTVJo7jd+vr62NWnzg8QphV66CPk0P raN6deeAcxqps4zHbtVuAbd86yeA0wUENPMLB3/m3aRuJxj1zrLUvXB3phBcCDMUoqFYv6 kZXu1T3Shtqx/xD+f3jus+xAM/QqteZtVGwkQngHGhssGJUwz1BRM+MgaVKh+aEUJZl/fY k4mY3YBla0Q3BDzsNTfe2cVk8I+FGVHQFdBl70irmz0wPeCGSfsbtNNiXiBMbg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1662516475; a=rsa-sha256; cv=none; b=b7GhaFsXrV5f8DQLYRa5MJj6aG6ehFiIkz1ZRUN/WhZrW+zMvLUAykzPGZ23weR50xwSZT p+Z+l7/vW7qGyrJzUbWpZmQWNVZB9j6mqfWhYstUqQRSZ1UqC/S+5oIMerh+Qj2iAuK8Gp 41xrAe4SjFhPpmWSEYfqAI+SifFNyFWr9eaEGE3pRqv18x0t7a5Epma8VeUgTV48zEnmnN QOeQIEuV7JH1ASra5+QslCiq+WSt1Hs6qQr8uG6IrdHTD2zzo96yW5d/iuFN+ciEIPUC12 x2gkqZsP+cRnBvRrRB0Bq8iQF1fsPkHZCKrByg3SPZuohcb8YjTt03tOryD6BQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=0586be48a97c5af50ba4f578d33211f81cc57016 commit 0586be48a97c5af50ba4f578d33211f81cc57016 Author: Alexander Motin AuthorDate: 2022-09-07 01:58:27 +0000 Commit: Alexander Motin CommitDate: 2022-09-07 01:58:27 +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 --- 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 1fda5bde72c2..07ebade1e44a 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 5cb7f29d82a7..543f97a65d30 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;