Issue Information
| Issue Number | 701927a |
| Symptom | When a RESULT_CACHE function is called from PL/SQL by an account other than the owner, the function body is executed using the schema and privileges of the caller account. This applies to anonymous blocks, stored procedures, package bodies, triggers, and dynamic PL/SQL. If the function body references a synonym or table belonging to the owner, the caller cannot find the object, resulting in a TBR-8033 (Specified schema object was not found) error. If exception handling exists in the function, the corresponding return value (such as -1) is returned as the result. Conversely, if an object with the same name exists for the caller, the caller's object is read without an error and an incorrect value is returned. In addition, CURRENT_SCHEMA inside the function is recognized as the caller rather than the owner. These incorrectly calculated values are stored in the shared result cache, and when another user, including the owner, subsequently calls the function with the same arguments from PL/SQL, that user receives the incorrect value. The function operates normally when called through SQL (SELECT f() FROM DUAL) or when the function does not have RESULT_CACHE. |
| Cause | During PSM bytecode generation, when calling a definer's rights function from another unit, a marker indicating "switch user to owner" is placed before the call instruction. At runtime, this marker is checked upon entry to the function, the session user information is changed to the function owner, and then restored when the function ends. The general DDL function call path includes this marker, but the RESULT_CACHE function-specific call path has lacked this processing since the feature was first introduced. As a result, when the function body is executed due to a cache miss, the user switch does not occur, so name resolution and privilege checks for SQL in the body are performed based on the caller. In addition, the result cache key on the PL/SQL path is determined only by the function and its arguments, regardless of the caller, so incorrectly calculated results are shared as-is and returned to other users as well. In contrast, the SQL path treats the function as a new execution entry point, and the entry point always switches to the owner regardless of the associated marker, so it is not affected by this issue. |
| Solutions | When calling a RESULT_CACHE function, a marker for execution with the owner's privileges is generated if the function has definer's rights, and no marker is generated if the function has invoker's rights. If a result cache hit occurs during execution and entry into the function is skipped, processing ensures that the marker is not passed to the next call. This operates in the same manner as the external procedure call path. There are no changes to the instruction structure or storage format, and newly compiled code runs normally on binaries from previous versions. Existing PSMs (Procedural Stored Modules) must be recompiled for the fix to take effect, and stored PSMs that reference RESULT_CACHE functions must be forcibly recompiled and the result cache must be cleared. The SQL path, functions without RESULT_CACHE, invoker's rights functions, and result cache keys remain unchanged. |
| Occurrence Date | 26.11.23. |
| Version Requiring the Patch | 7FS02PS |
Patch Information
| Patch Name | FS02PS_701927a |
| Major Version | 7 |
| Minor Version | FS02PS |
| Version Title | Fix missing definer's right when calling RESULT_CACHE functions from PSM |
| Available for Deployment | 26.11.30. |
| Compatibility | • TAC rolling patch: Available • TSC rolling patch: Available • Backup data compatibility: Available • Protocol compatibility: Available • Data format compatibility: Available |
| AP Impact | • Plan change: No • Result value change: Yes • SQL syntax change: No • System object change: No • Existing functionality change: No |
| Parameter | - |
| Workaround | - |