Skip to content

fix(libSceLibreSsl3): parse ASN1_get_object with a negative bound as the console does - #27500

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
xXPBSXx:fix-libressl3-asn1-negative-maximum
Nov 27, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
xXPBSXx:fix-libressl3-asn1-negative-maximum

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What

A PS5 (firmware 11.60, payload process; a title process may differ) accepted a negative bound in ASN1_get_object: with the bytes 30 03 02 01 05, the bounds -1 and INT64_MIN each returned 0x20 (constructed), advanced the pointer by 2 and changed the tag, the class and the length output (cases 3.5 and 3.6, lines 37 and 38 of the raw output in the first comment); the bound 0 with the same bytes returned 0x80 and left the pointer where it was (case 3.4, line 36). The probe printed only whether the three outputs changed, not their values, and ran once. ASN1_get_object_nid_postfix here throws std::invalid_argument for a negative bound (core/libs/prx/libSceLibreSsl3/src/IntegerDecoder.cpp:285 on the base 37749b6cd567), and a test pins that throw for -1 (core/libs/prx/libSceLibreSsl3/tests/ObjectHeader.cpp:168).

The fix commit (f91caa1bb6f, IntegerDecoder.cpp, 4 lines added and 2 removed) takes maximum < 0 out of the condition that throws and, for a negative bound, gives the guest input a size up to the end of the address space (UINTPTR_MAX minus the start address), because GuestInput throws when the start address plus the size would wrap (IntegerDecoder.cpp:133 to :136 on the base); the size for a bound of 0 or more is unchanged, and a null input pointer with a bound other than 0 still throws (IntegerDecoder.cpp:288), also for a negative bound, which was not measured. The test commit (d698c8459ce, ObjectHeader.cpp, 12 lines added and 3 removed) drops the case that expected a throw for -1 from the loop over the faulting arguments, which now ends at 6 cases, and adds a block that calls the function with -1 and with INT64_MIN on 30 03 02 01 05 and expects the return value 0x20, the pointer 2 bytes on and the three outputs different from their sentinels 123, 456 and 789, with no tag, class or length value because none was measured. The debt commit (ddf80dd2f3e, 1 line added and 1 removed) changes the entry ASN1_get_object in docs/dev/debt/changes/docs-libressl3-version-asn1-measured.md: it now says that this accepts a negative bound too, for any negative bound, with only -1 and INT64_MIN measured; two phrases without a measurement were shortened to keep the entry from growing, so it is 1156 characters with its list marker, down from 1162.

Not measured and not claimed: negative bounds other than -1 and INT64_MIN (they follow the same rule here, as an extension), the values of the tag, the class and the length for a negative bound, a null input pointer with a negative bound, and a title process.

Tested

Windows 10 Pro (10.0.19045), MinGW-W64 GCC 15.2.0 (WinLibs), CMake with Ninja, Release, -DBUILD_TESTING=ON, one machine, both arms on main 37749b6. Red: with the test commit alone (d698c84), ninja -j4 guest_libressl3_object_header_tests succeeded and ctest -R guest_libressl3_object_header -V printed Exit code 0xc0000409***Exception with what(): ASN1_get_object: invalid buffer or output (0 of 1 tests passed). Green: with the fix and the debt commit (ddf80dd, the head of this branch) the same test passed (Passed 0.48 sec, 100% passed, 0 of 1 failed). All 105 guest_libressl3_* test targets were built at the head and ctest -R libressl3 -j2 --timeout 60 reported 100% passed, 0 tests failed out of 106. Against a fresh main 81ff76a (fetched on 2026-11-26): tools/debt_fold.py --check exits with 0; tools/check_conventions.py --base upstream/main reports 0 errors and 1 warning (debt-length, 1156 characters, on the entry this change edits; the warning was already there at 1162); git merge-tree of the head with that main is clean. The builds ran on main 37749b6, not on 81ff76a. Not tested: Linux, macOS, the CI runner, a run of this code on a PS5, a title.

