RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1661160 - libblockdev can't resize LUKS 2 encrypted devices on RHEL 7.6
Summary: libblockdev can't resize LUKS 2 encrypted devices on RHEL 7.6
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libblockdev
Version: 7.6
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Vojtech Trefny
QA Contact: guazhang@redhat.com
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-12-20 08:51 UTC by Vojtech Trefny
Modified: 2021-09-03 14:08 UTC (History)
3 users (show)

Fixed In Version: libblockdev-2.18-4.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-08-06 12:59:43 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2019:2153 0 None None None 2019-08-06 12:59:44 UTC

Description Vojtech Trefny 2018-12-20 08:51:25 UTC
Description of problem:

Resize attempt of a LUKS 2 devices fails with "Failed to activate device: Invalid argument"

>>> BlockDev.crypto_luks_resize("/dev/mapper/test", 1024, "verysecretpassphrase")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/gi/overrides/BlockDev.py", line 235, in crypto_luks_resize
    return _crypto_luks_resize(luks_device, size, passphrase, key_file)
GLib.Error: g-bd-crypto-error-quark: Failed to activate device: Invalid argument (0)


Version-Release number of selected component (if applicable):
How reproducible:
Name        : libblockdev-crypto
Arch        : x86_64
Version     : 2.18
Release     : 3.el7

Comment 1 Vojtech Trefny 2018-12-20 09:05:33 UTC
Upstream PR: https://github.com/storaged-project/libblockdev/pull/414

Comment 4 guazhang@redhat.com 2019-03-29 07:54:57 UTC
Hello

Sorry, I need reproduces for the bug, Could you please share some test code for it ?

Comment 5 Vojtech Trefny 2019-04-02 14:06:59 UTC
```
import gi 
gi.require_version('BlockDev', '2.0') 

from gi.repository import BlockDev 
BlockDev.switch_init_checks(False) 

BlockDev.init(BlockDev.plugin_specs_from_names(["crypto"]))
BlockDev.crypto_luks_resize("/dev/mapper/test", 0, "passphrase")
```

Where "/dev/mapper/test" is an unlocked LUKS2 device and "passphrase" is passphrase for unlocking it.

Comment 6 guazhang@redhat.com 2019-04-03 10:07:27 UTC
Hello

Please have a look my failed.

# lsblk
NAME                                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
loop0                                 7:0    0    15G  0 loop  
loop1                                 7:1    0    15G  0 loop  
loop2                                 7:2    0    15G  0 loop  
loop3                                 7:3    0    15G  0 loop  
loop4                                 7:4    0    15G  0 loop  
loop5                                 7:5    0    15G  0 loop  
loop6                                 7:6    0    15G  0 loop  
└─vg01-lv01                         253:7    0    10G  0 lvm   
  └─mapper                          253:8    0    10G  0 crypt 
sda                                   8:0    0 931.5G  0 disk  
├─sda1                                8:1    0     1G  0 part  /boot
└─sda2                                8:2    0 930.5G  0 part  
  ├─rhel_storageqe--05-root         253:0    0    50G  0 lvm   /
  ├─rhel_storageqe--05-swap         253:1    0   7.9G  0 lvm   [SWAP]
  └─rhel_storageqe--05-home         253:2    0 872.6G  0 lvm   /home



# cat runtest.py 

#!/bin/env/python
import gi 
gi.require_version('BlockDev', '2.0') 
from gi.repository import BlockDev 
BlockDev.switch_init_checks(False) 
BlockDev.init(BlockDev.plugin_specs_from_names(["crypto"]))
BlockDev.crypto_luks_resize("/dev/mapper/mapper",10, "redhat redhat")


# python3 runtest.py 
Traceback (most recent call last):
  File "runtest.py", line 13, in <module>
    BlockDev.crypto_luks_resize("/dev/mapper/mapper",10, "redhat redhat")
  File "/usr/lib64/python3.6/site-packages/gi/overrides/BlockDev.py", line 235, in crypto_luks_resize
    return _crypto_luks_resize(luks_device, size, passphrase, key_file)
GLib.Error: g-bd-crypto-error-quark: Failed to resize device: Invalid argument (4)



# cat runtest.py 
# echo "redhat redhat > key_file"
#!/bin/env/python
import gi 
gi.require_version('BlockDev', '2.0') 
from gi.repository import BlockDev 
BlockDev.switch_init_checks(False) 
BlockDev.init(BlockDev.plugin_specs_from_names(["crypto"]))
BlockDev.crypto_luks_resize("/dev/mapper/mapper",10, "redhat redhat","key_file")


# python3 runtest.py 
Traceback (most recent call last):
  File "runtest.py", line 13, in <module>
    BlockDev.crypto_luks_resize("/dev/mapper/mapper",10, "redhat redhat","key_file")
  File "/usr/lib64/python3.6/site-packages/gi/overrides/BlockDev.py", line 235, in crypto_luks_resize
    return _crypto_luks_resize(luks_device, size, passphrase, key_file)
GLib.Error: g-bd-crypto-error-quark: Failed to activate device: Operation not permitted (0)

Comment 7 Vojtech Trefny 2019-04-03 12:05:23 UTC
I've tested this with a fresh 7.7 installation and it works for me.

Can you please try this again with this script:


```
from __future__ import print_function

import gi 
gi.require_version('BlockDev', '2.0') 

from gi.repository import BlockDev 
BlockDev.switch_init_checks(False)

BlockDev.utils_init_logging(lambda level, msg: print(msg))

BlockDev.init(BlockDev.plugin_specs_from_names(["crypto"]))
BlockDev.crypto_luks_resize("/dev/mapper/test", 0, "passphrase")
```

(The added line enables extra logging and prints cryptsetup log to stdout.)

Also please check libblockdev version and if it's linked against cryptsetup 2.

$ rpm -qa | grep blockdev
libblockdev-2.18-4.el7.x86_64
libblockdev-crypto-2.18-4.el7.x86_64
libblockdev-utils-2.18-4.el7.x86_64
python2-blockdev-2.18-4.el7.x86_64

$ ldd /usr/lib64/libbd_crypto.so.2 | grep cryptsetup
	libcryptsetup.so.12 => /lib64/libcryptsetup.so.12 (0x00007fef516ef000)

Comment 8 guazhang@redhat.com 2019-04-18 07:04:20 UTC
Hello

test passed, so move to verified 

thanks
Guazhang

Comment 10 errata-xmlrpc 2019-08-06 12:59:43 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, 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-2019:2153


Note You need to log in before you can comment on or make changes to this bug.