Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1l32fT-0002aC-FY for mharc-grub-devel@gnu.org; Fri, 22 Jan 2021 15:04:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l32fP-0002Xh-Uv for grub-devel@gnu.org; Fri, 22 Jan 2021 15:04:25 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:40934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1l32fK-0001Xg-6L for grub-devel@gnu.org; Fri, 22 Jan 2021 15:04:23 -0500 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1l32fH-00084i-9E for grub-devel@gnu.org; Fri, 22 Jan 2021 20:04:15 +0000 Received: by mail-qk1-f198.google.com with SMTP id y187so4916502qke.20 for ; Fri, 22 Jan 2021 12:04:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:autocrypt:to:cc:message-id:date :user-agent:mime-version:content-language:content-transfer-encoding; bh=YGGPOjEqRVCt/1uRnRYyjAA5W90RD6wRw6cdQC9DHcw=; b=SnqilnQ/ObvTJgFArgBgnHnBU3plc6OJzzkIkmR1ibeYZNb73tmociuQHIOzXAFgG9 toMOLO0h3X8/bNtux9/b1h5IMa16HIVI/RGpwxrqfIUh/Cip4ksEo/nJD/oZIb818Kb1 aMEUyHf820XW+0GW0dwzkG0L8QF83gc0/prYLiOFgGcNrD3VatYoQFJepQK2ehBPzoCy 6In4dLEtE3GLuS15CGdZvWRif+HyE6j5E4ytpbjvv/29mC0eSnVqGiVWu2Z0jf+igz0b MxtzOSZ6qv52hRiuW45ckiZolV1E+X3ZNeGfWO4lNxAOzzTdij08hU9UhkaSUWq+I8h/ j12w== X-Gm-Message-State: AOAM530+7Cad6kwkmC18OusvwVg5Iq3U/5sudQBIFm+5oF/jbGZOgy34 PLTyRzrhlgdDPdJebYDYy7Qq8zA87sdfKbVeXlMCFZ1Nn8uVZ/0i84aECWdw/fNCAExDFww03sX nh+Bv4ylKlGgGZlvVdlHi4aO9tX7M X-Received: by 2002:ac8:c8c:: with SMTP id n12mr1634240qti.339.1611345854373; Fri, 22 Jan 2021 12:04:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1MUvmeVtYymFDTVNbdZ6bJd5MvHrSbcnFEHJLC99vfFDtjq7trbo2OQCbzJOnFrEDLpGOjQ== X-Received: by 2002:ac8:c8c:: with SMTP id n12mr1634209qti.339.1611345853980; Fri, 22 Jan 2021 12:04:13 -0800 (PST) Received: from [192.168.1.75] ([179.110.97.151]) by smtp.gmail.com with ESMTPSA id u63sm6858491qkc.115.2021.01.22.12.04.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Jan 2021 12:04:13 -0800 (PST) From: "Guilherme G. Piccoli" Subject: i386/biosdisk - int 13h/service 48h response buffer issue? Autocrypt: addr=gpiccoli@canonical.com; prefer-encrypt=mutual; keydata= xsBNBFpVBxcBCADPNKmu2iNKLepiv8+Ssx7+fVR8lrL7cvakMNFPXsXk+f0Bgq9NazNKWJIn Qxpa1iEWTZcLS8ikjatHMECJJqWlt2YcjU5MGbH1mZh+bT3RxrJRhxONz5e5YILyNp7jX+Vh 30rhj3J0vdrlIhPS8/bAt5tvTb3ceWEic9mWZMsosPavsKVcLIO6iZFlzXVu2WJ9cov8eQM/ irIgzvmFEcRyiQ4K+XUhuA0ccGwgvoJv4/GWVPJFHfMX9+dat0Ev8HQEbN/mko/bUS4Wprdv 7HR5tP9efSLucnsVzay0O6niZ61e5c97oUa9bdqHyApkCnGgKCpg7OZqLMM9Y3EcdMIJABEB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bDbb/Y Yh6gTrYoRYHo6FuQl5YsHop/fmTahpTx11IMjuh6IJQ+lvdpdfYJ6hmAZ9kiVszDF6pGFVkY kHWtnE2Aa5qkxnA2HoFpqFifNWn5TyvJFpyqwVhVI8XYtXyVHub/WbXLWQwSJA4OHmqU8gDl X18zwLgdiQ== To: bug-grub@gnu.org, grub-devel@gnu.org Cc: gpiccoli@canonical.com, "Guilherme G. Piccoli" , halves@canonical.com, Jay Vosburgh , Dan Streetman , Gavin Guo Message-ID: <32eb0b0f-ebc8-4948-20b9-b357eda048fb@canonical.com> Date: Fri, 22 Jan 2021 17:04:09 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: none client-ip=91.189.89.112; envelope-from=gpiccoli@canonical.com; helo=youngberry.canonical.com X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jan 2021 20:04:25 -0000 Hello GRUB community, I'm Guilherme Piccoli from Canonical, this is my first time posting on GRUB mailing-list/bug tracker. This is both a bug report but also an email to grub-devel ML; the goal of such duplication was to either loop more people, but also to rely on a better "archiving" of such discussion, since searching in grub-devel (through its archives) seems much more straightforward than searching GRUB bugs (at least, that was my experience). I've been debugging an issue related to the following GRUB message: "error: attempt read-write outside of disk `hd0` ". After studying the code and doing some instrumentation, I've noticed this comes from a bad calculation/reading of disk total sectors. The whole problem started with a very odd problem reported by a Canonical customer, in which GRUB wasn't able to read some kernel images/initrd in /boot. But in the end, we were able to reproduce and understand the issue as this bad total_sectors reading, and going further in the debug, I found that for x86 legacy-mode booting, GRUB collects such information by using service 48h/int 13h [0], in grub_biosdisk_get_diskinfo_real(). I've then instrumented such function by dumping the contents of struct grub_biosdisk_drp in an HP ProLiant DL360 machine, collecting the following output: size=4a, flags=0 cyl=ffff, heads=ff, sec=20 bytesp_s=200, total_secs=d1bda5b0 The value 0xd1bda5b0 is a 32-bit value, although the total_sectors struct variable is 64-bit - so it seems at first sight that it returned valid lower 32 bits, but invalid/NULL upper 32 bits. To check that theory, I was able to boot Linux kernel using its 16-bit realmode entry point, and with that, I could use its EDD module to perform the same BIOS service 48h query, and this was the result collected by Linux (a dmesg print I've added): [4.027450] edd[0]->total_secs=1d1bda5b0 According to SCSI Read Capacity 16, the value that was read by kernel EDD is correct [1]. So...this reinforces the theory that somewhat GRUB seems to be "ignoring"/NULLifying the upper 32 bits of the total_sectors variable. When checking EDD code [2], we can see that the buffer in which the BIOS fills data from the service 48h request has its address set on SI register. In GRUB code, we have the pointer "broken" in two portions, as observed in function grub_biosdisk_get_diskinfo_real(): /* compute the address of drive parameters */ regs.esi = ((grub_addr_t) drp) & 0xf; regs.ds = ((grub_addr_t) drp) >> 4; I'm not experienced enough in memory segmentation to be sure if the address split is correct...but seems the values are fine except that the 32 upper bits of total_sectors are 0. Any guidance on that would be much appreciated. Thanks in advance, Guilherme [0] https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=48h:_Extended_Read_Drive_Parameters [1] $ sg_readcap /dev/sda READ CAPACITY (10) indicates device capacity too large now trying 16 byte cdb variant Read Capacity results: Protection: prot_en=0, p_type=0, p_i_exponent=0 Logical block provisioning: lbpme=0, lbprz=0 Last LBA=7813834159 (0x1d1bda5af), Number of logical blocks=7813834160 [== 0x1d1bda5b0] [...] [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/boot/edd.c#n101