- Notifications
You must be signed in to change notification settings - Fork5
Commitdb69e58
committed
Reset plan->row_security_env and planUserId
In the plancache, we check if the environment we planned the query underhas changed in a way which requires us to re-plan, such as when the userfor whom the plan was prepared changes and RLS is being used (and,therefore, there may be different policies to apply).Unfortunately, while those values were set and checked, they were notbeing reset when the query was re-planned and therefore, in cases wherewe change role, re-plan, and then change role again, we weren'tre-planning again. This leads to potentially incorrect policies beingapplied in cases where role-specific policies are used and a given queryis planned under one role and then executed under other roles, whichcould happen under security definer functions or when a common user andquery is planned initially and then re-used across multiple SET ROLEs.Further, extensions which made use of CopyCachedPlan() may suffer fromsimilar issues as the RLS-related fields were not properly copied aspart of the plan and therefore RevalidateCachedQuery() would copy in thecurrent settings without invalidating the query.Fix by using the same approach used for 'search_path', where we set thecorrect values in CompleteCachedPlan(), check them early on inRevalidateCachedQuery() and then properly reset them if re-planning.Also, copy through the values during CopyCachedPlan().Pointed out by Ashutosh Bapat. Reviewed by Michael Paquier.Back-patch to 9.5 where RLS was introduced.Security:CVE-2016-21931 parentd6e7401 commitdb69e58
File tree
3 files changed
+49
-14
lines changed- src
- backend/utils/cache
- test/regress
- expected
- sql
3 files changed
+49
-14
lines changedLines changed: 26 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
19 |
| - | |
| 19 | + | |
| 20 | + | |
20 | 21 |
| |
21 | 22 |
| |
22 | 23 |
| |
| |||
204 | 205 |
| |
205 | 206 |
| |
206 | 207 |
| |
207 |
| - | |
208 | 208 |
| |
| 209 | + | |
209 | 210 |
| |
210 | 211 |
| |
211 | 212 |
| |
| |||
271 | 272 |
| |
272 | 273 |
| |
273 | 274 |
| |
| 275 | + | |
| 276 | + | |
274 | 277 |
| |
275 | 278 |
| |
276 | 279 |
| |
| |||
409 | 412 |
| |
410 | 413 |
| |
411 | 414 |
| |
| 415 | + | |
| 416 | + | |
412 | 417 |
| |
413 | 418 |
| |
414 | 419 |
| |
| |||
571 | 576 |
| |
572 | 577 |
| |
573 | 578 |
| |
574 |
| - | |
575 |
| - | |
576 |
| - | |
577 |
| - | |
578 |
| - | |
579 |
| - | |
580 |
| - | |
581 |
| - | |
582 |
| - | |
583 |
| - | |
584 |
| - | |
585 | 579 |
| |
586 | 580 |
| |
587 | 581 |
| |
588 |
| - | |
| 582 | + | |
589 | 583 |
| |
590 | 584 |
| |
591 | 585 |
| |
| 586 | + | |
| 587 | + | |
592 | 588 |
| |
593 | 589 |
| |
594 | 590 |
| |
| |||
643 | 639 |
| |
644 | 640 |
| |
645 | 641 |
| |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
646 | 650 |
| |
647 | 651 |
| |
648 | 652 |
| |
| |||
1380 | 1384 |
| |
1381 | 1385 |
| |
1382 | 1386 |
| |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
1383 | 1395 |
| |
1384 | 1396 |
| |
1385 | 1397 |
| |
|
Lines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2334 | 2334 |
| |
2335 | 2335 |
| |
2336 | 2336 |
| |
| 2337 | + | |
2337 | 2338 |
| |
2338 | 2339 |
| |
| 2340 | + | |
2339 | 2341 |
| |
2340 | 2342 |
| |
2341 | 2343 |
| |
2342 | 2344 |
| |
2343 | 2345 |
| |
2344 | 2346 |
| |
2345 | 2347 |
| |
| 2348 | + | |
2346 | 2349 |
| |
| 2350 | + | |
2347 | 2351 |
| |
2348 | 2352 |
| |
2349 | 2353 |
| |
2350 | 2354 |
| |
2351 | 2355 |
| |
2352 | 2356 |
| |
2353 | 2357 |
| |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
2354 | 2368 |
| |
2355 | 2369 |
| |
2356 | 2370 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
852 | 852 |
| |
853 | 853 |
| |
854 | 854 |
| |
| 855 | + | |
855 | 856 |
| |
856 | 857 |
| |
| 858 | + | |
857 | 859 |
| |
858 | 860 |
| |
| 861 | + | |
859 | 862 |
| |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
860 | 869 |
| |
861 | 870 |
| |
862 | 871 |
| |
|
0 commit comments
Comments
(0)