Overlap: counted on 2026-11-26 from the 2384 open pull requests (file lists from the GitHub API, the 16 with 100 or more files read in full through the files API and, for those and for the pull requests with an old base, the real diff against the merge base; the patches of the 1393 pull requests that change a file under docs/dev/debt/ or a libSceLibreSsl3 file, or have LibreSSL, SSL3, ASN.1 or OpenSSL in the title or branch name, were searched for ASN1_get_object, IntegerDecoder, ObjectHeader and asn1-measured, from 13:37 to 14:01 UTC). No open pull request changes core/libs/prx/libSceLibreSsl3/src/IntegerDecoder.cpp, core/libs/prx/libSceLibreSsl3/tests/ObjectHeader.cpp or the fragment docs/dev/debt/changes/docs-libressl3-version-asn1-measured.md, or names ASN1_get_object in its diff, and no commit on main since 37749b6cd567 changed those files or docs/dev/debt/libSceLibreSsl3.md. #6743 lists the two source files only because of its old base; its own diff against the merge base does not change those files. #23573 (feat(libSceLibreSsl3): decode X509 certificates from BIO) and #25314 (fix(libSceLibreSsl3): accept BER lengths in X509_STORE_load_locations certificates) change other libSceLibreSsl3 files and fragments; the same holds for the other BER and decoding pull requests of the library that were checked (#25327, #25351, #25372, #27446, #27421, #27418 and #24677). Five open pull requests change the debt file docs/dev/debt/libSceLibreSsl3.md itself, for other entries: #17626 and #17622 and #17621 (ECDSA_do_sign and the EC_POINT functions), #15163 (cipher context flags) and #12315 (numeric object identifier text parsing). The merges of this head with these pull requests and with the pull requests with 100 or more files or an old base that were checked as well were made with git merge-tree from 14:02 to 14:27 UTC against main at 4a51193: #25314, #25327, #25351, #25372, #27446, #27421, #27418, #24677, #15163, #25940, #25704, #19486 and #6743 are clean; #23573, #17626, #17622, #17621, #12315 and the large old-base pull requests (#24917, #24910, #24322, #22647, #20315, #14443, #14340, #13929, #13928, #10193, #9508 and #7642) already conflict with main alone, in the same number of files, so none of them conflicts because of this change. A merge of this head into main at af6a58c was checked the same way at 14:29 UTC and is clean. The count was repeated from 14:46 to 14:50 UTC for what changed since 13:30 UTC (2408 open pull requests; the file lists of all of them were read again and the patches of the 149 updated since 13:30 UTC were searched again for the same names): no pull request opened or changed since then touches IntegerDecoder.cpp, ObjectHeader.cpp, the fragment or ASN1_get_object, and the heads of #17626, #17622, #17621 and #15163 (the pull requests that change docs/dev/debt/libSceLibreSsl3.md) have not moved since before the first count. On main at a4ed870 no commit since 37749b6cd567 changed those files or docs/dev/debt/libSceLibreSsl3.md, and the merge of this head into that main was checked at 14:51 UTC and is clean. This pull request does not depend on any of them (Depends on: none).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (no graphics change)
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • ASN.1 object decoding now accepts negative input bounds instead of rejecting them. For these bounds, decoding can proceed across the available addressable range, while invalid pointers continue to be rejected.
  • Documentation
    • Updated the ASN.1 decoding reference to describe support for negative bounds and clarify which values have been measured.

xXPBSXx and others added 3 commits November 26, 2026 14:03
A PS5 (firmware 11.60, payload process; a title process may differ) accepted a
negative bound for the header 30 03 02 01 05: -1 and INT64_MIN returned 0x20
and advanced the pointer by 2. Only these two values were measured.

Drop the fault case that expected -1 to throw and add the two measured values:
the return value, the cursor advance and that the three outputs were written.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…the console does

A PS5 (firmware 11.60, payload process; a title process may differ) accepted a
negative bound for the header 30 03 02 01 05: -1 and INT64_MIN returned 0x20
and advanced the pointer by 2, where ASN1_get_object threw. Only these two
values were measured.

A negative bound no longer throws: the header is read as if the input ran to the
end of the address space, so the bound cannot wrap it. Every negative value
takes this path here; the other negative values were not measured. A null input
pointer with a nonzero bound, a negative one included, still throws as before
(that combination was not measured).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e console

Amend the existing docs-libressl3-version-asn1-measured fragment (no second
fragment): the console accepted a negative bound for 30 03 02 01 05, and so does
this now, for any negative bound; only -1 and INT64_MIN were measured. To make
room the sentence about the null tag pointer drops a clause that repeated
"throws without mutation", and two source-reference phrases are shortened
("length arguments" to "lengths", the list of agreeing cases). The entry is
1156 characters with "- " (1162 before), still above 1000.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (PROBE_BUILD is the first 12 hex digits of the SHA-256 of the original source) and the complete raw output of the run that this pull request cites by line number (line 1 is the PROBE line). The utc in the PROBE line is the console's own clock, about 1 h 42 min ahead of real UTC; the run started at 07:36 UTC on 2026-11-18. The probe loads libSceLibreSsl3.sprx and libSceLibreSsl.sprx with dlopen, takes the functions with dlsym, and calls ASN1_get_object on stack buffers with a 2-second self limit per error case; the length, tag and class outputs are pre-filled with -1 and the probe prints whether they changed. In each CASE line the columns are the case, the call, the return value, the errno and the details. The source is posted verbatim except that an internal label after the first /* was removed; the code is unchanged, and the build ID is the hash of the original file.

