From nobody Wed Feb 05 10:28:12 2025 X-Original-To: bugs@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 4YnxJr3L3Bz5mXd5 for ; Wed, 05 Feb 2025 10:28:12 +0000 (UTC) (envelope-from bugzilla-noreply@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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YnxJr2hfsz3h7b for ; Wed, 05 Feb 2025 10:28:12 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738751292; 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=VvZo1jjyg5j7Pb6Ay7aEecg3hjrP4CvOdBEV+mD+lUo=; b=DYD0kxoozwmmVIgIYKadHXCaptUWdtbz2Ws0IYR0BpMb79/IZCdOGWcXqomexpXp8EEAzz 9TyqtF33FNVkrBw+nzxqzQ+OLYL3oXHLuYLIEMLqcKRoeGS/nB+z98Qk6KeRcTWu4IIpxQ DUGja0RXL+Y3b04CmxfD7vtgYxa7YWKao+JPVI2gi/9fQHVwVoDKAF/BSqyiFOlioxmAhx pnfjElBR2ZUjQr2K6LOFRvRQaqDnCpNBHRTuOb8uN8w3KCe20e1nAnOrBOdjh7MEqlGl3T BfCVMCkXOgLcYGxqI+D0gImzXoDv1eGZLgU2SDbwecy7jz2d+67Lp74wnFzp3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738751292; 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=VvZo1jjyg5j7Pb6Ay7aEecg3hjrP4CvOdBEV+mD+lUo=; b=kfR8n9AeYdGhUcr01BFx9+wrJNFp0Ww/rfdL+9Gro8bnIFqdtbcjNd21MiCBXqMUI8Qz28 SMxNe+A0qRcn/tyresZ3MgIczx4u3sWREO3KqebJkC5cEMbCYDyQ5TnA0SyB/OhoxGpurb S8cCnfT6C7M/JzruCTbNWZiBGsaKkKzN89Uu6vWNuA5sNZFSXpKeEfr7p9QyD0b1OmWLpT z2e8aBEtbLXX1zB51XHFdPlPnPomIdZaZwjrD1EtoY+E+XKpqIDsPyv4v0NOT+57ZMFfb5 zVGGOWEWlWSf5uHt+wawjvl6+Ark4xeVnegQkKTCUEEeYyHCHGaTXyNVz34CDQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1738751292; a=rsa-sha256; cv=none; b=VFEdpDpT/4q+2tsNDCauGVh5yS+Yyjgbl4MKSMbnx5xVkgDVkimcPsOZ1JyeYRceVLj6uo hkP/oh2hy3jrVgpqLvE+TznVE9zfLh/CwBPSacOhMuuKMO3mLZayWPGG8RA0dp62PYNyCu t0j6nOxIzpB6NSnM1Nji4YsiBa0P6ij/IYdxqK1U0XiuJXEwd1l5Pf9am4/AFO5YFc2fob NJ7LI1OGo/UbyDPvqyD9qFXLcX97ViOkJNj0VTpbV3zJUqDGvO8XCJ3P5a9bSkshNcyRWC oU9kS0WI5/RUCLB9P03R9/ak/wLjH3ZJeh/mIsfAMKO5KoleTyM0SF9qBmW3pw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 4YnxJr1QvWzp2k for ; Wed, 05 Feb 2025 10:28:12 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 515ASCst030847 for ; Wed, 5 Feb 2025 10:28:12 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 515ASC2k030846 for bugs@FreeBSD.org; Wed, 5 Feb 2025 10:28:12 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 284587] integer wrap and invalid read in scsi_sa saloadtimeouts() Date: Wed, 05 Feb 2025 10:28:12 +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: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: rtm@lcs.mit.edu 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D284587 Bug ID: 284587 Summary: integer wrap and invalid read in scsi_sa saloadtimeouts() Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu In saloadtimeouts() in scsi_sa.c: avail_len =3D scsi_4btoul(hdr->length) + sizeof(hdr->length); ...; used_len =3D sizeof(hdr->length); avail_len =3D MIN(avail_len, valid_len - sizeof(*hdr)); ...; while ((avail_len - used_len) > sizeof(*desc)) { ...; cur_ptr =3D &buf[used_len]; ...; used_len +=3D sizeof(*desc); The SCSI device can cause hdr->length to be -4, since it's a field in the response to a REPORT SUPPORTED OPERATION CODES. Then avail_len is zero, so avail_len - used_len is huge (since unsigned) and the while loop runs for many iterations when it shouldn't. Depending on the details, used_len can advance so that it's beyond the end of buf[]. And a little later: td =3D (struct scsi_report_supported_opcodes_timeout *)cur_= ptr; td_len =3D scsi_2btoul(td->length); td_len +=3D sizeof(td->length); used_len +=3D td_len; td->length is supplied by the SCSI device, and if it's large, it can cause used_len to be big enough that the while-loop's "avail_len - used_len" wraps, again causing the while loop to proceed when it ought to terminate. --=20 You are receiving this mail because: You are the assignee for the bug.=