Bug 670910 - fence_scsi: need stricter regular expression when looking for specific keys
Summary: fence_scsi: need stricter regular expression when looking for specific keys
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: fence-agents
Version: 6.1
Hardware: All
OS: Linux
low
high
Target Milestone: rc
: ---
Assignee: Ryan O'Hara
QA Contact: Cluster QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-01-19 16:33 UTC by Ryan O'Hara
Modified: 2016-04-26 15:04 UTC (History)
3 users (show)

Fixed In Version: fence-agents-3.0.12-13.el6
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-05-19 14:21:53 UTC
Target Upstream Version:


Attachments (Terms of Use)
Fix regular expression used to grep for specific registration keys. (1.61 KB, patch)
2011-01-19 17:06 UTC, Ryan O'Hara
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2011:0745 0 normal SHIPPED_LIVE fence-agents bug fix and enhancement update 2011-05-19 09:37:09 UTC

Description Ryan O'Hara 2011-01-19 16:33:30 UTC
In fence_scsi, there are a handful of places where it will look to see if a specific key is registered for a device. Currently the code looks like this:

my @keys = grep { /$node_key/ } get_registration_keys ($dev);

This line of code will get all keys registered with a specific device and filter (grep) for the key we are interested in. The code typically then checks to see if @keys is empty. The problem is with the regular expression used for grep. It needs to be more specific to avoid false positives.

An example:

# register key "11" with device /dev/sdb
% /usr/sbin/fence_scsi -o on -k 11 -d /dev/sdb

# list keys register with device /dev/sdb
sg_persist -i -k /dev/sdb
  DELL      MD3000            0617
  Peripheral device type: disk
  PR generation=0x20, 2 registered reservation keys follow:
    0x11

# check to see if key "11" is registered with /dev/sdb
% /usr/sbin/fence_scsi -o status -k 11 -d /dev/sdb; echo $?
0 <-- correct

# check to see if key "2" is registered with /dev/sdb
% /usr/sbin/fence_scsi -o status -k 2 -d /dev/sdb; echo $?
2 <-- correct

# check to see if key "1" is registered with /dev/sdb
 /usr/sbin/fence_scsi -o status -k 1 -d /dev/sdb; echo $?
0 <-- incorrect

In this example, fence_scsi is incorrectly reporting that key "1" is registered with /dev/sdb because the regular expression is not specific. This fix is simple -- use anchors to make the regular expression more specific:

my @keys = grep { /^$node_key$/ } get_registration_keys ($dev);

Comment 2 Ryan O'Hara 2011-01-19 17:06:07 UTC
Created attachment 474324 [details]
Fix regular expression used to grep for specific registration keys.

Patch to fix problem described above.

Comment 3 Ryan O'Hara 2011-01-19 17:08:55 UTC
Here is test of fence_scsi with patch:

# register key "11" with device /dev/sdb
% ./fence_scsi -o on -k 11 -d /dev/sdb

# list keys register with device /dev/sdb
sg_persist -i -k /dev/sdb
  DELL      MD3000            0617
  Peripheral device type: disk
  PR generation=0x20, 2 registered reservation keys follow:
    0x11

# check to see if key "11" is registered with /dev/sdb
% ./fence_scsi -o status -k 11 -d /dev/sdb; echo $?
0 <-- correct

# check to see if key "2" is registered with /dev/sdb
% ./fence_scsi -o status -k 2 -d /dev/sdb; echo $?
2 <-- correct

# check to see if key "1" is registered with /dev/sdb
% ./fence_scsi -o status -k 1 -d /dev/sdb; echo $?
2 <-- correct

Comment 4 Ryan O'Hara 2011-01-21 18:42:26 UTC
Pushed to RHEL6 branch.

commit cecc4a5fd1e3f494d6f7cf2eeded1a5b77336336

Comment 6 Dean Jansa 2011-03-29 16:10:24 UTC
[root@marathon-05 sbin]# ./fence_scsi -o on -k 11 -d /dev/sdb
Mar 29 11:08:25 fence_scsi: [debug] main::do_register_ignore (node_key=11, dev=/dev/sdb)
Mar 29 11:08:25 fence_scsi: [debug] main::do_reset (dev=/dev/sdb, status=0)
[root@marathon-05 sbin]# sg_persist -i -k /dev/sdb
  WINSYS    SA3478            347C
  Peripheral device type: disk
  PR generation=0x62, 1 registered reservation key follows:
    0x11
[root@marathon-05 sbin]# ./fence_scsi -o status -k 11 -d /dev/sdb; echo $?
Mar 29 11:08:38 fence_scsi: [debug] main::do_reset (dev=/dev/sdb, status=0)
0
[root@marathon-05 sbin]# ./fence_scsi -o status -k 2 -d /dev/sdb; echo $?
Mar 29 11:08:45 fence_scsi: [debug] main::do_reset (dev=/dev/sdb, status=0)
2
[root@marathon-05 sbin]# ./fence_scsi -o status -k 1 -d /dev/sdb; echo $?
Mar 29 11:08:51 fence_scsi: [debug] main::do_reset (dev=/dev/sdb, status=0)
2


Verified in fence-agents-3.0.12-21.el6

Comment 7 errata-xmlrpc 2011-05-19 14:21:53 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0745.html


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