From owner-freebsd-bugs@freebsd.org Fri Jun 21 14:12:50 2019 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C5FAD15AF488 for ; Fri, 21 Jun 2019 14:12:49 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 5F8B36B086 for ; Fri, 21 Jun 2019 14:12:49 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id 1D16B15AF486; Fri, 21 Jun 2019 14:12:49 +0000 (UTC) Delivered-To: bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EEAAD15AF485 for ; Fri, 21 Jun 2019 14:12:48 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8D13E6B083 for ; Fri, 21 Jun 2019 14:12:48 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id BA3961A063 for ; Fri, 21 Jun 2019 14:12:47 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id x5LECl64011748 for ; Fri, 21 Jun 2019 14:12:47 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id x5LEClAV011747 for bugs@FreeBSD.org; Fri, 21 Jun 2019 14:12:47 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 238748] several race conditions in nandsim Date: Fri, 21 Jun 2019 14:12:47 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 12.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: emaste@freebsd.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jun 2019 14:12:50 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D238748 Bug ID: 238748 Summary: several race conditions in nandsim Product: Base System Version: 12.0-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: emaste@freebsd.org Reported to secteam (admbugs 795) but does not need to be treated as a secu= rity issue because the NAND framework is not built by default, nandsim is not intended for production use, and the device is root-only. Reported by: Ilja Van Sprundel the nandsim driver has a global variable called crtls. when it's used no lo= cks are held. this can cause race conditions in several places leading -among o= ther things- to:=20 - double free=20 - NULL deref=20 - memory leak=20 freebsd-master\sys\dev\nand\nandsim.c static int nandsim_create_chip(struct sim_chip *chip) { struct sim_chip *sim_chip; nand_debug(NDBG_SIM,"create chip num:%d at ctrl:%d", chip->num, chip->ctrl_num); if (chip->ctrl_num >=3D MAX_SIM_DEV || chip->num >=3D MAX_CTRL_CS) { return (EINVAL); } if (ctrls[chip->ctrl_num].chips[chip->num]) { return (EEXIST); } sim_chip =3D malloc(sizeof(*sim_chip), M_NANDSIM, M_WAITOK); if (sim_chip =3D=3D NULL) { return (ENOMEM); } memcpy(sim_chip, chip, sizeof(*sim_chip)); ctrls[chip->ctrl_num].chips[chip->num] =3D sim_chip; <-- <-- no ctrls lock = held, this can leak=20 sim_chip->created =3D 1; return (0); } static int nandsim_destroy_chip(struct sim_ctrl_chip *chip) { struct sim_ctrl_conf *ctrl_conf; nand_debug(NDBG_SIM,"destroy chip num:%d at ctrl:%d", chip->chip_num, chip->ctrl_num); if (chip->ctrl_num >=3D MAX_SIM_DEV || chip->chip_num >=3D MAX_CTRL_CS) return (EINVAL); ctrl_conf =3D &ctrls[chip->ctrl_num]; if (!ctrl_conf->created || !ctrl_conf->chips[chip->chip_num]) return (ENODEV); if (ctrl_conf->running) return (EBUSY); free(ctrl_conf->chips[chip->chip_num], M_NANDSIM); <-- no ctrls lock held, = this could double free ctrl_conf->chips[chip->chip_num] =3D NULL; return (0); } static int nandsim_modify(struct sim_mod *mod) { struct sim_chip *sim_conf =3D NULL; struct nandsim_chip *sim_chip =3D NULL; nand_debug(NDBG_SIM,"modify ctlr %d chip %d", mod->ctrl_num, mod->chip_num); if (mod->field !=3D SIM_MOD_LOG_LEVEL) { if (mod->ctrl_num >=3D MAX_SIM_DEV || mod->chip_num >=3D MAX_CTRL_CS) return (EINVAL); sim_conf =3D ctrls[mod->ctrl_num].chips[mod->chip_num]; <-- can be NULL! sim_chip =3D get_nandsim_chip(mod->ctrl_num, mod->chip_num); <-- can be NUL= L! } switch (mod->field) { case SIM_MOD_LOG_LEVEL: nandsim_log_level =3D mod->new_value; <-- NULL deref break; case SIM_MOD_ERASE_TIME: sim_conf->erase_time =3D sim_chip->erase_delay =3D mod->new_value; <-- NULL= deref break; case SIM_MOD_PROG_TIME: sim_conf->prog_time =3D sim_chip->prog_delay =3D mod->new_value; <-- NULL d= eref break; case SIM_MOD_READ_TIME: sim_conf->read_time =3D sim_chip->read_delay =3D mod->new_value; <-- NULL d= eref break; case SIM_MOD_ERROR_RATIO: sim_conf->error_ratio =3D mod->new_value; <-- NULL deref sim_chip->error_ratio =3D mod->new_value; break; default: break; } return (0); } --=20 You are receiving this mail because: You are the assignee for the bug.=