=== Applying patches on top of PostgreSQL commit ID 81b2179b492e3af891544813b7e22a42386b34d0 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Mon Nov 16 00:03:29 UTC 2026 On branch cf/7403 nothing to commit, working tree clean === using 'git am' to apply patch ./0001-Check-RLS-policies-before-evaluating-the-ON-CONFLICT.patch === Applying: Check RLS policies before evaluating the ON CONFLICT WHERE clause Using index info to reconstruct a base tree... M src/backend/executor/nodeModifyTable.c M src/test/regress/expected/rowsecurity.out M src/test/regress/sql/rowsecurity.sql Falling back to patching base and 3-way merge... Auto-merging src/test/regress/sql/rowsecurity.sql Auto-merging src/test/regress/expected/rowsecurity.out Auto-merging src/backend/executor/nodeModifyTable.c CONFLICT (content): Merge conflict in src/backend/executor/nodeModifyTable.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Check RLS policies before evaluating the ON CONFLICT WHERE clause When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". === using patch(1) to apply patch ./0001-Check-RLS-policies-before-evaluating-the-ON-CONFLICT.patch === patching file src/backend/executor/nodeModifyTable.c Hunk #1 FAILED at 2945. Hunk #2 succeeded at 2992 with fuzz 1 (offset 16 lines). Hunk #3 FAILED at 3102. Hunk #4 succeeded at 3153 with fuzz 1 (offset 26 lines). 2 out of 4 hunks FAILED -- saving rejects to file src/backend/executor/nodeModifyTable.c.rej patching file src/test/regress/expected/rowsecurity.out patching file src/test/regress/sql/rowsecurity.sql Unstaged changes after reset: M src/backend/executor/nodeModifyTable.c M src/test/regress/expected/rowsecurity.out M src/test/regress/sql/rowsecurity.sql Removing src/backend/executor/nodeModifyTable.c.rej === using 'git apply' to apply patch ./0001-Check-RLS-policies-before-evaluating-the-ON-CONFLICT.patch === Applied patch to 'src/backend/executor/nodeModifyTable.c' with conflicts. Applied patch to 'src/test/regress/expected/rowsecurity.out' cleanly. Applied patch to 'src/test/regress/sql/rowsecurity.sql' cleanly. U src/backend/executor/nodeModifyTable.c diff --cc src/backend/executor/nodeModifyTable.c index 966094b6a32,8130cf4949d..00000000000 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@@ -2935,6 -2934,23 +2935,26 @@@ ExecOnConflictUpdate(ModifyTableContex */ ExecCheckTupleVisible(context->estate, relation, existing); ++<<<<<<< ours ++======= + /* + * Make tuple and any needed join variables available to ExecQual and + * ExecProject. The EXCLUDED tuple is installed in ecxt_innertuple, while + * the target's existing tuple is installed in the scantuple. EXCLUDED + * has been made to reference INNER_VAR in setrefs.c, but there is no + * other redirection. + */ + econtext->ecxt_scantuple = existing; + econtext->ecxt_innertuple = excludedSlot; + econtext->ecxt_outertuple = NULL; + + /* + * The RLS checks below must run before the WHERE clause is evaluated. The + * WHERE clause is user-supplied and can contain leaky functions, which + * must not get to see an existing row that the policies hide from the + * user. + */ ++>>>>>>> theirs if (resultRelInfo->ri_WithCheckOptions != NIL) { /* @@@ -2969,29 -2973,15 +2989,36 @@@ ExecWithCheckOptions(WCO_RLS_CONFLICT_CHECK, resultRelInfo, existing, mtstate->ps.state); + ExecWithCheckOptions(WCO_VIEW_CONFLICT_CHECK, resultRelInfo, + existing, + mtstate->ps.state); + } + + /* + * Make tuple and any needed join variables available to ExecQual and + * ExecProject. The EXCLUDED tuple is installed in ecxt_innertuple, while + * the target's existing tuple is installed in the scantuple. EXCLUDED + * has been made to reference INNER_VAR in setrefs.c, but there is no + * other redirection. + */ + econtext->ecxt_scantuple = existing; + econtext->ecxt_innertuple = excludedSlot; + econtext->ecxt_outertuple = NULL; + + if (!ExecQual(onConflictSetWhere, econtext)) + { + ExecClearTuple(existing); /* see return below */ + InstrCountFiltered1(&mtstate->ps, 1); + return true; /* done with the tuple */ } + if (!ExecQual(onConflictSetWhere, econtext)) + { + ExecClearTuple(existing); /* see return below */ + InstrCountFiltered1(&mtstate->ps, 1); + return true; /* done with the tuple */ + } + /* Project the new tuple version */ ExecProject(resultRelInfo->ri_onConflict->oc_ProjInfo); @@@ -3139,6 -3101,29 +3166,32 @@@ ExecOnConflictSelect(ModifyTableContex econtext->ecxt_innertuple = excludedSlot; econtext->ecxt_outertuple = NULL; ++<<<<<<< ours ++======= + /* + * As in ExecOnConflictUpdate(), the RLS checks must run before the WHERE + * clause is evaluated, so that user-supplied expressions never see a row + * that the policies hide from the user. + */ + if (resultRelInfo->ri_WithCheckOptions != NIL) + { + /* + * Check target's existing tuple against SELECT-applicable USING + * security barrier quals (if any), enforced here as RLS checks/WCOs. + * + * The rewriter creates WCOs from the USING quals of SELECT policies, + * and stores them as WCOs of "kind" WCO_RLS_CONFLICT_CHECK. If FOR + * UPDATE/SHARE was specified, UPDATE permissions are required on the + * target table, and the rewriter also adds WCOs built from the USING + * quals of UPDATE policies, using WCOs of the same kind, and this + * check enforces them too. + */ + ExecWithCheckOptions(WCO_RLS_CONFLICT_CHECK, resultRelInfo, + existing, + mtstate->ps.state); + } + ++>>>>>>> theirs if (!ExecQual(onConflictSelectWhere, econtext)) { ExecClearTuple(existing); /* see return below */