Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-123523

[RHEL10.2] ZeroDivisionError when creating LVM volume without size specification

Linking RHIVOS CVEs to...Migration: Automation ...Sync from "Extern...XMLWordPrintable

    • rhel-system-roles-1.119.1-0.1.el10
    • None
    • Moderate
    • 1
    • rhel-system-roles
    • 0
    • Dev ack
    • False
    • False
    • Hide

      None

      Show
      None
    • Yes
    • Red Hat Enterprise Linux
    • SysRoles Parking Lot
    • Bug Fix
    • Hide
      Cause: The code was treating a volume with no size as having size 0.

      Consequence: Some of the size calculations would use this as the denominator when
      calculating percentage used or available, leading to a divide by zero error.

      Fix: If no size is specified, treat this as if the size were specified as 100%. That
      is, use all of the available space in the pool.

      Result: The code works as expected when no size is specified.
      Show
      Cause: The code was treating a volume with no size as having size 0. Consequence: Some of the size calculations would use this as the denominator when calculating percentage used or available, leading to a divide by zero error. Fix: If no size is specified, treat this as if the size were specified as 100%. That is, use all of the available space in the pool. Result: The code works as expected when no size is specified.
    • Proposed
    • Unspecified
    • Unspecified
    • Unspecified
    • None

                                                                                                                                         
      When creating an LVM volume without specifying a `size` parameter (using the default value `size: 0` from `defaults/main.yml`), the blivet module crashes with a `ZeroDivisionError`.

       Root Cause

      In `library/blivet.py` line 1127, the `_trim_size()` method performs a division operation:

      ```python
      def _trim_size(self, size, parent_device):
          trim_percent = (1.0 - float(parent_device.free_space / size)) * 100
          log.debug("size: %s ; %s", size, trim_percent)
          ...
      ```

      When `size` is `0` (the default value from `defaults/main.yml` line 36), this causes a division by zero error.

       

      ```yaml
      - name: Reproduce ZeroDivisionError
        hosts: all
        become: true
        vars:
          storage_safe_mode: false
          storage_pools:
            - name: test_pool
              type: lvm
              disks:
                - sda  # Change to an unused disk on your system
              volumes:
                - name: test_volume
                  # No size specified - uses default size: 0
                  fs_type: xfs
        roles:
          - rhel-system-roles.storage
      ```
       

      patch

      ```python
      def _trim_size(self, size, parent_device):    # If size is 0, use all available free space (auto-fill)
          if size == Size(0):
              log.info("auto-fill volume '%s': using all available free space (%s)",
                       self._volume['name'], parent_device.free_space)
              return parent_device.free_space    trim_percent = (1.0 - float(parent_device.free_space / size)) * 100
          log.debug("size: %s ; %s", size, trim_percent)
          ...
      ```
       

       

      rhel-system-roles-1.110.0-0.1.el10.noarch

      python3-blivet-3.10.0-23.el10.noarch

      6.12.0-141.el10.x86_64

              rmeggins@redhat.com Richard Megginson
              guazhang@redhat.com Guangwu Zhang
              Richard Megginson Richard Megginson
              Guangwu Zhang Guangwu Zhang
              Angana Chakraborty Angana Chakraborty
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Created:
                Updated: