mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
rmapi: keep one copy of the dup share policy (#597)
share_check (behind dup_resource and may_share) now calls may_share_from after its object lookup instead of repeating the rules, so the GSP-RM forwarding gate and the local dup path cannot drift apart. Error order is unchanged: OBJECT_NOT_FOUND before INSUFFICIENT_PERMISSIONS. Follow-up to #337 (Greptile P2).
This commit is contained in:
@ -644,10 +644,8 @@ impl<const C: usize, const R: usize, A: RmAlloc> Server<C, R, A> {
|
||||
self.clients[slot].as_ref().map(|entry| &entry.share)
|
||||
}
|
||||
|
||||
/// Cross-process share policy (`_nv000655rm` -> `serverDupResource` ->
|
||||
/// `clientCanShareResource`): `caller` may take a reference to `(client, handle)` when it
|
||||
/// owns the client, has the same non-zero PID, is admin, or the resource was shared with
|
||||
/// it through `NV_ESC_RM_SHARE` (`_nv000663rm`). Returns the resource slot.
|
||||
/// Whether `caller` may take a reference to `(client, handle)` under the share policy in
|
||||
/// [`Self::may_share_from`], after checking the object exists. Returns the resource slot.
|
||||
fn share_check(&self, caller: &Caller, client: u32, handle: u32) -> Result<usize, NvStatus> {
|
||||
let Some(slot) = self.resource_slot(client, handle) else {
|
||||
return Err(status::OBJECT_NOT_FOUND);
|
||||
@ -655,17 +653,7 @@ impl<const C: usize, const R: usize, A: RmAlloc> Server<C, R, A> {
|
||||
let Some(res) = self.resources[slot] else {
|
||||
return Err(status::OBJECT_NOT_FOUND);
|
||||
};
|
||||
let src_owner = self.client_owner(client);
|
||||
let src_pid = self
|
||||
.client_slot(client)
|
||||
.and_then(|s| self.clients[s])
|
||||
.map_or(0, |c| c.pid);
|
||||
let allowed = src_owner == Some(caller.owner)
|
||||
|| caller.admin
|
||||
|| (caller.pid != 0 && src_pid == caller.pid)
|
||||
|| res.shared_all
|
||||
|| (res.shared_pid != 0 && caller.pid != 0 && res.shared_pid == caller.pid);
|
||||
if !allowed {
|
||||
if !self.may_share_from(caller, client, Some(&res)) {
|
||||
return Err(status::INSUFFICIENT_PERMISSIONS);
|
||||
}
|
||||
Ok(slot)
|
||||
|
||||
Reference in New Issue
Block a user