Ok. I’m successfully creating/reading my Bel LaPadulla markers in a raw disk device MBR, thanks to many of you on here. I’m in the final stages of this driver and now trying to secure the disk if needed. Ie, it should have only read access to all users or no access to all users
So I follow the example in http://blogs.msdn.com/doronh/archive/2007/10/16/setting-a-security-descriptor-on-a-legacy-device-object.aspx and it seems to work so far. I am able to see the pACLs get built and the ACEs added to the pACLs. The security descriptor seems to be built without issue and even the ZwSetSecurityObject seems to work (normal status returned). But when I try to open the disk I can still read/write to it.
For discussion, I am opening the raw disk device first, (i.e. \DosDevices\PhysicalDrive1 for a USB storage device) reading the MBR, since I have the disk open and then setting the security on that device while it is still open with:
status = ZwSetSecurityObject(deviceExtension->MBR, DACL_SECURITY_INFORMATION,
SecurityDescriptorNoAccess);
SecurityDescriptorNoAccess is comprised of the following:
aclNoAccessSize = sizeof(ACL);
aclNoAccessSize += RtlLengthSid(SeExports->SeLocalSystemSid);
aclNoAccessSize += 1 * FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart);
pAclNoAccess = (PACL) ExAllocatePoolWithTag(NonPagedPool, aclNoAccessSize, ‘3gaT’);
SecurityDescriptorNoAccess = (PSECURITY_DESCRIPTOR) ExAllocatePoolWithTag(
NonPagedPool, sizeof(SECURITY_DESCRIPTOR), ‘5gaT’);
status = RtlCreateAcl(pAclNoAccess, aclNoAccessSize, ACL_REVISION);
status = RtlAddAccessAllowedAce(pAclNoAccess, ACL_REVISION, GENERIC_READ,
SeExports->SeLocalSystemSid );
status = RtlCreateSecurityDescriptor(SecurityDescriptorNoAccess,
SECURITY_DESCRIPTOR_REVISION);
status = RtlSetDaclSecurityDescriptor(SecurityDescriptorNoAccess, TRUE, pAclNoAccess,
FALSE);
I wasn’t sure how to set the deny all( I found the ACCESS_DENIED_ACE structure but not a RtlAddAccessDeniedAce() method to apply the ACCESS_DENIED_ACE, so opted to just allow the SeLocalSystemSid to maintain access, though I would prefer nothing being able to access it. Then once the USB device completes my driver and is handed off for other OS functions, it is still completely read/write able. What am I doing wrong?