libSceLibreSsl3 version text and ASN1_get_object: probe.c (build d8bb31967822)
/* libSceLibreSsl3 OpenSSL_version and ASN1_get_object, heap-free calls only, payload process, firmware 11.60 (debt libSceLibreSsl3.md entries:
   OpenSSL_version: other firmware revisions are unverified, selectors 0 through 5 follow the public firmware 13.40 measurements in discussion #8981, unknown selectors follow LibreSSL
   4.0.0 and return "not available", no independent console test was run; ASN1_get_object has no console ABI or behavior verification, its 64-bit length arguments and BER header rules follow
   LibreSSL 4.0.0, errors use the existing parent-library queue, sharing that queue with console LibreSSL3 is unverified, negative buffer bounds and faulting null arguments throw without
   mutation). Prototypes from the repo: const char* OpenSSL_version(int type), int ASN1_get_object(const unsigned char** pp, long* plength, int* ptag, int* pclass, long omax); return value bits 0x80
   (constructed is 0x20 in the LibreSSL source, V_ASN1_CONSTRUCTED) and 0x80 (error) as in LibreSSL. The modules are opened with dlopen("libSceLibreSsl3.sprx") and dlopen("libSceLibreSsl.sprx") (as the earlier LibreSSL probes), and
   every name is looked up with dlsym in both (a missing name is the result for its cases): OpenSSL_version, ASN1_get_object, ERR_peek_error, ERR_get_error, ERR_clear_error, SSLeay_version, SSLeay,
   OPENSSL_version_major, OpenSSL_version_num. Only the two functions of the entry are called, plus the error queue functions after the error cases; nothing that needs the heap (the earlier probe found
   CRYPTO_malloc(32) returning NULL). OpenSSL_version is called for the selectors 0 to 5, 6, 7, 8, 100, -1, 0x7fffffff and INT_MIN (is the pointer not NULL, the string up to 128 characters printed ASCII-safe, whether
   two calls give the same pointer). ASN1_get_object success cases on stack buffers, with omax large: 30 03 02 01 05, 02 01 05, 04 00, 80 01 00, A0 03 02 01 05, 30 81 80 plus data, 30 82 01 00, 30 83 01 00 00,
   30 84 7F FF FF FF, 30 88 00 00 00 00 00 00 01 00, 1F 81 00, 1F 1F, 5F 7F, 1F FF FF FF FF 7F: the return value as hex, tag, class, length, and how many bytes the pointer advanced; BER indefinite length: 30 80 and 02 80;
   then the error cases, each a single call with a 2 second self limit (a hang or a fault ends the cases with the result HEAP and the probe): omax smaller than the content (30 05 02 01 05 with omax 3), a truncated header (30),
   (30 82 01), omax 0, omax -1 and omax INT64_MIN, 30 88 FF FF FF FF FF FF FF FF, 30 89 ..., 30 88 80 00 00 00 00 00 00 00 (return value, whether the pointer and the three outputs, pre-set to -1, changed); then
   ERR_peek_error and ERR_get_error from both modules (the value as hex, whether equal) and ERR_clear_error at the end; the NULL cases (ptag NULL, pclass NULL, plength NULL, pp NULL, *pp NULL) as single guarded calls
   only after everything else. A fault is caught by a guard (one hit per case, more than eight end the probe with _exit(125)); a fault is a result. Nothing is written to a file, nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h>   /* only for kernel_get_fw_version() */

#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
   itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif

static volatile int g_handle = -1;
static int (*volatile g_setmargins)(int, int, int) = 0; /* unused here */
static void reset_rate(void) {
  if (g_setmargins && g_handle >= 0) g_setmargins(g_handle, 0, 0);
}

static void probe_alarm(int sig) {
  static const char msg[] = "TIMEOUT\tprobe self limit\n";
  (void)sig;
  (void)!write(1, msg, sizeof msg - 1);
  reset_rate();
  _exit(124);
}

/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
   thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
   as a second safeguard. */
static void* probe_watchdog(void* arg) {
  static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
  unsigned left = PROBE_MAX_S;
  (void)arg;
  while (left) left = sleep(left);
  (void)!write(1, msg, sizeof msg - 1);
  reset_rate();
  _exit(124);
  return 0;
}

static void probe_watchdog_start(void) {
  pthread_t t;
  if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  probe_watchdog_start();
  struct tm tmv;
  gmtime_r(&now, &tmv);
  strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
  printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
         getpid(), utc);
  fflush(stdout);
}

static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
  printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
  fflush(stdout);
  cases++;
}

static void probe_end(void) {
  printf("END\t%d\n", cases);
  fflush(stdout);
}



#include <setjmp.h>
#include <limits.h>

typedef const char* (*fn_ver)(int);
typedef int (*fn_get)(const unsigned char**, long*, int*, int*, long);
typedef unsigned long (*fn_err)(void);
typedef void (*fn_clear)(void);
typedef unsigned long (*fn_num)(void);

