{"article":{"slug":"beyond-the-compiler-making-ibm-i-run-modified-native-code-program-validation-value","title":"Beyond the compiler: Making IBM i run modified native code - Program Validation Value","subtitle":null,"summary":"Silent Signal reconstructs IBM i's Program Validation Value (PVV), the check that stops modified native program code from running after restore, and shows a repeatable workflow (with an open pvv-ibmi release) for executing changed native code in controlled research settings.","content_type":"research","language":"en","canonical_url":"https://blog.silentsignal.eu/2026/11/10/Beyond-the-compiler-Making-IBM-i-run-modified-native-code-PVV/","author":{"name":"pz","url":"https://blog.silentsignal.eu/authors/pz.html","person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"Silent Signal","url":"https://blog.silentsignal.eu/","listing_slug":null,"listing":null},"topics":[{"name":"security","slug":"security","url":"https://listedarticles.com/topics/security"},{"name":"reverse-engineering","slug":"reverse-engineering","url":"https://listedarticles.com/topics/reverse-engineering"},{"name":"research","slug":"research","url":"https://listedarticles.com/topics/research"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":3705,"reading_minutes":16,"published_at":"2026-11-10T08:00:00.000Z","added_at":"2026-11-12T23:08:45.299Z","updated_at":"2026-11-12T23:08:45.299Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/beyond-the-compiler-making-ibm-i-run-modified-native-code-program-validation-value","markdown_url":"https://listedarticles.com/articles/beyond-the-compiler-making-ibm-i-run-modified-native-code-program-validation-value.md","example":false,"citation":"pz, Silent Signal. \"Beyond the compiler: Making IBM i run modified native code - Program Validation Value.\" 10 Nov 2026. https://blog.silentsignal.eu/2026/11/10/Beyond-the-compiler-Making-IBM-i-run-modified-native-code-PVV/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://blog.silentsignal.eu/2026/11/10/Beyond-the-compiler-Making-IBM-i-run-modified-native-code-PVV/"},"body_markdown":"![Beyond the compiler: Making IBM i run modified native code - Program Validation Value](https://blog.silentsignal.eu/img/door.gif)\n\n# Beyond the compiler: Making IBM i run modified native code - Program Validation Value\n\n[pz](https://blog.silentsignal.eu/authors/pz.html) 2026-11-10\n\n## Why this matters\n\nIBM i does not treat an application program as a normal file that happens to\ncontain POWER instructions. A compiler produces Machine Interface (MI) code,\nIBM i’s stable instruction-level boundary, and the system translates it into a\nnative form. The generated native code contains checks that support the IBM i\nobject and tagged-pointer model.\n\nChanging those instructions can make IBM i execute behavior that was not\npresent in the MI input. Earlier\n[Below MI research](https://silentsignal.github.io/BelowMI/) examined the wider\nconsequences on IBM i V7R4. Here I focus on the IBM i 7.5\n[Program Validation Value (PVV)](https://www.ibm.com/docs/ssw_ibm_i_74/rzamv/rzamvprotectagainstviruses.htm),\na 32-byte value stored with a saved program.\n\nI reconstructed the 32-byte PVV calculation and matched all 1,223 known-valid\nvalues. The reconstructed calculation derives its HMAC key entirely from saved\nprogram attributes and fixed Licensed Internal Code (LIC) constants; it\ncontains no separate secret for origin authentication. IBM i applies separate\ndigital-signature checks where required. In controlled USER-state programs—the\nordinary, non-SYSTEM execution mode—recalculating PVV and the separate save-file\nchecks allowed selected native instruction changes to survive restore and\nresave. A disposable CrackMe produced the expected changed output,\ndemonstrating execution.\n\nUSERB1, an ordinary test account without special authorities, restored a\nUSERB1-owned, PVV-repaired `MEMDUMP` program through IBM’s Restore Object List\n(`QSRRSTO`) API, and a resave preserved its modified native instructions. Its\nexecutable payload matched byte-for-byte the payload used in a controlled\nruntime test. In that test, `MEMDUMP` ran as USERB1 and read from a known-address\nUSER-domain buffer in a cooperating job running under QSECOFR, IBM i’s\nsecurity-officer profile. Other controls showed IBM i rejecting unsigned SYSTEM\nand INHERIT program-state variants and enforcing the SYSTEM-domain access\nboundary.\n\nMy [previous article](https://blog.silentsignal.eu/2026/10/06/512-bytes-at-a-time-reconstructing-IBM-i-save-file-checksums/)\ncovered the outer save file (SAVF) container: its per-record checksums and\nglobal checksum. During restore, IBM i also calculates PVV and compares it\nwith four values stored in the saved program.\n\nThe USER-state controls ran under the test system’s existing\n[restore-policy system values](https://www.ibm.com/docs/en/i/7.5.0?topic=40-validation-programs-being-restored)\n(`QVFYOBJRST=3`, `QFRCCVNRST=1`, and `QALWOBJRST=*ALL`) at\n[QSECURITY 40](https://www.ibm.com/docs/en/i/7.5.0?topic=reference-using-system-security-qsecurity-system-value),\nwhich enforces resource security and integrity protection.\n\n## Program validation and research approach\n\nSAVF record and global checks establish container consistency; PVV establishes\nconsistency with selected serialized program data. LIC copies the 32-byte\ndescriptor unchanged into the HMAC key object. Every descriptor byte\ncomes from saved program attributes or fixed LIC constants, and the recovered\npath contributes no additional secret. A party with the serialized program and\nthe reconstructed algorithm can therefore derive the key and recompute PVV; a\nmatch establishes consistency, not trusted origin. Restore authorization and\nsystem policy still govern the operation, while digital signatures authenticate\norigin where required.\n\nA program has separate\n[state and domain attributes](https://www.ibm.com/docs/en/i/7.5.0?topic=40-preventing-use-unsupported-interfaces).\nIts execution state is USER, SYSTEM, or INHERIT; INHERIT uses the caller’s\nstate. The program object itself has a USER or SYSTEM domain, and that saved\nattribute contributes separately to the PVV descriptor. Other objects accessed\nby the executing code also have domains. The USER domain is a storage-domain\nclassification, not a user identity or ownership boundary. At QSECURITY 40,\nUSER-state code cannot directly access SYSTEM-domain objects.\n\n### The algorithm at a glance\n\n```\nPVV = HMAC-SHA-256(descriptor, canonical_message)\n```\n\nPVV is calculated in four steps for the supported program format:\n\n1. Walk the saved program graph, select the protected byte ranges, normalize\n   saved pointers, and put the ranges into canonical-message order.\n2. Build a 32-byte descriptor from program attributes and constants chosen\n   by the recovered state, domain, version, release, and mode selectors.\n3. Use the descriptor as the HMAC key and the canonical message as the input to\n   HMAC-SHA-256.\n4. Split the result into four 64-bit values and compare them with the stored\n   values.\n\n### Leif Svalgaard’s earlier PVV work was a clue\n\nLeif Svalgaard described the earlier mechanism in Chapter 15, “Program\nValidation Value,” of [AS/400 Machine Level Programming](https://web.archive.org/web/20220523023735/https://svalgaard.leif.org/as400/mlp0tc.htm).\nHis [public program index](https://web.archive.org/web/20220523023735/https://svalgaard.leif.org/as400/programs/index.htm)\nalso lists `MIPGMVV`, which calculates an eight-byte value from program\nattributes. I reproduced his published example. Its four selector constants do\nnot match the current LIC descriptor constants in either byte order, but both\ndesigns select values according to state and domain. That similarity pointed\nme toward the current 32-byte validation route.\n\n## Finding the validator\n\nI started with `CHKOBJITG`, the IBM i command that checks object integrity.\n\nFor a program, `CHKOBJITG` reaches the IBM-supplied `QSYS/QSYCHKIT` program.\nIts native procedure `QSYINTEGRI::checkPgmMod` contains this sequence, copied\nfrom the retained IBM Display/Alter/Dump (DAD) output:\n\n```\n2B463690C5 0052B4  0000D4  62E30000  ORI 3,23,0\n2B463690C5 0052B8  0000D8  39400103  ADDI 10,0,259\n2B463690C5 0052BC  0000DC  44000141  SCV 10\n```\n\n`ADDI` loads selector 259 into `r10`; the following `SCV 10`, Supervisor Call\nVectored, enters dispatcher vector 10. The `10` in the mnemonic identifies the\nvector, while the value in `r10` selects the service. That combination led to\nthis observed call path:\n\n```\nQSYCHKIT/QSYINTEGRI::checkPgmMod\n  -> #cfmir\n  -> #dotssob\n  -> VBNTSSOB::#bntssob\n  -> VBNTSSOB::vbnskew4\n  -> VBNNAPE2::vbnspnt2\n```\n\nThe live capture tied the path to the loaded address of my `CALLAES` test\nfixture. I matched the remaining code against the IBM i 7.5 LIC from\ninstallation media by procedure name, normalized instruction sequence, call\ntopology, constants, and tables. The live instructions and invocation frames\nidentify the observed `CHKOBJITG` route; the build-matched LIC supplies the\ncomplete procedure bodies. For both `VBNTSSOB` and `VBNNAPE2`, the installation\naddresses were `0x3000` above the captured live addresses and the normalized\nbodies agreed; that displacement is evidence for this match, not an IBM i\naddressing rule.\n\n## Reconstructing PVV\n\nMy parser supports uncompressed IBM i 7.5 program (`*PGM`) and service-program\n(`*SRVPGM`) items whose record graph, section descriptors, and 40-bit segment\nidentity plus 24-bit in-segment pointer mapping follow the recovered layout. It\nrejects other layouts before calculation instead of trying models until one\nhappens to match the stored result.\n\n### The stored result\n\n`vbnspnt2` writes 32 calculated bytes, loads them as four 64-bit doublewords,\nand compares them with four values stored in different parts of the program\ngraph. Any mismatch returns false.\n\nFor `CALLAES`, the item starts at SAVF logical offset `0x4000`. The item-relative\noffset must first be converted to a SAVF logical offset. That logical coordinate\ncounts only 512-byte payloads; the physical coordinate also counts each\n16-byte record trailer:\n\n```\nlogical = 0x4000 + item_offset\nphysical = (logical // 512) * 528 + (logical % 512)\n```\n\nApplying both stages gives these four locations:\n\n| Part | Item offset | Logical SAVF offset | Physical SAVF offset | Stored bytes |\n| --- | --- | --- | --- | --- |\n| 0 | `0x22C0` | `0x62C0` | `0x65D0` | `E8DC295506AFD7E6` |\n| 1 | `0x4B78` | `0x8B78` | `0x8FC8` | `9794394254EF4224` |\n| 2 | `0x21F8` | `0x61F8` | `0x64F8` | `8EAD0FB7B8C3AB42` |\n| 3 | `0x2648` | `0x6648` | `0x6978` | `307B34648AE1C331` |\n\nIn comparison order, the stored PVV is:\n\n```\nE8DC295506AFD7E69794394254EF4224\n8EAD0FB7B8C3AB42307B34648AE1C331\n```\n\n### Building the canonical message\n\nLIC follows a graph of program headers, components, procedure records, native\nsections, counted arrays, and optional records. It adds selected byte ranges,\nnot the complete program item.\n\nSaved pointers cannot be hashed directly because their segment identities may\nchange after restore. LIC replaces them with a stable segment number and the\noffset inside that segment. For example:\n\n```\nsaved pointer:       10804C6DE6001520\nsegment number:                       1\nsegment offset:                  0x1520\ncanonical value:    0000000100001520\n```\n\nLIC also changes the order of some data. Appends shorter than `0x400` bytes are\ncopied into one owned stream. Appends of `0x400` bytes or more remain separate\nentries. The final HMAC message contains the complete copied stream first,\nfollowed by the retained entries.\n\nHere, an aggregate entry is one buffer passed to the HMAC update path.\n\nIf the logical append order is a short span `A`, a retained span `B`, and a\nshort span `C`, the message order is `A || C || B`.\n\nFor `CALLAES`, 65 logical appends became three aggregate entries:\n\n| Entry | Length | Message offset |\n| --- | --- | --- |\n| copied spans | `0x1234` | `0x0000` |\n| retained span 1 | `0x0610` | `0x1234` |\n| retained span 2 | `0x0870` | `0x1844` |\n\nThe final message length was `0x20B4`, or 8,372 bytes.\n\n### Building the descriptor\n\nThe descriptor contains four 64-bit values:\n\n1. one value formed by joining two four-byte program header fields;\n2. a fixed constant selected by state, domain, and version class;\n3. a constant selected by the target release;\n4. a constant selected by the recovered mode.\n\n“Version class” and “mode” are names for reconstructed selector inputs. I do\nnot present them as documented SAVF field names.\n\nWithin the retained fixtures, the recovered `version_kind=0x0028` input selects\none version class by contributing 0 to the table index; other observed values,\nincluding `CALLAES`’s `0x000A`, contribute 1. With `CALLAES`’s USER state and\ndomain, that selects `2E9132CE813F75B2`. The mode byte independently selects\nthe fourth 64-bit descriptor value: mode 1 selects `3809245098034DDE`, while\nmode 2 selects `3809745098034DDE`.\n\nCanonical program-state values are `0x0001` for USER, `0x0080` for SYSTEM, and\n`0x0000` for INHERIT. For descriptor selection, the state selector treats\n`0x0080` as SYSTEM, `0x0000` as INHERIT, and every other value as the remaining\nselector class. The domain selector tests the least significant bit of program\nbase byte `+0x20`—bit 7 in IBM’s MSB-0 numbering. In the `CALLAES` fixture the\nbyte was `0x80`; that bit is clear, so the program domain was USER. A byte of\n`0x81` selects SYSTEM program domain. This byte is separate from the 16-bit\nstate value `0x0080`.\n\nFor `CALLAES`, the selected descriptor was:\n\n```\nC884EBDE4ED4E62B2E9132CE813F75B2\n83CF578390004BA13809245098034DDE\n```\n\nThe calculation selects these fixed tables without consulting the stored PVV.\n\n### The cryptographic operation\n\nThe lower LIC code creates a key object, copies all 32 descriptor bytes into\nit, and feeds each aggregate entry to a message digest object. The next layer\nimplements the standard HMAC construction with a 64-byte block,\nthe `0x36` inner pad, the `0x5C` outer pad, and SHA-256.\n\nThe recovered calculation maps directly to Python’s standard HMAC\nimplementation:\n\n```\nimport hashlib\nimport hmac\n\ncalculated = hmac.new(\n    descriptor,\n    canonical_message,\n    hashlib.sha256,\n).digest()\n```\n\nFor `CALLAES`, it returns the exact 32 stored bytes shown above.\n\n## Offline validation\n\nI applied the recovered model to IBM-supplied save-file items and disposable\nprograms and service programs. The corpus measures agreement and structural\ncoverage over supported rows, not blind holdout or live restore and execution\ntests. The final totals were:\n\n```\nknown valid exact matches:        1,223\ndeliberate mutation fixtures:        16\nsuccessfully parsed rows:         1,239\nunsupported program items:           17\ntotal attempted items:            1,256\ndistinct structure profiles:      1,003\nunexplained mismatches:                0\n```\n\nA structure profile fingerprints object type, release and version selectors,\nmode, record shapes, and canonical-chunk construction without including the\nprotected byte values. The 1,003 profiles occur among the 1,223 known-valid\nrows; repeated saves or equivalent layouts can share one. The 16 deliberate\nmutation fixtures remained invalid. The parser rejected another 17 items\nbefore calculation: seven had malformed section descriptors or descriptors\nthat did not expose the validated 40-bit segment and 24-bit offset mapping, and\nten contained pointers that could not be mapped unambiguously to a recovered\nsegment. These are unsupported structures, not unexplained PVV mismatches.\n\nI produced these results with the local `pvv-ibmi` tool bundle. `pvv_demo.py`\nis its command-line entry point, `savf_checksum_demo.py` implements the SAVF\nchecks, and `scripts/reconstruct_v7r5_pvv.py` parses the program graph and\ncalculates PVV. I plan to publish the bundle and its usage notes in the\n[Silent Signal IBM i PVV repository](https://github.com/silentsignal/pvv-ibmi/).\n\nThe `--table` argument specifies `sandbox.ser`, which contains the lookup table\nused for the SAVF global checksum. I described its extraction in my\n[previous SAVF checksum article](https://blog.silentsignal.eu/2026/10/06/512-bytes-at-a-time-reconstructing-IBM-i-save-file-checksums/).\n\nThe tool’s two main commands are:\n\n```\npython3 pvv_demo.py --table sandbox.ser check input.FILE\npython3 pvv_demo.py --table sandbox.ser fix modified.FILE repaired.FILE\n```\n\n`check` verifies the SAVF checks and PVV. `fix` calculates PVV, writes the\nfour stored values, repairs the separate SAVF checks, and verifies the output\nin a new file while preserving the intended native change.\n\n## Live restore controls\n\nThe offline matches establish the calculation. The following controls test how\nrestore consumes the stored value, whether edited native code survives, and\nwhether IBM i executes the changed control flow.\n\n### A stale stored value\n\nIn the `P7QPM831` test program, I changed one stored PVV byte but left the\nprotected program data unchanged. I repaired only the SAVF checks. `CPC3703`\ndenotes normal restore completion in the baseline and corrected controls.\n\n| Input | PVV | SAVF checks | Result |\n| --- | --- | --- | --- |\n| baseline | valid | valid | `CPC3703`, process status 0 |\n| one stale byte | invalid | valid | `CPF3848`, `CPF3773`, process status 255 |\n| corrected value | valid | valid | `CPC3703`, process status 0 |\n\nThe stale restore created an object, which I then saved again. The calling\nprocess returned status 255, while the substituted restore messages recorded\nthe actual object counts:\n\n```\nCPF3848: 1 security or data format changes occurred.\nCPF3773: 1 objects restored. 0 not restored.\n```\n\nThe resaved object still contained the incorrect stored value. Writing the\nindependently calculated value restored normal completion. The mismatch was\ntherefore detected and changed the command outcome, but did not prevent object\ncreation in this control.\n\n### A native change that survived\n\nThe `RISCPVV1` test program measured native-code preservation without changing\nbehavior. I replaced one instruction with a different instruction that copies\nthe same register value:\n\n```\nbefore  60860000  ORI 6,4,0\nafter   7C862378  OR 6,4,4\n```\n\nThe saved creation material—the input IBM i can use to recreate native\ncode—remained unchanged. To distinguish preserved native code from code\nrecreated from that material, I repaired PVV and the SAVF, restored the object,\nand saved it again. The executable payload was eight native records joined in\ngraph order after removing each record’s final eight-byte saved-space pointer,\nwhich is metadata rather than executable payload.\n\nAll 1,120 executable bytes matched between the modified and resaved streams;\nthe original differed at the edited instruction. The 40-bit segment-identity\nprefixes within those trailing pointers changed as expected when\nIBM i materialized the object; their 24-bit in-segment offsets did not. The\nexecutable payload and repaired PVV remained unchanged.\n\n### CrackMe: a branch that changed behavior\n\n`PVVPASS`, which I call CrackMe here, provided the visible control. This\ndisposable fixture compared its argument with `silentsignal`, printed\n`pwd is ok` for a match, and printed `wrong` otherwise.\n\nThe retained source was:\n\n```\n#include <stdio.h>\n#include <string.h>\n\nint main(int argc, char **argv)\n{\n    if (argc > 1 && strcmp(argv[1], \"silentsignal\") == 0)\n        puts(\"pwd is ok\");\n    else\n        puts(\"wrong\");\n    return 0;\n}\n```\n\nI compiled it as a native Integrated Language Environment (ILE) C program with\n`DBGVIEW(*NONE)`, `OPTIMIZE(40)`, and `ACTGRP(*CALLER)`, then saved it without\ncompression.\n\nThe relevant saved instructions are below in reconstructed DAD style. Register\n5 holds the current input byte. Register 0 holds the current expected byte.\n\n```\n1E75B1F2E2001F78  2C250000  CMPI   0,1,5,0\n1E75B1F2E2001F7C  397E0010  ADDI   11,30,16\n1E75B1F2E2001F80  387FFFC0  ADDI   3,31,-64\n1E75B1F2E2001F84  63CC0000  ORI    12,30,0\n1E75B1F2E2001F88  78CAC1C6  RLDICR 10,6,56,7\n1E75B1F2E2001F8C  7C0103E6  SETTAG\n1E75B1F2E2001F90  7CA50040  CMPL   1,1,5,0\n1E75B1F2E2001F94  40860048  BC     4,6,0X48\n1E75B1F2E2001F98  41820014  BC     12,2,0X14\n1E75B1F2E2001F9C  8CA40001  LBZU   5,0X1(4)\n1E75B1F2E2001FA0  2C250000  CMPI   0,1,5,0\n1E75B1F2E2001FA4  8C0C0001  LBZU   0,0X1(12)\n1E75B1F2E2001FA8  4BFFFFE8  B      0X3FFFFE8\n```\n\nThe first `CMPI` sets `CR0.EQ` from the input byte. The instructions before\n`CMPL` do not change CR0. `SETTAG` affects the tag state, not the condition\nregisters. `CMPL 1,1,5,0` sets `CR1.EQ` from the comparison of the input and\nexpected bytes.\n\nThe branch at `0x1E75B1F2E2001F94` tests `CR1.EQ` and reaches the failure block\nwhen the bytes differ. The next branch tests `CR0.EQ` and reaches success when\nthe input byte is zero. Equal nonzero bytes continue the loop.\n\nThe encoded displacements make the control flow explicit:\n\n```\n0x1E75B1F2E2001F94 + 0x48 -> 0x1E75B1F2E2001FDC  failure\n0x1E75B1F2E2001F98 + 0x14 -> 0x1E75B1F2E2001FAC  success\n0x1E75B1F2E2001FA8 - 0x18 -> 0x1E75B1F2E2001F90  next comparison\n```\n\nThe saved text supports that mapping: `silentsignal` is at logical offset\n`0x69B0`, `pwd is ok` at `0x69C0`, and `wrong` at `0x69D0`. The success block\nselects the text at `r30+0x10`; the failure block selects `r30+0x20`.\n\nI replaced only the mismatch branch:\n\n```\nbefore  40860048  BC 4,6,0X48\nafter   60000000  ORI 0,0,0\n```\n\nThe variants produced this result:\n\n| Saved variant | PVV | Instruction after resave | Output for incorrect input |\n| --- | --- | --- | --- |\n| baseline | valid | original branch | `wrong` |\n| changed branch, stale PVV | stale | original branch | `wrong` |\n| changed branch, repaired PVV | valid | changed instruction | `pwd is ok` |\n\nThe repaired program printed `pwd is ok` for both `nope` and `x`. A fresh save\nof the repaired object still contained `60000000` at the instruction site\nidentified from the object structure.\n\n### Restore access: command and API controls\n\nIBM’s documented\n[Restore Object List (`QSRRSTO`) API](https://www.ibm.com/docs/en/i/7.5.0?topic=ssw_ibm_i_75%2Fapis%2Fqsrrsto.html)\nhas a different authority model from the Restore Object (`RSTOBJ`) command.\nIBM has documented its default public authority as `*USE` since the\n[2006 Backup and Recovery APIs manual](https://public.dhe.ibm.com/systems/power/docs/systemi/v5r4/en_US/backup.pdf).\nThat permits calling the API; it does not supply the user-space, save-file,\nlibrary, or target-object authorities required for a restore. Callers without\nthe `*SAVSYS` save-system special authority must satisfy those documented\nauthority requirements, as USERB1 did within its test library.\n\nFor the end-to-end control, I rebuilt CrackMe from the retained source and the\nsame compiler settings. I resolved the patch location from the new SAVF. The\nrebuilt program contained the same `40860048` mismatch branch at native record\n1 offset `0xB4`. I created baseline, branch-edited/stale-PVV, and\nbranch-edited/repaired-PVV variants; all three had valid SAVF checks.\n\nWith the repaired SAVF loaded into save file `TESTSAVF` in the USERB1 library\nand the target absent, `RSTOBJ` failed with `CPD0032` (not authorized to the\ncommand) and created no program. To test the API separately, I used a small,\nlocally written USERB1-owned program that called `QSRRSTO` directly and restored\n`PVVPASS` into the USERB1 library. Both the caller and a small USERB1-owned\nwrapper that recorded the job context before and after invoking the caller were\n`USRPRF(*USER)` and `USEADPAUT(*NO)`, so they neither adopted their owners’\nauthority nor used authority adopted higher in the call stack. In the same job,\nthe wrapper used IBM’s Retrieve Job Attributes command (`RTVJOBA`) to report\ncurrent user `USERB1` immediately before and after the API call.\n\nUnder this authority context, the repaired variant produced the CrackMe output\nreported above. Its resave retained `60000000` at native record 1 offset\n`0xB4`, and its 1,032-byte executable payload matched the repaired input after\nthe final eight-byte saved-space pointer was removed from each native record.\n\nThe stale-PVV API control restored with the original branch and printed\n`wrong` instead. This was one end-to-end test within USERB1’s authorized object\nscope: command denial, API restore, execution, and resave.\n\nI then rebuilt `MEMDUMP` entirely as USERB1, applied the native edits to its\nsaved representation, and repaired PVV and the SAVF checks. Running as USERB1,\nI called `QSYS/QSRRSTO`; it created the `MEMDUMP` program in the USERB1 library\nas a USER-state, USER-domain program owned by USERB1, with `USRPRF(*USER)` and\n`USEADPAUT(*NO)`. A fresh save retained both modified instruction sites. The\nrepaired input, the USERB1-restored resave, and the distinct program object used\nfor the memory-read test had byte-for-byte identical 1,496-byte executable\npayloads.\n\n## Signature, state, and domain boundaries\n\nThe native code controls above used USER state. I also tested the separate\nstate, domain, and signature boundaries.\n\n| Control | Result |\n| --- | --- |\n| USER to SYSTEM state, PVV repaired | IBM i rejected it as unsigned with `CPD37A0`, then `CPF3770` (no object restored) |\n| USER to INHERIT state, PVV repaired | IBM i rejected it as unsigned with `CPD37A0`, then `CPF3770` (no object restored) |\n| USER state, USER to SYSTEM domain, PVV repaired | IBM i restored it with `CPC3703`; a USER-state call failed with `MCH6801` domain violation |\n\nThe repaired SYSTEM-state fixture passed the offline reconstructed PVV check,\nbut the live restore failed the digital signature requirement:\n\n```\noffline PVV validation         PASS\nlive trusted-signature check   FAIL\n```\n\nI also traced the complete 16-bit state field. The relevant LIC branches reduce\nto this classification before the signature service is called:\n\n```\nstate 0x0001 -> record flag 0\nstate 0x8000 -> record flag 0\nall other 65,534 values -> record flag 1\n```\n\nThe flag is an input to the later signature path, not the final restore result\nby itself. Canonical SYSTEM state is `0x0080`, and INHERIT state is `0x0000`;\nboth produce flag 1. The activation resolver separately treats `0x0000` as\nINHERIT, selects SYSTEM only for `0x0080`, and sends `0x0001`, `0x8000`, and\nother noncanonical values to USER. I found no state value that both takes the\nflag 0 path and activates as SYSTEM on this route.\n\nThe `0x8000` state value is not SYSTEM state. It restored and activated as\nUSER in the live control. The same hexadecimal value appears as the two-byte\ndomain contribution for SYSTEM domain, but that is another field.\n\n## Security impact\n\nUnder the tested conditions, externally modified USER-state native code\nbypassed a compiler-generated pointer-validation sequence and performed a\nmemory access that the original compiled code could not. CrackMe independently\nestablished execution of modified native bytes; the controlled `MEMDUMP`\nruntime test established this consequence.\nThe compiler-generated path used `LQ` to load the 128-bit pointer and record\nits tag status, `TXER` to check that status, and `_SETSPPFP` (Set Space Pointer\nfrom Pointer) before the memory access. At native section offset `+0x220C`, I\nreplaced the first two instructions with a direct native load and branch:\n\n```\n; original\n2f3708714600220c:  e2dfff9b  LQ         22,0XFF90(31),11\n2f37087146002210:  7c0004c8  TXER       0,0,41\n; replacement\n2f3708714600220c:  eb7fff98  LD         27,0XFF98(31)\n2f37087146002210:  48000028  B          0X28\n; later target access\n2f370871460022b8:  889b0000  LBZ        4,0X0(27)\n```\n\nThe source had copied the supplied 64-bit address into this `r31`-relative\nslot; the `LD` loads it into `r27`, and the branch continues at `+0x2238`. The\nlater `LBZ` at `+0x22B8` performs the byte read through `r27`. With the same\nsupplied address, the unmodified `MEMDUMP` failed with\n`MCH3601` (pointer not set). The modified code bypassed the generated validation\nsequence and, when invoked as USERB1, returned the exact expected 32 bytes from\na known-address USER-domain buffer belonging to a cooperating QSECOFR job. The\ntarget address was supplied by the cooperating QSECOFR job; obtaining such an\naddress independently is a separate prerequisite.\n\nFor the supported saved-program format, the derivable HMAC key makes PVV a\nrecomputable consistency check. With an editable SAVF and an authorized restore\npath, recalculating PVV and the SAVF checks preserved the tested USER-state\nnative changes. Separate controls enforced trusted signatures for the tested\nSYSTEM and INHERIT variants and blocked USER-state access to SYSTEM-domain\nstorage.\n\n## Conclusion\n\nPVV was the missing piece between editing saved native POWER instructions and\npreserving them through IBM i restore so that the modified code could execute.\nReconstructing it turned that obstacle into a repeatable research workflow:\nCrackMe demonstrated changed native control flow, while `MEMDUMP` showed its\npractical consequence in a controlled, known-address USER-domain read. The PVV\nreconstruction is not by itself a vulnerability or a signature bypass; the\n`pvv-ibmi` release accompanying this article lets other researchers reproduce\nthe calculation and use the same workflow, while restore authorization,\ntrusted signatures, and domain enforcement remain separate boundaries.\n","body_html":"<figure><img src=\"https://blog.silentsignal.eu/img/door.gif\" alt=\"Beyond the compiler: Making IBM i run modified native code - Program Validation Value\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></figure>\n<h1 id=\"beyond-the-compiler-making-ibm-i-run-modified-native-code-progra\">Beyond the compiler: Making IBM i run modified native code - Program Validation Value</h1>\n<p><a href=\"https://blog.silentsignal.eu/authors/pz.html\" rel=\"nofollow ugc noopener\">pz</a> 2026-11-10</p>\n<h2 id=\"why-this-matters\">Why this matters</h2>\n<p>IBM i does not treat an application program as a normal file that happens to\ncontain POWER instructions. A compiler produces Machine Interface (MI) code,\nIBM i’s stable instruction-level boundary, and the system translates it into a\nnative form. The generated native code contains checks that support the IBM i\nobject and tagged-pointer model.</p>\n<p>Changing those instructions can make IBM i execute behavior that was not\npresent in the MI input. Earlier\n<a href=\"https://silentsignal.github.io/BelowMI/\" rel=\"nofollow ugc noopener\">Below MI research</a> examined the wider\nconsequences on IBM i V7R4. Here I focus on the IBM i 7.5\n<a href=\"https://www.ibm.com/docs/ssw_ibm_i_74/rzamv/rzamvprotectagainstviruses.htm\" rel=\"nofollow ugc noopener\">Program Validation Value (PVV)</a>,\na 32-byte value stored with a saved program.</p>\n<p>I reconstructed the 32-byte PVV calculation and matched all 1,223 known-valid\nvalues. The reconstructed calculation derives its HMAC key entirely from saved\nprogram attributes and fixed Licensed Internal Code (LIC) constants; it\ncontains no separate secret for origin authentication. IBM i applies separate\ndigital-signature checks where required. In controlled USER-state programs—the\nordinary, non-SYSTEM execution mode—recalculating PVV and the separate save-file\nchecks allowed selected native instruction changes to survive restore and\nresave. A disposable CrackMe produced the expected changed output,\ndemonstrating execution.</p>\n<p>USERB1, an ordinary test account without special authorities, restored a\nUSERB1-owned, PVV-repaired <code>MEMDUMP</code> program through IBM’s Restore Object List\n(<code>QSRRSTO</code>) API, and a resave preserved its modified native instructions. Its\nexecutable payload matched byte-for-byte the payload used in a controlled\nruntime test. In that test, <code>MEMDUMP</code> ran as USERB1 and read from a known-address\nUSER-domain buffer in a cooperating job running under QSECOFR, IBM i’s\nsecurity-officer profile. Other controls showed IBM i rejecting unsigned SYSTEM\nand INHERIT program-state variants and enforcing the SYSTEM-domain access\nboundary.</p>\n<p>My <a href=\"https://blog.silentsignal.eu/2026/10/06/512-bytes-at-a-time-reconstructing-IBM-i-save-file-checksums/\" rel=\"nofollow ugc noopener\">previous article</a>\ncovered the outer save file (SAVF) container: its per-record checksums and\nglobal checksum. During restore, IBM i also calculates PVV and compares it\nwith four values stored in the saved program.</p>\n<p>The USER-state controls ran under the test system’s existing\n<a href=\"https://www.ibm.com/docs/en/i/7.5.0?topic=40-validation-programs-being-restored\" rel=\"nofollow ugc noopener\">restore-policy system values</a>\n(<code>QVFYOBJRST=3</code>, <code>QFRCCVNRST=1</code>, and <code>QALWOBJRST=*ALL</code>) at\n<a href=\"https://www.ibm.com/docs/en/i/7.5.0?topic=reference-using-system-security-qsecurity-system-value\" rel=\"nofollow ugc noopener\">QSECURITY 40</a>,\nwhich enforces resource security and integrity protection.</p>\n<h2 id=\"program-validation-and-research-approach\">Program validation and research approach</h2>\n<p>SAVF record and global checks establish container consistency; PVV establishes\nconsistency with selected serialized program data. LIC copies the 32-byte\ndescriptor unchanged into the HMAC key object. Every descriptor byte\ncomes from saved program attributes or fixed LIC constants, and the recovered\npath contributes no additional secret. A party with the serialized program and\nthe reconstructed algorithm can therefore derive the key and recompute PVV; a\nmatch establishes consistency, not trusted origin. Restore authorization and\nsystem policy still govern the operation, while digital signatures authenticate\norigin where required.</p>\n<p>A program has separate\n<a href=\"https://www.ibm.com/docs/en/i/7.5.0?topic=40-preventing-use-unsupported-interfaces\" rel=\"nofollow ugc noopener\">state and domain attributes</a>.\nIts execution state is USER, SYSTEM, or INHERIT; INHERIT uses the caller’s\nstate. The program object itself has a USER or SYSTEM domain, and that saved\nattribute contributes separately to the PVV descriptor. Other objects accessed\nby the executing code also have domains. The USER domain is a storage-domain\nclassification, not a user identity or ownership boundary. At QSECURITY 40,\nUSER-state code cannot directly access SYSTEM-domain objects.</p>\n<h3 id=\"the-algorithm-at-a-glance\">The algorithm at a glance</h3>\n<pre><code>PVV = HMAC-SHA-256(descriptor, canonical_message)</code></pre>\n<p>PVV is calculated in four steps for the supported program format:</p>\n<ol><li><p>Walk the saved program graph, select the protected byte ranges, normalize</p><p> saved pointers, and put the ranges into canonical-message order.</p></li><li><p>Build a 32-byte descriptor from program attributes and constants chosen</p><p> by the recovered state, domain, version, release, and mode selectors.</p></li><li><p>Use the descriptor as the HMAC key and the canonical message as the input to</p><p> HMAC-SHA-256.</p></li><li><p>Split the result into four 64-bit values and compare them with the stored</p><p> values.</p></li></ol>\n<h3 id=\"leif-svalgaard-s-earlier-pvv-work-was-a-clue\">Leif Svalgaard’s earlier PVV work was a clue</h3>\n<p>Leif Svalgaard described the earlier mechanism in Chapter 15, “Program\nValidation Value,” of <a href=\"https://web.archive.org/web/20220523023735/https://svalgaard.leif.org/as400/mlp0tc.htm\" rel=\"nofollow ugc noopener\">AS/400 Machine Level Programming</a>.\nHis <a href=\"https://web.archive.org/web/20220523023735/https://svalgaard.leif.org/as400/programs/index.htm\" rel=\"nofollow ugc noopener\">public program index</a>\nalso lists <code>MIPGMVV</code>, which calculates an eight-byte value from program\nattributes. I reproduced his published example. Its four selector constants do\nnot match the current LIC descriptor constants in either byte order, but both\ndesigns select values according to state and domain. That similarity pointed\nme toward the current 32-byte validation route.</p>\n<h2 id=\"finding-the-validator\">Finding the validator</h2>\n<p>I started with <code>CHKOBJITG</code>, the IBM i command that checks object integrity.</p>\n<p>For a program, <code>CHKOBJITG</code> reaches the IBM-supplied <code>QSYS/QSYCHKIT</code> program.\nIts native procedure <code>QSYINTEGRI::checkPgmMod</code> contains this sequence, copied\nfrom the retained IBM Display/Alter/Dump (DAD) output:</p>\n<pre><code>2B463690C5 0052B4  0000D4  62E30000  ORI 3,23,0\n2B463690C5 0052B8  0000D8  39400103  ADDI 10,0,259\n2B463690C5 0052BC  0000DC  44000141  SCV 10</code></pre>\n<p><code>ADDI</code> loads selector 259 into <code>r10</code>; the following <code>SCV 10</code>, Supervisor Call\nVectored, enters dispatcher vector 10. The <code>10</code> in the mnemonic identifies the\nvector, while the value in <code>r10</code> selects the service. That combination led to\nthis observed call path:</p>\n<pre><code>QSYCHKIT/QSYINTEGRI::checkPgmMod\n  -&gt; #cfmir\n  -&gt; #dotssob\n  -&gt; VBNTSSOB::#bntssob\n  -&gt; VBNTSSOB::vbnskew4\n  -&gt; VBNNAPE2::vbnspnt2</code></pre>\n<p>The live capture tied the path to the loaded address of my <code>CALLAES</code> test\nfixture. I matched the remaining code against the IBM i 7.5 LIC from\ninstallation media by procedure name, normalized instruction sequence, call\ntopology, constants, and tables. The live instructions and invocation frames\nidentify the observed <code>CHKOBJITG</code> route; the build-matched LIC supplies the\ncomplete procedure bodies. For both <code>VBNTSSOB</code> and <code>VBNNAPE2</code>, the installation\naddresses were <code>0x3000</code> above the captured live addresses and the normalized\nbodies agreed; that displacement is evidence for this match, not an IBM i\naddressing rule.</p>\n<h2 id=\"reconstructing-pvv\">Reconstructing PVV</h2>\n<p>My parser supports uncompressed IBM i 7.5 program (<code>*PGM</code>) and service-program\n(<code>*SRVPGM</code>) items whose record graph, section descriptors, and 40-bit segment\nidentity plus 24-bit in-segment pointer mapping follow the recovered layout. It\nrejects other layouts before calculation instead of trying models until one\nhappens to match the stored result.</p>\n<h3 id=\"the-stored-result\">The stored result</h3>\n<p><code>vbnspnt2</code> writes 32 calculated bytes, loads them as four 64-bit doublewords,\nand compares them with four values stored in different parts of the program\ngraph. Any mismatch returns false.</p>\n<p>For <code>CALLAES</code>, the item starts at SAVF logical offset <code>0x4000</code>. The item-relative\noffset must first be converted to a SAVF logical offset. That logical coordinate\ncounts only 512-byte payloads; the physical coordinate also counts each\n16-byte record trailer:</p>\n<pre><code>logical = 0x4000 + item_offset\nphysical = (logical // 512) * 528 + (logical % 512)</code></pre>\n<p>Applying both stages gives these four locations:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Part</th><th>Item offset</th><th>Logical SAVF offset</th><th>Physical SAVF offset</th><th>Stored bytes</th></tr></thead><tbody><tr><td>0</td><td><code>0x22C0</code></td><td><code>0x62C0</code></td><td><code>0x65D0</code></td><td><code>E8DC295506AFD7E6</code></td></tr><tr><td>1</td><td><code>0x4B78</code></td><td><code>0x8B78</code></td><td><code>0x8FC8</code></td><td><code>9794394254EF4224</code></td></tr><tr><td>2</td><td><code>0x21F8</code></td><td><code>0x61F8</code></td><td><code>0x64F8</code></td><td><code>8EAD0FB7B8C3AB42</code></td></tr><tr><td>3</td><td><code>0x2648</code></td><td><code>0x6648</code></td><td><code>0x6978</code></td><td><code>307B34648AE1C331</code></td></tr></tbody></table></div>\n<p>In comparison order, the stored PVV is:</p>\n<pre><code>E8DC295506AFD7E69794394254EF4224\n8EAD0FB7B8C3AB42307B34648AE1C331</code></pre>\n<h3 id=\"building-the-canonical-message\">Building the canonical message</h3>\n<p>LIC follows a graph of program headers, components, procedure records, native\nsections, counted arrays, and optional records. It adds selected byte ranges,\nnot the complete program item.</p>\n<p>Saved pointers cannot be hashed directly because their segment identities may\nchange after restore. LIC replaces them with a stable segment number and the\noffset inside that segment. For example:</p>\n<pre><code>saved pointer:       10804C6DE6001520\nsegment number:                       1\nsegment offset:                  0x1520\ncanonical value:    0000000100001520</code></pre>\n<p>LIC also changes the order of some data. Appends shorter than <code>0x400</code> bytes are\ncopied into one owned stream. Appends of <code>0x400</code> bytes or more remain separate\nentries. The final HMAC message contains the complete copied stream first,\nfollowed by the retained entries.</p>\n<p>Here, an aggregate entry is one buffer passed to the HMAC update path.</p>\n<p>If the logical append order is a short span <code>A</code>, a retained span <code>B</code>, and a\nshort span <code>C</code>, the message order is <code>A || C || B</code>.</p>\n<p>For <code>CALLAES</code>, 65 logical appends became three aggregate entries:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Entry</th><th>Length</th><th>Message offset</th></tr></thead><tbody><tr><td>copied spans</td><td><code>0x1234</code></td><td><code>0x0000</code></td></tr><tr><td>retained span 1</td><td><code>0x0610</code></td><td><code>0x1234</code></td></tr><tr><td>retained span 2</td><td><code>0x0870</code></td><td><code>0x1844</code></td></tr></tbody></table></div>\n<p>The final message length was <code>0x20B4</code>, or 8,372 bytes.</p>\n<h3 id=\"building-the-descriptor\">Building the descriptor</h3>\n<p>The descriptor contains four 64-bit values:</p>\n<ol><li>one value formed by joining two four-byte program header fields;</li><li>a fixed constant selected by state, domain, and version class;</li><li>a constant selected by the target release;</li><li>a constant selected by the recovered mode.</li></ol>\n<p>“Version class” and “mode” are names for reconstructed selector inputs. I do\nnot present them as documented SAVF field names.</p>\n<p>Within the retained fixtures, the recovered <code>version_kind=0x0028</code> input selects\none version class by contributing 0 to the table index; other observed values,\nincluding <code>CALLAES</code>’s <code>0x000A</code>, contribute 1. With <code>CALLAES</code>’s USER state and\ndomain, that selects <code>2E9132CE813F75B2</code>. The mode byte independently selects\nthe fourth 64-bit descriptor value: mode 1 selects <code>3809245098034DDE</code>, while\nmode 2 selects <code>3809745098034DDE</code>.</p>\n<p>Canonical program-state values are <code>0x0001</code> for USER, <code>0x0080</code> for SYSTEM, and\n<code>0x0000</code> for INHERIT. For descriptor selection, the state selector treats\n<code>0x0080</code> as SYSTEM, <code>0x0000</code> as INHERIT, and every other value as the remaining\nselector class. The domain selector tests the least significant bit of program\nbase byte <code>+0x20</code>—bit 7 in IBM’s MSB-0 numbering. In the <code>CALLAES</code> fixture the\nbyte was <code>0x80</code>; that bit is clear, so the program domain was USER. A byte of\n<code>0x81</code> selects SYSTEM program domain. This byte is separate from the 16-bit\nstate value <code>0x0080</code>.</p>\n<p>For <code>CALLAES</code>, the selected descriptor was:</p>\n<pre><code>C884EBDE4ED4E62B2E9132CE813F75B2\n83CF578390004BA13809245098034DDE</code></pre>\n<p>The calculation selects these fixed tables without consulting the stored PVV.</p>\n<h3 id=\"the-cryptographic-operation\">The cryptographic operation</h3>\n<p>The lower LIC code creates a key object, copies all 32 descriptor bytes into\nit, and feeds each aggregate entry to a message digest object. The next layer\nimplements the standard HMAC construction with a 64-byte block,\nthe <code>0x36</code> inner pad, the <code>0x5C</code> outer pad, and SHA-256.</p>\n<p>The recovered calculation maps directly to Python’s standard HMAC\nimplementation:</p>\n<pre><code>import hashlib\nimport hmac\n\ncalculated = hmac.new(\n    descriptor,\n    canonical_message,\n    hashlib.sha256,\n).digest()</code></pre>\n<p>For <code>CALLAES</code>, it returns the exact 32 stored bytes shown above.</p>\n<h2 id=\"offline-validation\">Offline validation</h2>\n<p>I applied the recovered model to IBM-supplied save-file items and disposable\nprograms and service programs. The corpus measures agreement and structural\ncoverage over supported rows, not blind holdout or live restore and execution\ntests. The final totals were:</p>\n<pre><code>known valid exact matches:        1,223\ndeliberate mutation fixtures:        16\nsuccessfully parsed rows:         1,239\nunsupported program items:           17\ntotal attempted items:            1,256\ndistinct structure profiles:      1,003\nunexplained mismatches:                0</code></pre>\n<p>A structure profile fingerprints object type, release and version selectors,\nmode, record shapes, and canonical-chunk construction without including the\nprotected byte values. The 1,003 profiles occur among the 1,223 known-valid\nrows; repeated saves or equivalent layouts can share one. The 16 deliberate\nmutation fixtures remained invalid. The parser rejected another 17 items\nbefore calculation: seven had malformed section descriptors or descriptors\nthat did not expose the validated 40-bit segment and 24-bit offset mapping, and\nten contained pointers that could not be mapped unambiguously to a recovered\nsegment. These are unsupported structures, not unexplained PVV mismatches.</p>\n<p>I produced these results with the local <code>pvv-ibmi</code> tool bundle. <code>pvv_demo.py</code>\nis its command-line entry point, <code>savf_checksum_demo.py</code> implements the SAVF\nchecks, and <code>scripts/reconstruct_v7r5_pvv.py</code> parses the program graph and\ncalculates PVV. I plan to publish the bundle and its usage notes in the\n<a href=\"https://github.com/silentsignal/pvv-ibmi/\" rel=\"nofollow ugc noopener\">Silent Signal IBM i PVV repository</a>.</p>\n<p>The <code>--table</code> argument specifies <code>sandbox.ser</code>, which contains the lookup table\nused for the SAVF global checksum. I described its extraction in my\n<a href=\"https://blog.silentsignal.eu/2026/10/06/512-bytes-at-a-time-reconstructing-IBM-i-save-file-checksums/\" rel=\"nofollow ugc noopener\">previous SAVF checksum article</a>.</p>\n<p>The tool’s two main commands are:</p>\n<pre><code>python3 pvv_demo.py --table sandbox.ser check input.FILE\npython3 pvv_demo.py --table sandbox.ser fix modified.FILE repaired.FILE</code></pre>\n<p><code>check</code> verifies the SAVF checks and PVV. <code>fix</code> calculates PVV, writes the\nfour stored values, repairs the separate SAVF checks, and verifies the output\nin a new file while preserving the intended native change.</p>\n<h2 id=\"live-restore-controls\">Live restore controls</h2>\n<p>The offline matches establish the calculation. The following controls test how\nrestore consumes the stored value, whether edited native code survives, and\nwhether IBM i executes the changed control flow.</p>\n<h3 id=\"a-stale-stored-value\">A stale stored value</h3>\n<p>In the <code>P7QPM831</code> test program, I changed one stored PVV byte but left the\nprotected program data unchanged. I repaired only the SAVF checks. <code>CPC3703</code>\ndenotes normal restore completion in the baseline and corrected controls.</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Input</th><th>PVV</th><th>SAVF checks</th><th>Result</th></tr></thead><tbody><tr><td>baseline</td><td>valid</td><td>valid</td><td><code>CPC3703</code>, process status 0</td></tr><tr><td>one stale byte</td><td>invalid</td><td>valid</td><td><code>CPF3848</code>, <code>CPF3773</code>, process status 255</td></tr><tr><td>corrected value</td><td>valid</td><td>valid</td><td><code>CPC3703</code>, process status 0</td></tr></tbody></table></div>\n<p>The stale restore created an object, which I then saved again. The calling\nprocess returned status 255, while the substituted restore messages recorded\nthe actual object counts:</p>\n<pre><code>CPF3848: 1 security or data format changes occurred.\nCPF3773: 1 objects restored. 0 not restored.</code></pre>\n<p>The resaved object still contained the incorrect stored value. Writing the\nindependently calculated value restored normal completion. The mismatch was\ntherefore detected and changed the command outcome, but did not prevent object\ncreation in this control.</p>\n<h3 id=\"a-native-change-that-survived\">A native change that survived</h3>\n<p>The <code>RISCPVV1</code> test program measured native-code preservation without changing\nbehavior. I replaced one instruction with a different instruction that copies\nthe same register value:</p>\n<pre><code>before  60860000  ORI 6,4,0\nafter   7C862378  OR 6,4,4</code></pre>\n<p>The saved creation material—the input IBM i can use to recreate native\ncode—remained unchanged. To distinguish preserved native code from code\nrecreated from that material, I repaired PVV and the SAVF, restored the object,\nand saved it again. The executable payload was eight native records joined in\ngraph order after removing each record’s final eight-byte saved-space pointer,\nwhich is metadata rather than executable payload.</p>\n<p>All 1,120 executable bytes matched between the modified and resaved streams;\nthe original differed at the edited instruction. The 40-bit segment-identity\nprefixes within those trailing pointers changed as expected when\nIBM i materialized the object; their 24-bit in-segment offsets did not. The\nexecutable payload and repaired PVV remained unchanged.</p>\n<h3 id=\"crackme-a-branch-that-changed-behavior\">CrackMe: a branch that changed behavior</h3>\n<p><code>PVVPASS</code>, which I call CrackMe here, provided the visible control. This\ndisposable fixture compared its argument with <code>silentsignal</code>, printed\n<code>pwd is ok</code> for a match, and printed <code>wrong</code> otherwise.</p>\n<p>The retained source was:</p>\n<pre><code>#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\nint main(int argc, char **argv)\n{\n    if (argc &gt; 1 &amp;&amp; strcmp(argv[1], &quot;silentsignal&quot;) == 0)\n        puts(&quot;pwd is ok&quot;);\n    else\n        puts(&quot;wrong&quot;);\n    return 0;\n}</code></pre>\n<p>I compiled it as a native Integrated Language Environment (ILE) C program with\n<code>DBGVIEW(*NONE)</code>, <code>OPTIMIZE(40)</code>, and <code>ACTGRP(*CALLER)</code>, then saved it without\ncompression.</p>\n<p>The relevant saved instructions are below in reconstructed DAD style. Register\n5 holds the current input byte. Register 0 holds the current expected byte.</p>\n<pre><code>1E75B1F2E2001F78  2C250000  CMPI   0,1,5,0\n1E75B1F2E2001F7C  397E0010  ADDI   11,30,16\n1E75B1F2E2001F80  387FFFC0  ADDI   3,31,-64\n1E75B1F2E2001F84  63CC0000  ORI    12,30,0\n1E75B1F2E2001F88  78CAC1C6  RLDICR 10,6,56,7\n1E75B1F2E2001F8C  7C0103E6  SETTAG\n1E75B1F2E2001F90  7CA50040  CMPL   1,1,5,0\n1E75B1F2E2001F94  40860048  BC     4,6,0X48\n1E75B1F2E2001F98  41820014  BC     12,2,0X14\n1E75B1F2E2001F9C  8CA40001  LBZU   5,0X1(4)\n1E75B1F2E2001FA0  2C250000  CMPI   0,1,5,0\n1E75B1F2E2001FA4  8C0C0001  LBZU   0,0X1(12)\n1E75B1F2E2001FA8  4BFFFFE8  B      0X3FFFFE8</code></pre>\n<p>The first <code>CMPI</code> sets <code>CR0.EQ</code> from the input byte. The instructions before\n<code>CMPL</code> do not change CR0. <code>SETTAG</code> affects the tag state, not the condition\nregisters. <code>CMPL 1,1,5,0</code> sets <code>CR1.EQ</code> from the comparison of the input and\nexpected bytes.</p>\n<p>The branch at <code>0x1E75B1F2E2001F94</code> tests <code>CR1.EQ</code> and reaches the failure block\nwhen the bytes differ. The next branch tests <code>CR0.EQ</code> and reaches success when\nthe input byte is zero. Equal nonzero bytes continue the loop.</p>\n<p>The encoded displacements make the control flow explicit:</p>\n<pre><code>0x1E75B1F2E2001F94 + 0x48 -&gt; 0x1E75B1F2E2001FDC  failure\n0x1E75B1F2E2001F98 + 0x14 -&gt; 0x1E75B1F2E2001FAC  success\n0x1E75B1F2E2001FA8 - 0x18 -&gt; 0x1E75B1F2E2001F90  next comparison</code></pre>\n<p>The saved text supports that mapping: <code>silentsignal</code> is at logical offset\n<code>0x69B0</code>, <code>pwd is ok</code> at <code>0x69C0</code>, and <code>wrong</code> at <code>0x69D0</code>. The success block\nselects the text at <code>r30+0x10</code>; the failure block selects <code>r30+0x20</code>.</p>\n<p>I replaced only the mismatch branch:</p>\n<pre><code>before  40860048  BC 4,6,0X48\nafter   60000000  ORI 0,0,0</code></pre>\n<p>The variants produced this result:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Saved variant</th><th>PVV</th><th>Instruction after resave</th><th>Output for incorrect input</th></tr></thead><tbody><tr><td>baseline</td><td>valid</td><td>original branch</td><td><code>wrong</code></td></tr><tr><td>changed branch, stale PVV</td><td>stale</td><td>original branch</td><td><code>wrong</code></td></tr><tr><td>changed branch, repaired PVV</td><td>valid</td><td>changed instruction</td><td><code>pwd is ok</code></td></tr></tbody></table></div>\n<p>The repaired program printed <code>pwd is ok</code> for both <code>nope</code> and <code>x</code>. A fresh save\nof the repaired object still contained <code>60000000</code> at the instruction site\nidentified from the object structure.</p>\n<h3 id=\"restore-access-command-and-api-controls\">Restore access: command and API controls</h3>\n<p>IBM’s documented\n<a href=\"https://www.ibm.com/docs/en/i/7.5.0?topic=ssw_ibm_i_75%2Fapis%2Fqsrrsto.html\" rel=\"nofollow ugc noopener\">Restore Object List (<code>QSRRSTO</code>) API</a>\nhas a different authority model from the Restore Object (<code>RSTOBJ</code>) command.\nIBM has documented its default public authority as <code>*USE</code> since the\n<a href=\"https://public.dhe.ibm.com/systems/power/docs/systemi/v5r4/en_US/backup.pdf\" rel=\"nofollow ugc noopener\">2006 Backup and Recovery APIs manual</a>.\nThat permits calling the API; it does not supply the user-space, save-file,\nlibrary, or target-object authorities required for a restore. Callers without\nthe <code>*SAVSYS</code> save-system special authority must satisfy those documented\nauthority requirements, as USERB1 did within its test library.</p>\n<p>For the end-to-end control, I rebuilt CrackMe from the retained source and the\nsame compiler settings. I resolved the patch location from the new SAVF. The\nrebuilt program contained the same <code>40860048</code> mismatch branch at native record\n1 offset <code>0xB4</code>. I created baseline, branch-edited/stale-PVV, and\nbranch-edited/repaired-PVV variants; all three had valid SAVF checks.</p>\n<p>With the repaired SAVF loaded into save file <code>TESTSAVF</code> in the USERB1 library\nand the target absent, <code>RSTOBJ</code> failed with <code>CPD0032</code> (not authorized to the\ncommand) and created no program. To test the API separately, I used a small,\nlocally written USERB1-owned program that called <code>QSRRSTO</code> directly and restored\n<code>PVVPASS</code> into the USERB1 library. Both the caller and a small USERB1-owned\nwrapper that recorded the job context before and after invoking the caller were\n<code>USRPRF(*USER)</code> and <code>USEADPAUT(*NO)</code>, so they neither adopted their owners’\nauthority nor used authority adopted higher in the call stack. In the same job,\nthe wrapper used IBM’s Retrieve Job Attributes command (<code>RTVJOBA</code>) to report\ncurrent user <code>USERB1</code> immediately before and after the API call.</p>\n<p>Under this authority context, the repaired variant produced the CrackMe output\nreported above. Its resave retained <code>60000000</code> at native record 1 offset\n<code>0xB4</code>, and its 1,032-byte executable payload matched the repaired input after\nthe final eight-byte saved-space pointer was removed from each native record.</p>\n<p>The stale-PVV API control restored with the original branch and printed\n<code>wrong</code> instead. This was one end-to-end test within USERB1’s authorized object\nscope: command denial, API restore, execution, and resave.</p>\n<p>I then rebuilt <code>MEMDUMP</code> entirely as USERB1, applied the native edits to its\nsaved representation, and repaired PVV and the SAVF checks. Running as USERB1,\nI called <code>QSYS/QSRRSTO</code>; it created the <code>MEMDUMP</code> program in the USERB1 library\nas a USER-state, USER-domain program owned by USERB1, with <code>USRPRF(*USER)</code> and\n<code>USEADPAUT(*NO)</code>. A fresh save retained both modified instruction sites. The\nrepaired input, the USERB1-restored resave, and the distinct program object used\nfor the memory-read test had byte-for-byte identical 1,496-byte executable\npayloads.</p>\n<h2 id=\"signature-state-and-domain-boundaries\">Signature, state, and domain boundaries</h2>\n<p>The native code controls above used USER state. I also tested the separate\nstate, domain, and signature boundaries.</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Control</th><th>Result</th></tr></thead><tbody><tr><td>USER to SYSTEM state, PVV repaired</td><td>IBM i rejected it as unsigned with <code>CPD37A0</code>, then <code>CPF3770</code> (no object restored)</td></tr><tr><td>USER to INHERIT state, PVV repaired</td><td>IBM i rejected it as unsigned with <code>CPD37A0</code>, then <code>CPF3770</code> (no object restored)</td></tr><tr><td>USER state, USER to SYSTEM domain, PVV repaired</td><td>IBM i restored it with <code>CPC3703</code>; a USER-state call failed with <code>MCH6801</code> domain violation</td></tr></tbody></table></div>\n<p>The repaired SYSTEM-state fixture passed the offline reconstructed PVV check,\nbut the live restore failed the digital signature requirement:</p>\n<pre><code>offline PVV validation         PASS\nlive trusted-signature check   FAIL</code></pre>\n<p>I also traced the complete 16-bit state field. The relevant LIC branches reduce\nto this classification before the signature service is called:</p>\n<pre><code>state 0x0001 -&gt; record flag 0\nstate 0x8000 -&gt; record flag 0\nall other 65,534 values -&gt; record flag 1</code></pre>\n<p>The flag is an input to the later signature path, not the final restore result\nby itself. Canonical SYSTEM state is <code>0x0080</code>, and INHERIT state is <code>0x0000</code>;\nboth produce flag 1. The activation resolver separately treats <code>0x0000</code> as\nINHERIT, selects SYSTEM only for <code>0x0080</code>, and sends <code>0x0001</code>, <code>0x8000</code>, and\nother noncanonical values to USER. I found no state value that both takes the\nflag 0 path and activates as SYSTEM on this route.</p>\n<p>The <code>0x8000</code> state value is not SYSTEM state. It restored and activated as\nUSER in the live control. The same hexadecimal value appears as the two-byte\ndomain contribution for SYSTEM domain, but that is another field.</p>\n<h2 id=\"security-impact\">Security impact</h2>\n<p>Under the tested conditions, externally modified USER-state native code\nbypassed a compiler-generated pointer-validation sequence and performed a\nmemory access that the original compiled code could not. CrackMe independently\nestablished execution of modified native bytes; the controlled <code>MEMDUMP</code>\nruntime test established this consequence.\nThe compiler-generated path used <code>LQ</code> to load the 128-bit pointer and record\nits tag status, <code>TXER</code> to check that status, and <code>_SETSPPFP</code> (Set Space Pointer\nfrom Pointer) before the memory access. At native section offset <code>+0x220C</code>, I\nreplaced the first two instructions with a direct native load and branch:</p>\n<pre><code>; original\n2f3708714600220c:  e2dfff9b  LQ         22,0XFF90(31),11\n2f37087146002210:  7c0004c8  TXER       0,0,41\n; replacement\n2f3708714600220c:  eb7fff98  LD         27,0XFF98(31)\n2f37087146002210:  48000028  B          0X28\n; later target access\n2f370871460022b8:  889b0000  LBZ        4,0X0(27)</code></pre>\n<p>The source had copied the supplied 64-bit address into this <code>r31</code>-relative\nslot; the <code>LD</code> loads it into <code>r27</code>, and the branch continues at <code>+0x2238</code>. The\nlater <code>LBZ</code> at <code>+0x22B8</code> performs the byte read through <code>r27</code>. With the same\nsupplied address, the unmodified <code>MEMDUMP</code> failed with\n<code>MCH3601</code> (pointer not set). The modified code bypassed the generated validation\nsequence and, when invoked as USERB1, returned the exact expected 32 bytes from\na known-address USER-domain buffer belonging to a cooperating QSECOFR job. The\ntarget address was supplied by the cooperating QSECOFR job; obtaining such an\naddress independently is a separate prerequisite.</p>\n<p>For the supported saved-program format, the derivable HMAC key makes PVV a\nrecomputable consistency check. With an editable SAVF and an authorized restore\npath, recalculating PVV and the SAVF checks preserved the tested USER-state\nnative changes. Separate controls enforced trusted signatures for the tested\nSYSTEM and INHERIT variants and blocked USER-state access to SYSTEM-domain\nstorage.</p>\n<h2 id=\"conclusion\">Conclusion</h2>\n<p>PVV was the missing piece between editing saved native POWER instructions and\npreserving them through IBM i restore so that the modified code could execute.\nReconstructing it turned that obstacle into a repeatable research workflow:\nCrackMe demonstrated changed native control flow, while <code>MEMDUMP</code> showed its\npractical consequence in a controlled, known-address USER-domain read. The PVV\nreconstruction is not by itself a vulnerability or a signature bypass; the\n<code>pvv-ibmi</code> release accompanying this article lets other researchers reproduce\nthe calculation and use the same workflow, while restore authorization,\ntrusted signatures, and domain enforcement remain separate boundaries.</p>","headings":[{"level":1,"text":"Beyond the compiler: Making IBM i run modified native code - Program Validation Value","id":"beyond-the-compiler-making-ibm-i-run-modified-native-code-progra"},{"level":2,"text":"Why this matters","id":"why-this-matters"},{"level":2,"text":"Program validation and research approach","id":"program-validation-and-research-approach"},{"level":3,"text":"The algorithm at a glance","id":"the-algorithm-at-a-glance"},{"level":3,"text":"Leif Svalgaard’s earlier PVV work was a clue","id":"leif-svalgaard-s-earlier-pvv-work-was-a-clue"},{"level":2,"text":"Finding the validator","id":"finding-the-validator"},{"level":2,"text":"Reconstructing PVV","id":"reconstructing-pvv"},{"level":3,"text":"The stored result","id":"the-stored-result"},{"level":3,"text":"Building the canonical message","id":"building-the-canonical-message"},{"level":3,"text":"Building the descriptor","id":"building-the-descriptor"},{"level":3,"text":"The cryptographic operation","id":"the-cryptographic-operation"},{"level":2,"text":"Offline validation","id":"offline-validation"},{"level":2,"text":"Live restore controls","id":"live-restore-controls"},{"level":3,"text":"A stale stored value","id":"a-stale-stored-value"},{"level":3,"text":"A native change that survived","id":"a-native-change-that-survived"},{"level":3,"text":"CrackMe: a branch that changed behavior","id":"crackme-a-branch-that-changed-behavior"},{"level":3,"text":"Restore access: command and API controls","id":"restore-access-command-and-api-controls"},{"level":2,"text":"Signature, state, and domain boundaries","id":"signature-state-and-domain-boundaries"},{"level":2,"text":"Security impact","id":"security-impact"},{"level":2,"text":"Conclusion","id":"conclusion"}]}}