Bug 1959918

Summary: hdparm --dco-identify produces invalid Real max sectors output for some drives
Product: Red Hat Enterprise Linux 8 Reporter: Michal Grzedzicki <mge>
Component: hdparmAssignee: Tomáš Bžatek <tbzatek>
Status: CLOSED ERRATA QA Contact: Robin Hack <rhack>
Severity: medium Docs Contact:
Priority: unspecified    
Version: CentOS StreamCC: bstinson, davide, jwboyer, tbzatek
Target Milestone: betaKeywords: TestCaseNotNeeded, Triaged
Target Release: ---   
Hardware: x86_64   
OS: All   
Whiteboard:
Fixed In Version: hdparm-9.54-4.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-09 19:44:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Patch backporting upstream fix to hdparm package
none
Patch backporting upstream fix to hdparm package none

Description Michal Grzedzicki 2021-05-12 15:53:46 UTC
Created attachment 1782457 [details]
Patch backporting upstream fix to hdparm package

Description of problem:
hdparm --dco-identify produces invalid Real max sectors output for drives with certain sizes.

Version-Release number of selected component (if applicable): hdparm-9.54-3


How reproducible:
Can be reliably reproduced on affected drives like Seagate XF1230 1920GB.
The drives need to have certain sizes to trigger the issue.

Steps to Reproduce:
1. run hdparm --dco-identify /dev/sdd


Actual results:
/dev/sdd:
DCO Checksum verified.
DCO Revision: 0x0002
The following features can be selectively disabled via DCO:
Transfer modes:
mdma0 mdma1 mdma2
udma0 udma1 udma2 udma3 udma4 udma5 udma6
Real max sectors: 18446744073165333168
ATA command/feature sets:
SMART self_test error_log security 48_bit
SATA command/feature sets:
interface_power_management SSP

Expected results:
/dev/sdd:
DCO Checksum verified.
DCO Revision: 0x0002
The following features can be selectively disabled via DCO:
Transfer modes:
mdma0 mdma1 mdma2
udma0 udma1 udma2 udma3 udma4 udma5 udma6
Real max sectors: 3750748848
ATA command/feature sets:
SMART self_test error_log security 48_bit
SATA command/feature sets:
interface_power_management SSP

Additional info:
Real max sectors value is incorrect.

calculation is using bitshift operations, if shift result value has most significant bit set it's treated as signed negative value and extended as such to 64 bit value (filled with 1-s instead of 0's).

The issue is more clear if we look at hex values.

Incorrect value:
hex(18446744073165333168) = 0xffffffffdf8fe2b0

Expected value:
hex(3750748848) = 0xdf8fe2b0


Reported and fixed upstream in https://sourceforge.net/p/hdparm/bugs/87/ (triggered the release of 9.62). Attached patch backports the upstream fix to 9.54.

Comment 1 Michal Grzedzicki 2021-05-13 10:01:51 UTC
Created attachment 1782689 [details]
Patch backporting upstream fix to hdparm package

Comment 3 Davide Cavalca 2021-05-18 19:44:38 UTC
I filed https://bugzilla.redhat.com/show_bug.cgi?id=1961841 to get this fixed in c9s as well, and put up https://gitlab.com/redhat/centos-stream/rpms/hdparm/-/merge_requests/4 to that end.

Comment 5 Tomáš Bžatek 2021-05-19 13:32:21 UTC
Thanks for the contribution, this is really helpful!

I've read through the patch and tried to find a drive nearby to trigger the issue, no luck so far.

Comment 9 Michal Grzedzicki 2021-05-20 10:46:03 UTC
(In reply to Tomáš Bžatek from comment #5)
> Thanks for the contribution, this is really helpful!
> 
> I've read through the patch and tried to find a drive nearby to trigger the
> issue, no luck so far.

Yeah it's tricky to reproduce, not many drives are in the size range triggering this, we noticed this after processing hundreds of drives.
To test it I created a reproducer based on the data caught by strace.

Comment 10 Michal Grzedzicki 2021-05-20 10:47:03 UTC
(In reply to Tomáš Bžatek from comment #5)
> Thanks for the contribution, this is really helpful!
> 
> I've read through the patch and tried to find a drive nearby to trigger the
> issue, no luck so far.

I have access to the hardware and can test the rpm if that helps.

Comment 20 errata-xmlrpc 2021-11-09 19:44:15 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (hdparm bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4421