static sigjmp_buf guard_env;
static volatile int guard_sig = 0, guard_active = 0, guard_hits = 0;
static void guard_handler(int s) {
  static const char msg[] = "FAULT\tguard\n";
  guard_sig = s;
  if (!guard_active || ++guard_hits > 8) { (void)!write(1, msg, sizeof msg - 1); _exit(125); }
  guard_active = 0;
  siglongjmp(guard_env, 1);
}

static fn_get g_get;

static void ascii(const char* s, char* out, size_t cap) {
  size_t n = 0;
  for (size_t i = 0; s && s[i] && i < 128 && n + 5 < cap; ++i) {
    unsigned char c = (unsigned char)s[i];
    if (c >= 0x20 && c < 0x7F && c != '"' && c != '\\') out[n++] = (char)c;
    else n += (size_t)snprintf(out + n, cap - n, "\\x%02x", c);
  }
  out[n] = 0;
}

static void succ(const char* id, const unsigned char* buf, unsigned n, long omax) {
  unsigned char b[64];
  memset(b, 0, sizeof b);
  memcpy(b, buf, n);
  const unsigned char* p = b;
  long len = -1;
  int tag = -1, cls = -1;
  int r = g_get(&p, &len, &tag, &cls, omax);
  char extra[200], label[60], hx[40] = "";
  for (unsigned i = 0; i < n && i < 10; ++i) { char t[4]; snprintf(t, sizeof t, "%02x", buf[i]); strncat(hx, t, sizeof hx - strlen(hx) - 1); }
  snprintf(label, sizeof label, "ASN1_get_object(%s, omax %ld)", hx, omax);
  snprintf(extra, sizeof extra, "ret=0x%x tag=%d class=0x%x length=%ld pointer_advanced=%ld", (unsigned)r, tag, (unsigned)cls, len, (long)(p - b));
  probe_case(id, label, r, 0, extra);
}

static void errcase(const char* id, const char* label, const unsigned char* buf, unsigned n, long omax) {
  unsigned char b[64];
  memset(b, 0, sizeof b);
  memcpy(b, buf, n);
  const unsigned char* p = b;
  long len = -1;
  int tag = -1, cls = -1;
  guard_sig = 0;
  int r = -1;
  alarm(2);
  if (sigsetjmp(guard_env, 1) == 0) {
    guard_active = 1;
    r = g_get(&p, &len, &tag, &cls, omax);
    guard_active = 0;
  }
  alarm(PROBE_MAX_S);
  char extra[220];
  snprintf(extra, sizeof extra, "ret=0x%x pointer_advanced=%ld tag_changed=%d class_changed=%d length_changed=%d fault_signal=%d", (unsigned)r, (long)(p - b), tag != -1, cls != -1, len != -1, (int)guard_sig);
  probe_case(id, label, r, 0, extra);
}

