From nobody Sun Feb 23 14:52:45 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 4Z16Kp0b0rz5ns9L for ; Sun, 23 Feb 2025 14:52:46 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z16Kp076Zz3kFM for ; Sun, 23 Feb 2025 14:52:46 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740322366; 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=3n3JX1WfRMFF5HtRnQGjLg+hW4Y+enctf/axeMGFR+M=; b=J5Kmp5iiQquqKppREnrlUYIwAIbc5AdJda/zH0tx5eFdjHC/ZZJC7vbKzZm+5cfkybdk+A vpecjkyrXtnECJSmeO0TU3SlkJRQ7Blr+eNnHpEAou7BaiT69FbMKgITpY+blIEfJALC6M Bq/O4MP2bQUMBRWjSjo+xnt7AecgwiJdq/rr9nfztYhY+9k3xmYSf1CMjYiqTzvDsydpzB GG5jCBrjio3JOoo5M0XVyfUMaIMnXuorlgzp79SvBZQ53mg6SB9whOxVMvM6APO3Y076++ WAaPY12six2FzrXukHPbcNTQEEIzMqPxXX1240XY4ekujiLAMx+fFrDP/su2Pw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740322366; a=rsa-sha256; cv=none; b=QijrISAXrN6tYKOwzd9eNfQg43TA63PWe5AMkT7MK0Q6XkaWfu+a1r1o3G21lNVsjaA0fv X1Ph6OJljylLpilxKuS1bhp6pueHM22rIptQuBhLdA5EHz87ChXZK/z5eGZ5uXAA9jaHd1 NwrsAsOw1vlsO8UlMNEx85rK4awMqlMKU0NvumVYYi2h9CZJme57pVLYrFl80GMzmylOd5 HwURHWQTjBOCTXRG5dnsdYWdnpMsTLjxGHM9E+ksU/9ItDygCDlRD5gOHZcmIr6sSgSm9P Bbk01U9uOq+CHLc4EaLsTWZngeTN37Ea4CdQe07awZri/XN9VUpMcsLubN9eNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740322366; 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=3n3JX1WfRMFF5HtRnQGjLg+hW4Y+enctf/axeMGFR+M=; b=Ndwl3UQkPc9Hc9CZgzyRczDoHaKODSCFAB4ppjBaRJpP98pcou5NgQlRp8c4tqd8+CzJo5 K9bdEINcra84cZotl/F/309MfQ4tnaUnWPk4pQJIxDfPM7vUEQwGekregWnkRcF4rYQYf7 PM/aKZWv2WdwgRm0lBInJYulCuhjl2H1AiYLiS4IT1brh5Njdvy5DC/5DRVXNksQT5v0EI Cikz2/zy0BTEk3MprH2QVIQsvjxcW4kXNMzw8YimRRmRP1jV5XbLWlL4FqCNTy/yRqlXt2 MElFS0hhntu9XjWxE5IboEAOaq1CF7K7as9qkyhpvkXCMS6rIhGw2mvY6GKUlg== 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 4Z16Kn6pQbzykT for ; Sun, 23 Feb 2025 14:52:45 +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 51NEqjEg055735 for ; Sun, 23 Feb 2025 14:52:45 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 51NEqji1055734 for bugs@FreeBSD.org; Sun, 23 Feb 2025 14:52:45 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 284991] buffer overflow in md_sii.c sii_meta_write() Date: Sun, 23 Feb 2025 14:52:45 +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 attachments.mimetype attachments.created 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=3D284991 Bug ID: 284991 Summary: buffer overflow in md_sii.c sii_meta_write() 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 Attachment #257768 text/plain mime type: Created attachment 257768 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D257768&action= =3Dedit iscsi target that claims sector size is 3 bytes During taste, it's possible for sii_meta_write() to execute: buf =3D malloc(pp->sectorsize, M_MD_SII, M_WAITOK | M_ZERO); memcpy(buf, meta, sizeof(*meta)); If a misbehaving device claims a sectorsize smaller than 512, the memcpy will overflow the allocated buffer, since sizeof(*meta) is 512. I've attached a demo in the form of a fake iscsi target that claims a sector size of 3 at the decisive moment. On a kernel without INVARIANTS: # uname -a FreeBSD 15.0-CURRENT FreeBSD 15.0-CURRENT #490 main-n250999-c0872cef91fc-dirty: Sun Feb 23 08:34:01 EST 2025=20=20=20=20 rtm@xxx:/usr/obj/usr/rtm/symbsd/src/riscv.riscv64/sys/RTM riscv # cc iscsi38d.c # ./a.out ... REDZONE: Buffer overflow detected. 16 bytes corrupted after 0xffffffd00cb81= 703 (3 bytes allocated). Allocation backtrace: #0 0xffffffc00078d614 at redzone_setup+0xa0 #1 0xffffffc0004136ae at malloc+0xba #2 0xffffffc0003bf9e8 at sii_meta_write+0x5a #3 0xffffffc0003be76e at g_raid_md_write_sii+0x2a4 #4 0xffffffc0003bf5a6 at g_raid_md_sii_start+0x3a8 #5 0xffffffc0003bd738 at g_raid_md_taste_sii+0x812 #6 0xffffffc00039e15e at $x+0x192 #7 0xffffffc000391488 at g_new_provider_event+0xa2 #8 0xffffffc00038c658 at g_run_events+0x120 #9 0xffffffc00038ebc0 at g_event_procbody+0x58 #10 0xffffffc0003f88dc at fork_exit+0x68 #11 0xffffffc0007efd7a at fork_trampoline+0xa Free backtrace: #0 0xffffffc00078d9de at redzone_check+0x344 #1 0xffffffc0004146fc at free_dbg+0x5c #2 0xffffffc0004134c6 at free+0x1c #3 0xffffffc0003bfac0 at sii_meta_write+0x132 #4 0xffffffc0003be76e at g_raid_md_write_sii+0x2a4 #5 0xffffffc0003bf5a6 at g_raid_md_sii_start+0x3a8 #6 0xffffffc0003bd738 at g_raid_md_taste_sii+0x812 #7 0xffffffc00039e15e at $x+0x192 #8 0xffffffc000391488 at g_new_provider_event+0xa2 #9 0xffffffc00038c658 at g_run_events+0x120 #10 0xffffffc00038ebc0 at g_event_procbody+0x58 #11 0xffffffc0003f88dc at fork_exit+0x68 #12 0xffffffc0007efd7a at fork_trampoline+0xa panic: Stopping here. On a kernel with INVARIANTS, it panics in g_io_request(): KASSERT(bp->bio_offset % cp->provider->sectorsize =3D=3D 0,= =20=20=20=20=20=20 ("wrong offset %jd for sectorsize %u",=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 bp->bio_offset, cp->provider->sectorsize)); --=20 You are receiving this mail because: You are the assignee for the bug.=