diff options
author | Keiichi Watanabe <keiichiw@chromium.org> | 2020-04-08 03:55:37 +0900 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-04-15 18:01:33 +0000 |
commit | 05489a7637c10232e759ce3885e860a4f8d2d1be (patch) | |
tree | 91b919c309348f59b8f725251a05e84b53a0b765 | |
parent | 275c1ef45db270b9cf0d7c614e5bdf59cb91bb41 (diff) | |
download | crosvm-05489a7637c10232e759ce3885e860a4f8d2d1be.tar crosvm-05489a7637c10232e759ce3885e860a4f8d2d1be.tar.gz crosvm-05489a7637c10232e759ce3885e860a4f8d2d1be.tar.bz2 crosvm-05489a7637c10232e759ce3885e860a4f8d2d1be.tar.lz crosvm-05489a7637c10232e759ce3885e860a4f8d2d1be.tar.xz crosvm-05489a7637c10232e759ce3885e860a4f8d2d1be.tar.zst crosvm-05489a7637c10232e759ce3885e860a4f8d2d1be.zip |
crosvm: Fix clippy::correctness error
Fix a style problem categorized into `clippy::correctness`, which causes an error by default. BUG=chromium:908640 TEST=cargo clippy --all-features --all-targets -- -D clippy:correctness Change-Id: I85f54c9b031a1628127041e85678c88f1c72d4df Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2145535 Tested-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
-rw-r--r-- | io_jail/src/lib.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/io_jail/src/lib.rs b/io_jail/src/lib.rs index a927cdb..7a12307 100644 --- a/io_jail/src/lib.rs +++ b/io_jail/src/lib.rs @@ -68,6 +68,8 @@ pub enum Error { PreservingFd(i32), /// Program size is too large ProgramTooLarge, + /// Alignment of file should be divisible by the alignment of sock_filter. + WrongProgramAlignment, /// File size should be non-zero and a multiple of sock_filter WrongProgramSize, } @@ -148,6 +150,10 @@ impl Display for Error { ProcFd(s) => write!(f, "an entry in /proc/self/fd is not an integer: {}", s), PreservingFd(e) => write!(f, "fork failed in minijail_preserve_fd with error {}", e), ProgramTooLarge => write!(f, "bpf program is too large (max 64K instructions)"), + WrongProgramAlignment => write!( + f, + "the alignment of bpf file was not a multiple of that of sock_filter" + ), WrongProgramSize => write!(f, "bpf file was empty or not a multiple of sock_filter"), } } @@ -287,6 +293,13 @@ impl Minijail { if count > (!0 as u16) as usize { return Err(Error::ProgramTooLarge); } + if buffer.as_ptr() as usize % std::mem::align_of::<sock_filter>() != 0 { + return Err(Error::WrongProgramAlignment); + } + + // Safe cast because we checked that the buffer address is divisible by the alignment of + // sock_filter. + #[allow(clippy::cast_ptr_alignment)] let header = sock_fprog { len: count as c_ushort, filter: buffer.as_ptr() as *mut sock_filter, |