int main(void) {
  struct sigaction sa;
  memset(&sa, 0, sizeof sa);
  sa.sa_handler = guard_handler;
  sigaction(SIGSEGV, &sa, 0);
  sigaction(SIGBUS, &sa, 0);
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();
  char extra[420], id[24], label[110];

  errno = 0;
  void* L3 = dlopen("libSceLibreSsl3.sprx", RTLD_LAZY);
  void* L = dlopen("libSceLibreSsl.sprx", RTLD_LAZY);
  snprintf(extra, sizeof extra, "libSceLibreSsl3=%d libSceLibreSsl=%d", L3 != 0, L != 0);
  probe_case("0", "dlopen of the two modules", L3 || L ? 0 : -1, errno, extra);
  if (!L3 && !L) { probe_end(); return 0; }
  fn_ver ver3 = L3 ? (fn_ver)dlsym(L3, "OpenSSL_version") : 0, ver1 = L ? (fn_ver)dlsym(L, "OpenSSL_version") : 0;
  fn_get get3 = L3 ? (fn_get)dlsym(L3, "ASN1_get_object") : 0, get1 = L ? (fn_get)dlsym(L, "ASN1_get_object") : 0;
  fn_err peek3 = L3 ? (fn_err)dlsym(L3, "ERR_peek_error") : 0, peek1 = L ? (fn_err)dlsym(L, "ERR_peek_error") : 0;
  fn_err getE3 = L3 ? (fn_err)dlsym(L3, "ERR_get_error") : 0, getE1 = L ? (fn_err)dlsym(L, "ERR_get_error") : 0;
  fn_clear clr3 = L3 ? (fn_clear)dlsym(L3, "ERR_clear_error") : 0, clr1 = L ? (fn_clear)dlsym(L, "ERR_clear_error") : 0;
  void* sslv3 = L3 ? dlsym(L3, "SSLeay_version") : 0;
  void* sslv1 = L ? dlsym(L, "SSLeay_version") : 0;
  void* ssl3 = L3 ? dlsym(L3, "SSLeay") : 0;
  void* maj3 = L3 ? dlsym(L3, "OPENSSL_version_major") : 0;
  void* num3 = L3 ? dlsym(L3, "OpenSSL_version_num") : 0;
  snprintf(extra, sizeof extra, "Ssl3: version=%d get_object=%d peek=%d get_error=%d clear=%d SSLeay_version=%d SSLeay=%d version_major=%d version_num=%d | Ssl: version=%d get_object=%d peek=%d get_error=%d clear=%d SSLeay_version=%d",
           ver3 != 0, get3 != 0, peek3 != 0, getE3 != 0, clr3 != 0, sslv3 != 0, ssl3 != 0, maj3 != 0, num3 != 0, ver1 != 0, get1 != 0, peek1 != 0, getE1 != 0, clr1 != 0, sslv1 != 0);
  probe_case("0b", "dlsym of the names in both modules", 0, 0, extra);

  fn_ver ver = ver3 ? ver3 : ver1;
  g_get = get3 ? get3 : get1;
  fn_err peek = peek3 ? peek3 : peek1;
  (void)peek;

  /* b) OpenSSL_version */
  if (ver) {
    int sel[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 100, -1, 0x7fffffff};
    for (int i = 0; i < 13; ++i) {
      int s = i < 12 ? sel[i] : INT_MIN;
      const char* p1 = ver(s);
      const char* p2 = ver(s);
      char txt[200];
      ascii(p1, txt, sizeof txt);
      snprintf(id, sizeof id, "1.%d", i + 1);
      snprintf(label, sizeof label, "OpenSSL_version(%d)", s);
      snprintf(extra, sizeof extra, "not_null=%d same_pointer_twice=%d text=\"%s\"", p1 != 0, p1 == p2, txt);
      probe_case(id, label, 0, 0, extra);
    }
  }

  if (!g_get) { probe_case("2", "ASN1_get_object", 0, 0, "export missing: cases skipped"); probe_end(); return 0; }

  /* d) success cases */
  static const unsigned char c1[] = {0x30, 0x03, 0x02, 0x01, 0x05}, c2[] = {0x02, 0x01, 0x05}, c3[] = {0x04, 0x00}, c4[] = {0x80, 0x01, 0x00}, c5[] = {0xA0, 0x03, 0x02, 0x01, 0x05},
                                     c6[] = {0x30, 0x81, 0x80}, c7[] = {0x30, 0x82, 0x01, 0x00}, c8[] = {0x30, 0x83, 0x01, 0x00, 0x00}, c9[] = {0x30, 0x84, 0x7F, 0xFF, 0xFF, 0xFF},
                                     c10[] = {0x30, 0x88, 0, 0, 0, 0, 0, 0, 0x01, 0x00}, c11[] = {0x1F, 0x81, 0x00}, c12[] = {0x1F, 0x1F}, c13[] = {0x5F, 0x7F}, c14[] = {0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F},
                                     c15[] = {0x30, 0x80}, c16[] = {0x02, 0x80};
  succ("2.1", c1, sizeof c1, 100);
  succ("2.2", c2, sizeof c2, 100);
  succ("2.3", c3, sizeof c3, 100);
  succ("2.4", c4, sizeof c4, 100);
  succ("2.5", c5, sizeof c5, 100);
  succ("2.6", c6, sizeof c6, 100000);
  succ("2.7", c7, sizeof c7, 100000);
  succ("2.8", c8, sizeof c8, 100000);
  succ("2.9", c9, sizeof c9, 0x7FFFFFFF);
  succ("2.10", c10, sizeof c10, 100000);
  succ("2.11", c11, sizeof c11, 100);
  succ("2.12", c12, sizeof c12, 100);
  succ("2.13", c13, sizeof c13, 100);
  succ("2.14", c14, sizeof c14, 100);
  succ("2.15", c15, sizeof c15, 100);
  succ("2.16", c16, sizeof c16, 100);

  /* e) error cases */
  static const unsigned char e1[] = {0x30, 0x05, 0x02, 0x01, 0x05}, e2[] = {0x30}, e3[] = {0x30, 0x82, 0x01}, e4[] = {0x30, 0x88, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
                                  e5[] = {0x30, 0x89, 1, 2, 3, 4, 5, 6, 7, 8, 9}, e6[] = {0x30, 0x88, 0x80, 0, 0, 0, 0, 0, 0, 0};
  errcase("3.1", "ASN1_get_object(30 05 02 01 05, omax 3)", e1, sizeof e1, 3);
  errcase("3.2", "ASN1_get_object(30, omax 100) truncated header", e2, sizeof e2, 1);
  errcase("3.3", "ASN1_get_object(30 82 01, omax 3) truncated length", e3, sizeof e3, 3);
  errcase("3.4", "ASN1_get_object(30 03 02 01 05, omax 0)", c1, sizeof c1, 0);
  errcase("3.5", "ASN1_get_object(30 03 02 01 05, omax -1)", c1, sizeof c1, -1);
  errcase("3.6", "ASN1_get_object(30 03 02 01 05, omax INT64_MIN)", c1, sizeof c1, (long)0x8000000000000000L);
  errcase("3.7", "ASN1_get_object(30 88 FF x8, omax 100000)", e4, sizeof e4, 100000);
  errcase("3.8", "ASN1_get_object(30 89 .., omax 100000) nine length bytes", e5, sizeof e5, 100000);
  errcase("3.9", "ASN1_get_object(30 88 80 00 .., omax 100000) larger than LONG_MAX", e6, sizeof e6, 100000);

  /* f) error queue in both modules */
  {
    unsigned long p3 = peek3 ? peek3() : 0, p1 = peek1 ? peek1() : 0;
    snprintf(extra, sizeof extra, "Ssl3: has=%d value=0x%lx | Ssl: has=%d value=0x%lx | equal=%d", peek3 != 0, p3, peek1 != 0, p1, p3 == p1);
    probe_case("4.1", "ERR_peek_error after the error cases", 0, 0, extra);
    unsigned long g3 = getE3 ? getE3() : 0, g1 = getE1 ? getE1() : 0;
    snprintf(extra, sizeof extra, "Ssl3: value=0x%lx | Ssl: value=0x%lx | equal=%d", g3, g1, g3 == g1);
    probe_case("4.2", "ERR_get_error from both modules (first entry)", 0, 0, extra);
    if (clr3) clr3();
    if (clr1) clr1();
    unsigned long a3 = peek3 ? peek3() : 0, a1 = peek1 ? peek1() : 0;
    snprintf(extra, sizeof extra, "Ssl3 peek after clear=0x%lx | Ssl peek after clear=0x%lx", a3, a1);
    probe_case("4.3", "ERR_clear_error and ERR_peek_error", 0, 0, extra);
  }

  /* g) NULL cases, last */
  {
    int stopped = 0;
    const char* tn[5] = {"ptag NULL", "pclass NULL", "plength NULL", "pp NULL", "*pp NULL"};
    for (int i = 0; i < 5 && !stopped; ++i) {
      unsigned char b[8] = {0x30, 0x03, 0x02, 0x01, 0x05, 0, 0, 0};
      const unsigned char* p = b;
      long len = -1;
      int tag = -1, cls = -1, r = -1;
      guard_sig = 0;
      alarm(2);
      if (sigsetjmp(guard_env, 1) == 0) {
        guard_active = 1;
        switch (i) {
          case 0: r = g_get(&p, &len, 0, &cls, 100); break;
          case 1: r = g_get(&p, &len, &tag, 0, 100); break;
          case 2: r = g_get(&p, 0, &tag, &cls, 100); break;
          case 3: r = g_get(0, &len, &tag, &cls, 100); break;
          default: { const unsigned char* q = 0; r = g_get(&q, &len, &tag, &cls, 100); break; }
        }
        guard_active = 0;
      } else {
        stopped = 1;
      }
      alarm(PROBE_MAX_S);
      snprintf(id, sizeof id, "5.%d", i + 1);
      snprintf(label, sizeof label, "ASN1_get_object(%s)", tn[i]);
      snprintf(extra, sizeof extra, "ret=0x%x fault_signal=%d", (unsigned)r, (int)guard_sig);
      probe_case(id, label, r, 0, extra);
    }
    if (stopped) probe_case("5.9", "NULL cases stopped after the first fault", 0, 0, "remaining NULL cases skipped by design");
  }

  probe_end();
  return 0;
}
Run at 07:36 UTC on 2026-11-18: stdout
PROBE	libressl3_version_asn1	fw=0x11600005	build=d8bb31967822	pid=292	utc=2026-11-18T09:18:03Z
CASE	0	dlopen of the two modules	0	3	libSceLibreSsl3=1 libSceLibreSsl=1
CASE	0b	dlsym of the names in both modules	0	0	Ssl3: version=1 get_object=1 peek=1 get_error=1 clear=1 SSLeay_version=0 SSLeay=1 version_major=0 version_num=0 | Ssl: version=0 get_object=1 peek=1 get_error=1 clear=1 SSLeay_version=0
CASE	1.1	OpenSSL_version(0)	0	0	not_null=1 same_pointer_twice=1 text="LibreSSL 3.7.3"
CASE	1.2	OpenSSL_version(1)	0	0	not_null=1 same_pointer_twice=1 text="compiler: information not available"
CASE	1.3	OpenSSL_version(2)	0	0	not_null=1 same_pointer_twice=1 text="built on: date not available"
CASE	1.4	OpenSSL_version(3)	0	0	not_null=1 same_pointer_twice=1 text="platform: information not available"
CASE	1.5	OpenSSL_version(4)	0	0	not_null=1 same_pointer_twice=1 text="OPENSSLDIR: \x22/etc/ssl\x22"
CASE	1.6	OpenSSL_version(5)	0	0	not_null=1 same_pointer_twice=1 text="ENGINESDIR: N/A"
CASE	1.7	OpenSSL_version(6)	0	0	not_null=1 same_pointer_twice=1 text="not available"
CASE	1.8	OpenSSL_version(7)	0	0	not_null=1 same_pointer_twice=1 text="not available"
CASE	1.9	OpenSSL_version(8)	0	0	not_null=1 same_pointer_twice=1 text="not available"
CASE	1.10	OpenSSL_version(100)	0	0	not_null=1 same_pointer_twice=1 text="not available"
CASE	1.11	OpenSSL_version(-1)	0	0	not_null=1 same_pointer_twice=1 text="not available"
CASE	1.12	OpenSSL_version(2147483647)	0	0	not_null=1 same_pointer_twice=1 text="not available"
CASE	1.13	OpenSSL_version(-2147483648)	0	0	not_null=1 same_pointer_twice=1 text="not available"
CASE	2.1	ASN1_get_object(3003020105, omax 100)	32	0	ret=0x20 tag=16 class=0x0 length=3 pointer_advanced=2
CASE	2.2	ASN1_get_object(020105, omax 100)	0	0	ret=0x0 tag=2 class=0x0 length=1 pointer_advanced=2
CASE	2.3	ASN1_get_object(0400, omax 100)	0	0	ret=0x0 tag=4 class=0x0 length=0 pointer_advanced=2
CASE	2.4	ASN1_get_object(800100, omax 100)	0	0	ret=0x0 tag=0 class=0x80 length=1 pointer_advanced=2
CASE	2.5	ASN1_get_object(a003020105, omax 100)	32	0	ret=0x20 tag=0 class=0x80 length=3 pointer_advanced=2
CASE	2.6	ASN1_get_object(308180, omax 100000)	32	0	ret=0x20 tag=16 class=0x0 length=128 pointer_advanced=3
CASE	2.7	ASN1_get_object(30820100, omax 100000)	32	0	ret=0x20 tag=16 class=0x0 length=256 pointer_advanced=4
CASE	2.8	ASN1_get_object(3083010000, omax 100000)	32	0	ret=0x20 tag=16 class=0x0 length=65536 pointer_advanced=5
CASE	2.9	ASN1_get_object(30847fffffff, omax 2147483647)	160	0	ret=0xa0 tag=16 class=0x0 length=2147483647 pointer_advanced=6
CASE	2.10	ASN1_get_object(30880000000000000100, omax 100000)	32	0	ret=0x20 tag=16 class=0x0 length=256 pointer_advanced=10
CASE	2.11	ASN1_get_object(1f8100, omax 100)	0	0	ret=0x0 tag=128 class=0x0 length=0 pointer_advanced=4
CASE	2.12	ASN1_get_object(1f1f, omax 100)	0	0	ret=0x0 tag=31 class=0x0 length=0 pointer_advanced=3
CASE	2.13	ASN1_get_object(5f7f, omax 100)	0	0	ret=0x0 tag=127 class=0x40 length=0 pointer_advanced=3
CASE	2.14	ASN1_get_object(1fffffffff7f, omax 100)	128	0	ret=0x80 tag=0 class=0x0 length=0 pointer_advanced=0
CASE	2.15	ASN1_get_object(3080, omax 100)	33	0	ret=0x21 tag=16 class=0x0 length=0 pointer_advanced=2
CASE	2.16	ASN1_get_object(0280, omax 100)	128	0	ret=0x80 tag=0 class=0x0 length=0 pointer_advanced=0
CASE	3.1	ASN1_get_object(30 05 02 01 05, omax 3)	160	0	ret=0xa0 pointer_advanced=2 tag_changed=1 class_changed=1 length_changed=1 fault_signal=0
CASE	3.2	ASN1_get_object(30, omax 100) truncated header	128	0	ret=0x80 pointer_advanced=0 tag_changed=1 class_changed=1 length_changed=1 fault_signal=0
CASE	3.3	ASN1_get_object(30 82 01, omax 3) truncated length	128	0	ret=0x80 pointer_advanced=0 tag_changed=1 class_changed=1 length_changed=1 fault_signal=0
CASE	3.4	ASN1_get_object(30 03 02 01 05, omax 0)	128	0	ret=0x80 pointer_advanced=0 tag_changed=1 class_changed=1 length_changed=1 fault_signal=0
CASE	3.5	ASN1_get_object(30 03 02 01 05, omax -1)	32	0	ret=0x20 pointer_advanced=2 tag_changed=1 class_changed=1 length_changed=1 fault_signal=0
CASE	3.6	ASN1_get_object(30 03 02 01 05, omax INT64_MIN)	32	0	ret=0x20 pointer_advanced=2 tag_changed=1 class_changed=1 length_changed=1 fault_signal=0
CASE	3.7	ASN1_get_object(30 88 FF x8, omax 100000)	160	0	ret=0xa0 pointer_advanced=10 tag_changed=1 class_changed=1 length_changed=0 fault_signal=0
CASE	3.8	ASN1_get_object(30 89 .., omax 100000) nine length bytes	128	0	ret=0x80 pointer_advanced=0 tag_changed=1 class_changed=1 length_changed=1 fault_signal=0
CASE	3.9	ASN1_get_object(30 88 80 00 .., omax 100000) larger than LONG_MAX	160	0	ret=0xa0 pointer_advanced=10 tag_changed=1 class_changed=1 length_changed=1 fault_signal=0
CASE	4.1	ERR_peek_error after the error cases	0	0	Ssl3: has=1 value=0xdfff09b | Ssl: has=1 value=0x0 | equal=0
CASE	4.2	ERR_get_error from both modules (first entry)	0	0	Ssl3: value=0xdfff09b | Ssl: value=0x0 | equal=0
CASE	4.3	ERR_clear_error and ERR_peek_error	0	0	Ssl3 peek after clear=0x0 | Ssl peek after clear=0x0
CASE	5.1	ASN1_get_object(ptag NULL)	-1	0	ret=0xffffffff fault_signal=11
CASE	5.9	NULL cases stopped after the first fault	0	0	remaining NULL cases skipped by design
END	45

AI-assisted (Claude Code).

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: ASN.1 negative bounds

Layer / File(s) Summary
Decoder bound handling and validation
core/libs/prx/libSceLibreSsl3/src/IntegerDecoder.cpp, core/libs/prx/libSceLibreSsl3/tests/ObjectHeader.cpp, docs/dev/debt/changes/docs-libressl3-version-asn1-measured.md
The decoder uses the remaining address space when maximum is negative. Tests verify the -1 and INT64_MIN cases, cursor updates, and invalid-argument exceptions. The documentation records the behavior and notes which negative values were measured.

Suggested reviewers: thegodspeed1999

Change: Bug fix

Merge Risk: Minimal · up to ddf80

This change makes ASN1_get_object accept negative bounds, matching measured PS5 firmware behavior, and updates the tests and documentation. No concrete defect was found, so the merge-readiness risk is minimal.

Security architecture risk: Minimal · up to ddf80

The decoder now accepts a negative limit for console compatibility. This changes which calls proceed, but the review did not establish that callers gain access to memory or privileges they could not already reach with a nonnegative limit.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated exposure change is that callers of the existing guest API can now parse headers using negative bounds. The same byte-read and output paths were already reachable with caller-selected nonnegative bounds; broader access across the guest-to-host boundary was not established.

Trust Boundaries and Controls

  • observed — Guest-provided pointers reach memory through the existing copy-in, writability, and copy-out helpers. The new arithmetic ceiling prevents range wrap but does not check mapping ownership; the helpers' ownership enforcement was not available for source verification.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8e9ca323-cc2e-47a7-b510-7935b5e2e0e3
Commits

Reviewing files that changed from the base of the PR and between 41dfbe4 and ddf80dd.

Files selected for processing: 3

  • core/libs/prx/libSceLibreSsl3/src/IntegerDecoder.cpp
  • core/libs/prx/libSceLibreSsl3/tests/ObjectHeader.cpp
  • docs/dev/debt/changes/docs-libressl3-version-asn1-measured.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the review supports merging based on the inspected code and author-reported checks.

What I ran

  • Reviewed head ddf80dd2f3e84e797a2c19d95b6a230b6502cbf7 using the prepared diff and repo_read.py.
  • No commands or tests were run by me; test results below are author-reported.

Results

Check Result Note
Source and test review passed All three changed files read
Tests and builds not run Author reports 106 LibreSSL 3 tests passed
Merge and conventions not run Author reports clean merge and convention check

Findings

Blocking

None.

Non-blocking

None.

Not verified

No local tests, builds, merge checks, convention checks, or negative control were run. PS5 behavior, Linux and macOS behavior, and title-process behavior were not verified. Read: IntegerDecoder.cpp, ObjectHeader.cpp, docs/dev/debt/changes/docs-libressl3-version-asn1-measured.md, plus the prepared description, commits, manifest, and diff. Excluded files: none; all three changed files were included and read.

To get this to a good state

Nothing is required.

@oneandonlydean
oneandonlydean merged commit c416980 into boykopovar:main Nov 27, 2026
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants