Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soundness issue for svd2rust generated code #2

Closed
CXWorks opened this issue Jul 14, 2024 · 1 comment
Closed

Soundness issue for svd2rust generated code #2

CXWorks opened this issue Jul 14, 2024 · 1 comment

Comments

@CXWorks
Copy link

CXWorks commented Jul 14, 2024

Hi,

Thanks for your time. We are researchers focusing on Rust's unsafe soundness issues, our automaic tools found the potential issues in your generated code from svd2rust, a logical unsafe function is marked as safe:

#[doc = r"Writes raw bits to the field"]
#[inline(always)]
pub fn bits(self, value: u8) -> &'a mut W {
self.w.bits = (self.w.bits & !(0x03 << 12)) | (((value as u32) & 0x03) << 12);
self.w
}

please check this issue from svd2rust for more details: rust-embedded/svd2rust#714

And the latest(2024-07-14) svd2rust will generate the code like below for similiar cases:

    #[doc = " Writes raw bits to the field"]
    #[doc = ""]
    #[doc = " # Safety"]
    #[doc = ""]
    #[doc = " Passing incorrect value can cause undefined behaviour. See reference manual"]
    #[inline(always)]
    pub unsafe fn bits(self, value: FI::Ux) -> &'a mut W<REG> {
        self.w.bits &= !(REG::Ux::mask::<WI>() << self.o);
        self.w.bits |= (REG::Ux::from(value) & REG::Ux::mask::<WI>()) << self.o;
        self.w
    }

The esiaest way to fix is to regenerate the Rust library. Thanks again for your time & paitence!

@CXWorks
Copy link
Author

CXWorks commented Jul 19, 2024

This is a false positive since the register accepts all the possible input values, sorry for troubling.

@CXWorks CXWorks closed this as completed Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant