From nobody@FreeBSD.org  Fri Mar  8 13:30:39 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 76F9DF6
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  8 Mar 2013 13:30:39 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 4D68E150
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  8 Mar 2013 13:30:39 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r28DUbi4077712
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 8 Mar 2013 13:30:37 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r28DUba1077711;
	Fri, 8 Mar 2013 13:30:37 GMT
	(envelope-from nobody)
Message-Id: <201303081330.r28DUba1077711@red.freebsd.org>
Date: Fri, 8 Mar 2013 13:30:37 GMT
From: Arrigo Marchiori <ardovm@yahoo.it>
To: freebsd-gnats-submit@FreeBSD.org
Subject: BTX Loader i386 incorrectly probes EDD, possibly resulting division by zero
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         176748
>Category:       kern
>Synopsis:       [libi386] [patch] BTX Loader i386 incorrectly probes EDD, possibly resulting division by zero
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 08 13:40:01 UTC 2013
>Closed-Date:    
>Last-Modified:  Tue Jan 14 16:30:02 UTC 2014
>Originator:     Arrigo Marchiori
>Release:        9-STABLE
>Organization:
>Environment:
FreeBSD myhost 9.1-STABLE FreeBSD 9.1-STABLE #19 r247772: Mon Mar  4 10:47:30 CET 2013     root@myhost:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
BTX probes for disk drives using interrupt 0x13.
The "EDD" information is parsed incorrectly: the loader may incorrectly assume that the EDD information is present, and therefore overwrite the number of sectors and their size with incorrect values.

The error is in file /usr/src/sys/boot/i386/libi386/biosdisk.c, inside function bd_int13probe().

The call to interrupt 0x13, AH=0x41 returns values in the bits of the CX register. The bit EDD_INTERFACE_EDD is not checked, while it should be.

The effect on my configuration was that bd_int13probe() incorrectly assumed that EDD information was present; it requested for it with int 0x13, AH=0x48 and overwrote the number and size of sectors with invalid values (zero, in my case). This resulted in a zero by zero division in file
/usr/src/sys/boot/i386/common/disk.c, function disk_open().

My setup had some buildworld/buildkernel tunings through src.conf(5). For instance, ZFS support was not compiled in. I believe such customization should not influence this particular problem.
>How-To-Repeat:
Find a system with a mass memory that does not provide EDD information.
This problem was detected on a AMD Geode GX CPU, using a USB drive for boot.
Please let me know if you need any more information about this.
>Fix:
The attached patch adds the check for the EDD_INTERFACE_EDD bit inside the data returned by the call to interrupt 0x13, AH=0x41.
It solves the problem on my hardware configuration.


Patch attached with submission follows:

Index: biosdisk.c
===================================================================
--- biosdisk.c	(revisione 247767)
+++ biosdisk.c	(copia locale)
@@ -231,7 +231,8 @@
 	v86int();
 	if (V86_CY(v86.efl) ||	/* carry set */
 	    (v86.ebx & 0xffff) != 0xaa55 || /* signature */
-	    (v86.ecx & EDD_INTERFACE_FIXED_DISK) == 0)
+	    (v86.ecx & EDD_INTERFACE_FIXED_DISK) == 0 ||
+            (v86.ecx & EDD_INTERFACE_EDD) == 0)
 		return (1);
 	/* EDD supported */
 	bd->bd_flags |= BD_MODEEDD1;


>Release-Note:
>Audit-Trail:

From: Arrigo Marchiori <ardovm@yahoo.it>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/176748: [libi386] [patch] BTX Loader i386 incorrectly
 probes EDD, possibly resulting division by zero
Date: Tue, 14 Jan 2014 17:21:13 +0100

 Hello,
 
 this patch still applies to today's 9-STABLE.
 
 Can I do anything to help integrating it?
 
 Regards,
 -- 
 rigo
 
 http://rigo.altervista.org
>Unformatted:
