From nobody Mon May 08 08:55:23 2023 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 4QFFVh0sCNz49cCh for ; Mon, 8 May 2023 08:55:24 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QFFVg5xSBz3sDg for ; Mon, 8 May 2023 08:55:23 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683536123; 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=UFm5oFpYLI4oArmJBArtexaLmNEZOOEuFXtZ4UladnA=; b=VQLLqJsltWCN+/Zy8lSsarIBRufmpDJjiDx8srGbwi3H0JOCuNql1XDld3PfowGIV+6WQD HFjRVOMc0u7PJ7YIx4mVaXiJyBFbjxVe4NiEEqJk1rfFunL/6J7Om1MdYI5ifOlgK+nBjh oWa4LgbP/OJc8T4ysP/EQTT6lUeOvd7y3zuILjHDj6hU/Mh6U6Qhkl99uYH7KFyVODuA1Z XkH01DzHACZiDt/O5C3dM5c/DimBGHUXi5HPfxX4BPbv6TtwmaMgzwF5n13edgp4c2ZR3+ sXTOI2qDrb3KCeshiUPFXJItZtmUrNhCLL37qJCU0vcwLRM8IlrEG1jNZhgtKQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683536123; a=rsa-sha256; cv=none; b=Y/cNIzcVc1Jg5gYlakGj+hxCu3R7IalYRot4/CarNSjmOGGAidjR2LT7vCNqGf2xQTBTY8 zTYqfiLSPvX5Qa8XRIhVxd6swVO8QUVelNtu2/BxQ5vo2UTrlWCbG0B7N0s/6NW3MGsQWC 080oEc7xG9DIy2OA5/usf4fvW+aMOTOyfeHTwfrs57hGSmnrMK7scr/hKRC5sHSF7z0vHS gpNPnn+EpU7Verghv8Na3Hi/O3n0UKLib7ogCpBtIlf/A7Jn1tsp+p5L8INhpZaBeLLQOn D9kp7JBp7C0ugR1QPUPiWW4yLS70xtbQHSJOWgfdI+hs/hC4Di43M73qGiXqcA== 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 4QFFVg50Rpztwt for ; Mon, 8 May 2023 08:55:23 +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 3488tNMa091132 for ; Mon, 8 May 2023 08:55:23 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 3488tNem091131 for bugs@FreeBSD.org; Mon, 8 May 2023 08:55:23 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 271310] potential NULL dereference in fsck_ffs's changeino() Date: Mon, 08 May 2023 08:55:23 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin 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.created 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 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 X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D271310 Bug ID: 271310 Summary: potential NULL dereference in fsck_ffs's changeino() Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu Created attachment 242049 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D242049&action= =3Dedit a broken FS image that causes a NULL dereference in fsck's changeino() Running fsck_ffs -y on the attached image causes this line in sbin/fsck_ffs/dir.c changeino() to dereference NULL: getinoinfo(dir)->i_depth =3D depth; I think the reason is that the link count of the i-node in question (i-number 3, a directory) has its high bit set, so that it looks negative in di_nlink (which is int16_t) in this code in checkinode() in pass1.c: if (mode =3D=3D IFDIR) { if (DIP(dp, di_size) =3D=3D 0) { inoinfo(inumber)->ino_state =3D DCLEAR; } else if (DIP(dp, di_nlink) <=3D 0) { inoinfo(inumber)->ino_state =3D DZLINK; } else { inoinfo(inumber)->ino_state =3D DSTATE; cacheino(dp, inumber); countdirs++; } As a result, ino_state is set to DZLINK, and cacheino() is not called, which is why getinoinfo() eventually returns NULL. Later, in pass4(), I think the expectation is that ino_linkcnt will be zero, and clri() will be called. But in fact ino_linkcnt is not zero (it's negative), so adjust() is called, which effectively expects cacheino() to have been called. case DZLINK: if (inoinfo(inumber)->ino_linkcnt =3D=3D 0)= { clri(&idesc, "UNREF", 1); break; } /* fall through */ case FSTATE: case DFOUND: n =3D inoinfo(inumber)->ino_linkcnt; if (n) { adjust(&idesc, (short)n); A backtrace from fsck_ffs -y fsck13a.img : Program received signal SIGSEGV, Segmentation fault. Address not mapped to object. 0x000000000020b165 in changeino (dir=3D3, name=3D0x201ecf "..", newnum=3D4,= depth=3D2) at dir.c:712 712 getinoinfo(dir)->i_depth =3D depth; (gdb) where #0 0x000000000020b165 in changeino (dir=3D3, name=3D0x201ecf "..", newnum= =3D4,=20 depth=3D2) at dir.c:712 #1 0x000000000020a553 in linkup (orphan=3D3, parentdir=3D0, name=3D0x0) at= dir.c:664 #2 0x0000000000209acd in adjust (idesc=3D0x7fffffffe7d0, lcnt=3D-32765) at dir.c:470 #3 0x000000000022025e in pass4 () at pass4.c:94 #4 0x0000000000219ae9 in checkfilesys (filesys=3D0x7fffffffed79 "junk") at main.c:484 #5 0x0000000000218f42 in main (argc=3D1, argv=3D0x7fffffffea28) at main.c:= 210 --=20 You are receiving this mail because: You are the assignee for the bug.=