From owner-freebsd-bugs@freebsd.org Wed Dec 21 18:07:50 2016 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 29618C8A185 for ; Wed, 21 Dec 2016 18:07:50 +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 mx1.freebsd.org (Postfix) with ESMTPS id ECFEE15DD for ; Wed, 21 Dec 2016 18:07:49 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id uBLI7neB006191 for ; Wed, 21 Dec 2016 18:07:49 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 215474] ccb_pathinq.(sim_vid|hba_vid|dev_name) aren't null terminated Date: Wed, 21 Dec 2016 18:07:50 +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 Many People X-Bugzilla-Who: asomers@FreeBSD.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-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.23 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2016 18:07:50 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D215474 Bug ID: 215474 Summary: ccb_pathinq.(sim_vid|hba_vid|dev_name) aren't null terminated Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Many People Priority: --- Component: kern Assignee: freebsd-bugs@FreeBSD.org Reporter: asomers@FreeBSD.org The sim_vid, hba_vid, and dev_name fields of struct ccb_pathinq are fixed-length strings. AFAICT the only place they're read is in sbin/camcontrol/camcontrol.c, which assumes they'll be null-terminated.=20 However, the kernel doesn't null-terminate them. A bunch of copy-pasted code uses strncpy to write them, and doesn't guarantee null-termination. For at least 4 drivers (mpr, mps, ciss, and hyperv), the hba_vid field actually overflows. You can see the result by doing "camcontrol negotiate da0 -v".= =20 Note the garbage at the end of the HBA vendor field: $ camcontrol negotiate da0 -v Current parameters: (pass0:mps0:0:10:0): transfer speed: 300.000MB/s (pass0:mps0:0:10:0): tagged queueing: enabled mps0: SIM/HBA version: 1 mps0: supports tag queue messages mps0: supports SDTR message mps0: supports 16 bit wide SCSI mps0: unknown PIM bit set mps0: unknown PIM bit set mps0: user has disabled initial BUS RESET or controller is in target/mixed = mode mps0: HBA engine count: 0 mps0: maximum target: 255 mps0: maximum LUN: 255 mps0: highest path ID in subsystem: 0 mps0: initiator ID: 255 mps0: SIM vendor: FreeBSD mps0: HBA vendor: Avago Tech (LSI)mps mps0: HBA vendor ID: 0x0000 mps0: HBA device ID: 0x0000 mps0: HBA subvendor ID: 0x0000 mps0: HBA subdevice ID: 0x0000 mps0: bus ID: 0 mps0: base transfer speed: 150.000MB/sec mps0: maximum transfer size: 4722688 bytes The correct solution is to replace strncpy with strlcpy to null-terminate t= hem, and shorten the hard-coded strings that are too long. --=20 You are receiving this mail because: You are the assignee for the bug.=