lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aKQJHOKOFn8i_F9Y@zeus>
Date: Tue, 19 Aug 2025 14:18:20 +0900
From: Ryosuke Yasuoka <ryasuoka@...hat.com>
To: Benno Lossin <lossin@...nel.org>
Cc: arnd@...db.de, gregkh@...uxfoundation.org, ojeda@...nel.org,
	alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
	bjorn3_gh@...tonmail.com, a.hindborg@...nel.org,
	aliceryhl@...gle.com, tmgross@...ch.edu, dakr@...nel.org,
	lee@...nel.org, rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH rust-next 2/2] rust: samples: miscdevice: add lseek
 samples

On Tue, Aug 19, 2025 at 12:05:41AM +0200, Benno Lossin wrote:
> On Mon Aug 18, 2025 at 3:58 PM CEST, Ryosuke Yasuoka wrote:
> > +    fn llseek(me: Pin<&RustMiscDevice>, file: &File, offset: i64, whence: i32) -> Result<isize> {
> > +        dev_info!(me.dev, "LLSEEK Rust Misc Device Sample\n");
> > +        let pos: i64;
> > +        let eof: i64;
> > +
> > +        // SAFETY:
> > +        // * The file is valid for the duration of this call.
> > +        // * f_inode must be valid while the file is valid.
> > +        unsafe {
> > +            pos = (*file.as_ptr()).f_pos;
> > +            eof = (*(*file.as_ptr()).f_inode).i_size;
> > +        }
> 
> Please include abstractions for writing & reading the file position
> instead of using `unsafe`.

OK. I believe I probably need to modify on the kernel:fs::file::File to
add abstraction for writing & reading. I'll re-consider and send them in
v2 patch.

Thank you very much for your comment.

> ---
> Cheers,
> Benno
> 
> > +
> > +        let new_pos = match whence {
> > +            SEEK_SET => offset,
> > +            SEEK_CUR => pos + offset,
> > +            SEEK_END => eof + offset,
> > +            _ => {
> > +                dev_err!(me.dev, "LLSEEK does not recognised: {}.\n", whence);
> > +                return Err(EINVAL);
> > +            }
> > +        };
> > +
> > +        if new_pos < 0 {
> > +            dev_err!(me.dev, "The file offset becomes negative: {}.\n", new_pos);
> > +            return Err(EINVAL);
> > +        }
> > +
> > +        // SAFETY: The file is valid for the duration of this call.
> > +        let ret: isize = unsafe {
> > +            (*file.as_ptr()).f_pos = new_pos;
> > +            new_pos as isize
> > +        };
> > +
> > +        Ok(ret)
> > +    }
> > +
> >      fn ioctl(me: Pin<&RustMiscDevice>, _file: &File, cmd: u32, arg: usize) -> Result<isize> {
> >          dev_info!(me.dev, "IOCTLing Rust Misc Device Sample\n");
> >  
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