• Mauricio Faria de Oliveira's avatar
    block: allow WRITE_SAME commands with the SG_IO ioctl · f142c511
    Mauricio Faria de Oliveira authored
    commit 25cdb645 upstream.
    
    The WRITE_SAME commands are not present in the blk_default_cmd_filter
    write_ok list, and thus are failed with -EPERM when the SG_IO ioctl()
    is executed without CAP_SYS_RAWIO capability (e.g., unprivileged users).
    [ sg_io() -> blk_fill_sghdr_rq() > blk_verify_command() -> -EPERM ]
    
    The problem can be reproduced with the sg_write_same command
    
      # sg_write_same --num 1 --xferlen 512 /dev/sda
      #
    
      # capsh --drop=cap_sys_rawio -- -c \
        'sg_write_same --num 1 --xferlen 512 /dev/sda'
        Write same: pass through os error: Operation not permitted
      #
    
    For comparison, the WRITE_VERIFY command does not observe this problem,
    since it is in that list:
    
      # capsh --drop=cap_sys_rawio -- -c \
        'sg_write_verify --num 1 --ilen 512 --lba 0 /dev/sda'
      #
    
    So, this patch adds the WRITE_SAME commands to the list, in order
    for the SG_IO ioctl to finish successfully:
    
      # capsh --drop=cap_sys_rawio -- -c \
    ...
    f142c511
scsi_ioctl.c 19.8 KB