Bug 1905072

Summary: "fsadm resize /dev/foo" without size argument crashes [rhel-7.9.z]
Product: Red Hat Enterprise Linux 7 Reporter: Marius Vollmer <mvollmer>
Component: lvm2Assignee: Zdenek Kabelac <zkabelac>
lvm2 sub component: Command-line tools QA Contact: cluster-qe <cluster-qe>
Status: CLOSED ERRATA Docs Contact:
Severity: high    
Priority: urgent CC: agk, ajschorr, cmarthal, dlawrenc, heinzm, jbrassow, jreznik, mcsontos, mjuricek, mpitt, msnitzer, prajnoha, thornber, zkabelac
Version: 7.9Keywords: Regression, ZStream
Target Milestone: rc   
Target Release: 7.9   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: lvm2-2.02.187-6.el7_9.4 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1905705 (view as bug list) Environment:
Last Closed: 2021-03-16 13:57:09 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:
Bug Depends On:    
Bug Blocks: 1905705    

Description Marius Vollmer 2020-12-07 12:47:45 UTC
Description of problem:

Leaving out the NEW_SIZE argument to "fsdadm resize" results in a crash.

Version-Release number of selected component (if applicable):
lvm2-2.02.187-6.el7_9.3.x86_64

How reproducible:
Always

Steps to Reproduce:
# fsadm resize $(findmnt -n -o source /)
/sbin/fsadm: line 818: $3: unbound variable

Actual results:
fsadm crashes

Expected results:
fsadm does nothing since the filesystem is already at maximum size

Comment 4 Zdenek Kabelac 2020-12-08 21:27:55 UTC
Fixed by this patch:

https://www.redhat.com/archives/lvm-devel/2020-December/msg00005.html

Feel free to apply this patch on your locally installed  /usr/sbin/fsadm bash script to get an instant fix on your system.

Comment 5 Zdenek Kabelac 2020-12-08 21:31:16 UTC
Introduced regression causes troubles for a specific use-case of fsadm - where the resize without size parameter has resized the filesystem to match device size.

Provided fixing patch is very and has no impact on other things than validating input parameters for fsadm which is now 'guarded' by prohibiting of use of unbound shell variables.

Tested by this upstream testing case:

https://www.redhat.com/archives/lvm-devel/2020-December/msg00003.html

Comment 6 Martin Pitt 2020-12-15 15:22:28 UTC
This also happens on RHEL 8.4 -- should this bug be cloned?

Comment 7 Zdenek Kabelac 2020-12-15 15:26:01 UTC
See bug 1905705

Comment 24 errata-xmlrpc 2021-03-16 13:57:09 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 (lvm2 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:0863

Comment 25 Andrew Schorr 2021-03-24 12:38:55 UTC
This patch can't be right. The new version of detect_device_size in fsadm says:

# get the full size of device in bytes
detect_device_size() {
        # check if blockdev supports getsize64
        DEVSIZE=$("$BLOCKDEV" --getsize64 "$VOLUME" 2>"$NULL" || true)
        if test -n "$DEVSIZE" ; then
                DEVSIZE=$("$BLOCKDEV" --getsize "$VOLUME" || true)
                test -n "$DEVSIZE" || error "Cannot read size of device \"$VOLUME\"."
                SSSIZE=$("$BLOCKDEV" --getss "$VOLUME" || true)
                test -n "$SSSIZE" || error "Cannot read sector size of device \"$VOLUME\"."
                DEVSIZE=$(( $DEVSIZE * $SSSIZE ))
        fi
}

So it tries to get the size using --getsize64, and then it seems to attempt to test whether
it got back a non-empty result, but the sense of the test is inverted. It should say:

if test -z "$DEVSIZE" ; then

before falling back to using getsize/getss. As written, it falls back to using
getsize/getss when getsize64 actually works, but if getsize64 is absent, then it won't
fall back, and the user is screwed. And isn't getsize deprecated in favor of getsz?
Shouldn't this function actually read:

# get the full size of device in bytes
detect_device_size() {
        # check if blockdev supports getsize64
        DEVSIZE=$("$BLOCKDEV" --getsize64 "$VOLUME" 2>"$NULL" || true)
        if test -z "$DEVSIZE" ; then
                DEVSIZE=$("$BLOCKDEV" --getsz "$VOLUME" || true)
                test -n "$DEVSIZE" || error "Cannot read size of device \"$VOLUME\"."
                SSSIZE=$("$BLOCKDEV" --getss "$VOLUME" || true)
                test -n "$SSSIZE" || error "Cannot read sector size of device \"$VOLUME\"."
                DEVSIZE=$(( $DEVSIZE * $SSSIZE ))
        fi
}

In other words, please patch as follows:

 detect_device_size() {
        # check if blockdev supports getsize64
        DEVSIZE=$("$BLOCKDEV" --getsize64 "$VOLUME" 2>"$NULL" || true)
-       if test -n "$DEVSIZE" ; then
-               DEVSIZE=$("$BLOCKDEV" --getsize "$VOLUME" || true)
+       if test -z "$DEVSIZE" ; then
+               DEVSIZE=$("$BLOCKDEV" --getsz "$VOLUME" || true)
                test -n "$DEVSIZE" || error "Cannot read size of device \"$VOLUME\"."
                SSSIZE=$("$BLOCKDEV" --getss "$VOLUME" || true)
                test -n "$SSSIZE" || error "Cannot read sector size of device \"$VOLUME\"."

Regards,
Andy

Comment 26 Martin Pitt 2021-03-30 06:42:29 UTC
This still crashes in exactly the same way with lvm2-2.02.187-6.el7_9.5.x86_64 . Same in RHEL 8.4, as our automatic OS issue tracker shows: https://github.com/cockpit-project/bots/issues/1453

Please reopen (for some weird reason I can't)

Comment 27 Marius Vollmer 2021-03-30 07:45:37 UTC
I can't reproduce the crash with lvm2-2.02.187-6.el7_9.5.x86_64 on rhel-7-9.  The last time it happened in our CI on rhel-7-9 was 2021-02-04T03:14:56.333597.  So I'd say this is fixed on rhel-7-9 and there is no need to reopen this report.

Comment 28 Martin Pitt 2021-03-30 07:51:17 UTC
Thanks Marius, you are  right of course -- we still see that on CentOS 7 which hasn't picked up that fix yet. Sorry for the noise!

Comment 29 Marius Vollmer 2021-03-30 10:10:02 UTC
(In reply to Andrew Schorr from comment #25)
> This patch can't be right. The new version of detect_device_size in fsadm
> says:

I think you have a point, but it is unrelated to this bug report here as far as I can see. Could you open a new bug report?

Comment 30 Zdenek Kabelac 2021-03-30 10:24:55 UTC
There is actually no need to open a new bug for comment 25.
The incorrect logic just caused 2 extra calls of blockdev command - but all the numbers were still correct and there is no bug in fsadm behavior.
Also the issue has been already fixed upstream:

https://listman.redhat.com/archives/lvm-devel/2021-March/msg00263.html