11
29
Fork
You've already forked ipmitool
33

fix ipmitool crash with fru edit #12

Closed
ZhikuiRen wants to merge 5 commits from ZhikuiRen/ipmitool:master into master
pull from: ZhikuiRen/ipmitool:master
merge into: IPMITool:master
IPMITool:master
IPMITool:bugfix/43-Fix-timezone-and-DST-in-SEL
IPMITool:pages
IPMITool:bugfix/fix-ci-builds
IPMITool:feature/refactor-sdr-name-handling
IPMITool:cleanup/nm
IPMITool:feature/add-support-for-boot-mailbox
IPMITool:codefactor
IPMITool:bugfix/26
First-time contributor
Copy link

fix ipmitool crash with fru edit

First rebase
#1 with latest master

Then fix remaining issue:
fru edit command can increase fru size. Allocate new fru data with
the bigger size. This fixes ipmitool crash when fru edit increases fru
size.

Tested:
fru edit command that increases fru size complete successfully.

fix ipmitool crash with fru edit First rebase https://codeberg.org/IPMITool/ipmitool/pulls/1 with latest master Then fix remaining issue: fru edit command can increase fru size. Allocate new fru data with the bigger size. This fixes ipmitool crash when fru edit increases fru size. Tested: fru edit command that increases fru size complete successfully.
The current implementation of ipmitool fru edit does not perform proper
checks when attempting to resize the FRU. This results in undesireable
changes to the FRU in several instances:
1. If the FRU is shrinking and a FRU area does not exist (offset 0),
ipmitool may attempt to shift it forwards (decrementing the offset).
This results in a wraparound to 0xFF, leaving an erroneous field offset.
2. If the areas are not in the exact order given as an example in the
FRU spec, ipmitool may shift the wrong fields, which would cause data
loss. (the FRU spec does not specify a required order for FRU fields)
3. If the FRU is being enlarged after a fru field edit, the FRU size is
not properly modified before writing the FRU, so the end of the FRU
becomes truncated, resulting in data loss.
This commit addresses these three issues by:
1. Confirming that a area's does not have an offset of 0x00 before
attempting to shift it.
2. Ensuring that the area's offset is after the area that was modified
before attempting to shift it.
3. Properly edit the size of the FRU before the FRU is written.
Tested:
Shrinking a FRU was tested with and without the change:
New Header without change:
01 00 00 01 0a ff 00 f5
 ^^
Note that the Multi Record area now has an offset of 0xFF.
New Header with change:
01 00 00 01 0a 00 00 f4
 ^^
Note that the Multi Record area retains its offset of 0x00.
This change also includes printouts specifying what offsets are found
and when they are being shifted, as well as data being erased if the FRU
is being shrunk:
Offset: 0
Offset: 0
Offset: 8
Offset: 88 moving by -8 bytes.
Offset: 0
Erasing leftover data from 200 to 208
After shrinking the FRU, the FRU was reverted to its original state with
the fix in place:
01 00 00 01 0b 00 00 f3
 ^^
This resulted in only the product area offset being updated as expected.
Offset: 0
Offset: 0
Offset: 8
Offset: 80 moving by 8 bytes.
Offset: 0
The implementation of IPMI FRU write used in these tests errors out
without writing the FRU if a checksum fails to pass, so without this
fix, it was impossible to enlarge the FRU. This is because without the
change, the last 8 bytes of the FRU would be truncated which would
result in the checksum of the final FRU area being lost which would thus
trigger this FRU write failure.
Signed-off-by: Alex Schendel <alex.schendel@intel.com>
Replaced literal int with macro and fixed formatting errors.
Signed-off-by: Schendel <alex.schendel@intel.com>
fru edit command can increase fru size. Allocate new fru data with
the bigger size. This fixes ipmitool crash when fru edit increases fru
size.
Tested:
fru edit command that increases fru size complete successfully.
Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Reviewed-on: ZhikuiRen/ipmitool#1 
Lexden left a comment
Copy link

LGTM, thank you for refactoring my PR.
I am uncertain if the FRU_AREA_COUNT macro is desirable considering the refactoring that Alexander made in c27480c96e.

LGTM, thank you for refactoring my PR. I am uncertain if the FRU_AREA_COUNT macro is desirable considering the refactoring that Alexander made in [c27480c96e](https://codeberg.org/IPMITool/ipmitool/commit/c27480c96eed0591ec325449f8b23013bd221c4f).
ZhikuiRen changed title from (削除) master (削除ここまで) to fix ipmitool crash with fru edit 2023年10月02日 23:39:44 +02:00
Author
First-time contributor
Copy link

Close this one since the change has been merged into the original PR #1

Close this one since the change has been merged into the original PR https://codeberg.org/IPMITool/ipmitool/pulls/1
ZhikuiRen closed this pull request 2023年10月02日 23:46:17 +02:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
IPMITool/ipmitool!12
Reference in a new issue
IPMITool/ipmitool
No description provided.
Delete branch "ZhikuiRen/ipmitool:master"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?