Skip to content

Commit

Permalink
ensure PcmMsrClient can only opened by root
Browse files Browse the repository at this point in the history
  • Loading branch information
trulyspinach authored and opcm committed Nov 16, 2023
1 parent dd02c99 commit cf555cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/MacMSRDriver/PcmMsr/PcmMsrClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,23 @@ IOReturn PcmMsrClientClassName::externalMethod(uint32_t selector, IOExternalMeth
return super::externalMethod(selector, args, dispatch, target, reference);
}

bool PcmMsrClientClassName::initWithTask(task_t owningTask, void *securityToken, UInt32 type, OSDictionary *properties)
{
if(!IOUserClient::initWithTask(owningTask, securityToken, type, properties)) {
return false;
}

sSecurityToken = securityToken;
return true;
}

bool PcmMsrClientClassName::start(IOService* provider)
{
bool result = false;


if(clientHasPrivilege(sSecurityToken, kIOClientPrivilegeAdministrator) != kIOReturnSuccess)
return false;

fProvider = OSDynamicCast(PcmMsrDriverClassName, provider);

if (fProvider != NULL) {
Expand Down
4 changes: 3 additions & 1 deletion src/MacMSRDriver/PcmMsr/PcmMsrClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class PcmMsrClientClassName : public IOUserClient

protected:
PcmMsrDriverClassName* fProvider;
void* sSecurityToken;
static const IOExternalMethodDispatch sMethods[kNumberOfMethods];

public:
virtual bool initWithTask(task_t owningTask, void *securityToken, UInt32 type, OSDictionary *properties) override;
virtual bool start(IOService *provider) override;

virtual IOReturn clientClose(void) override;

virtual bool didTerminate(IOService* provider, IOOptionBits opts, bool* defer) override;
Expand Down

0 comments on commit cf555cd

Please sign in to comment.