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
| ||
|
Message-ID: <CACETy0n0217=JOnHUWvxM_npDrdg4U=nzGYKqYbGFsvspjP6gg@mail.gmail.com> Date: Thu, 17 Aug 2023 16:53:03 +0200 From: Michele Dalle Rive <dallerivemichele@...il.com> To: Andrew Lunn <andrew@...n.ch> Cc: Greg KH <gregkh@...uxfoundation.org>, Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>, Wedson Almeida Filho <wedsonaf@...il.com>, "David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>, Alice Ryhl <aliceryhl@...gle.com>, Davide Rovelli <davide.rovelli@....ch>, rust-for-linux@...r.kernel.org, netdev@...r.kernel.org, linux-kernel@...r.kernel.org, patches@...ts.linux.dev Subject: Re: [RFC PATCH 0/7] Rust Socket abstractions On Mon, 14 Aug 2023 at 23:36, Andrew Lunn <andrew@...n.ch> wrote: > > > > There is a long standing tradition in Linux, you don't get a new API > > > merged without a user. > > > > Sorry for not being clear on that. > > > > These abstractions are meant to be used by modules: having them, modules > > can start using the kernel network functionalities through a first, high level > > interface. > > > > Since there is currently no network support in Rust, this patch series > > represents a first step to provide access to networking to modules. > > Sockets are just the highest layer of the network stack: the goal would be > > to port structures deeper in the network stack, to give modules more > > access to the network api. However, you need to start somewhere. > > > > > > > > There is not too much use of in kernel sockets. Network file systems > > > like NFS, and SMB are one. These need to be careful with memory usage, > > > you could be busy writing blocks out because the system is low on > > > memory and trying to free some up, and asking for more memory might > > > not work. Sending kernel log messages to a server. But that needs > > > care because of the different contexts it can be used in. Without > > > knowing what it will be used for, it is hard for us the point the > > > special considerations which need to be made. > > > > > > So please also let us see the code using this API. > > > > > > Andrew > > > > The lack of these abstractions was noticed in the context of a research > > of the usability of Rust for the development of consensus algorithms using UDP. > > O.K, so what are the use cases for consensus algorithms using UDP > within the kernel? Where is this code? Ideally you should post it for > merging alongside the rust API to sockets its needs. We can then > review both together, just as we would if somebody were submitting a > new API in C along with its user. > > Andrew Hello Andrew, in the last few days, I had the opportunity to discuss with some people from the RustForLinux community. I apologize for not being clear: the goal of these APIs was to give some network support to, in particular, out-of-tree modules; they were not meant to be used by a specific module that was planned to get upstreamed as well. The idea behind this patch is that, as of now, Rust is not a viable option for any OOT module that requires even the highest-level network support. I am wondering whether the `net` subsystem is interested in reviewing, giving feedback and eventually accepting code that is currently OOT-only. Also, it would be interesting if you could provide us any module or functionality you are planning to get in-tree which might use this interface; it could be useful in order to understand the applicability of these abstractions and find a concrete in-kernel use-case. I included in the email a couple of sample OOT modules that showcase the functionalities of the socket API; they will be attached as an actual patch if there will be a v2. Thank you for your time, Michele >From 4c966f6ff3acd3b7c27f7a558648722b227d45a7 Mon Sep 17 00:00:00 2001 From: Michele Dalle Rive <dallerivemichele@...il.com> Date: Thu, 17 Aug 2023 15:51:47 +0200 Subject: [PATCH] rust: net: add OOT sample modules. Add two sample modules that showcase some functionalities of the Rust socket API. Signed-off-by: Michele Dalle Rive <dallerivemichele@...il.com> --- samples/rust/rust_socket.rs | 45 +++++++++++++++++++++++++++++++++ samples/rust/rust_tcp_server.rs | 34 +++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 samples/rust/rust_socket.rs create mode 100644 samples/rust/rust_tcp_server.rs diff --git a/samples/rust/rust_socket.rs b/samples/rust/rust_socket.rs new file mode 100644 index 000000000000..fc1ed8536e57 --- /dev/null +++ b/samples/rust/rust_socket.rs @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust minimal sample. + +use core::str::FromStr; +use kernel::prelude::*; +use kernel::net::socket::*; +use kernel::net::ip::IpProtocol; +use kernel::net::addr::{SocketAddr}; +use kernel::net::AddressFamily; +use kernel::flag_set; + +module! { + type: RustSocket, + name: "rust_socket", + author: "Rust for Linux Contributors", + description: "Rust sockets support sample", + license: "GPL", +} + +struct RustSocket {} + +impl kernel::Module for RustSocket { + fn init(_module: &'static ThisModule) -> Result<Self> { + let sock = Socket::new(AddressFamily::Inet, SockType::Datagram, IpProtocol::Udp)?; + let addr = "0.0.0.0:8000"; + sock.bind(SocketAddr::from_str(addr)?)?; + + sock.set_option::<opts::sock::ReuseAddr>(true)?; + + assert_eq!(sock.sockname()?, SocketAddr::from_str(addr)?); + + let mut buf = [0; 1024]; + while let Ok((bytes, msghdr)) = sock.receive_msg(&mut buf, flag_set!()) { + if bytes == 0 { + break; + } + pr_info!("Received {} bytes from {}", bytes, msghdr.address().unwrap()); + if msghdr.flags().contains(flags::MessageFlag::Trunc) { + pr_info!("The message was truncated"); + } + } + Ok(Self{}) + } +} \ No newline at end of file diff --git a/samples/rust/rust_tcp_server.rs b/samples/rust/rust_tcp_server.rs new file mode 100644 index 000000000000..987c4c752d2b --- /dev/null +++ b/samples/rust/rust_tcp_server.rs @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust echo server sample. + +use core::str::FromStr; +use kernel::prelude::*; +use kernel::net::tcp::TcpListener; +use kernel::net::addr::SocketAddr; +use kernel::flag_set; + +module! { + type: RustTcpServer, + name: "rust_tcp_server", + author: "Rust for Linux Contributors", + license: "GPL", +} + +struct RustTcpServer {} + +impl kernel::Module for RustTcpServer { + fn init(_module: &'static ThisModule) -> Result<Self> { + let listener = TcpListener::new(SocketAddr::from_str("0.0.0.0:8000")?)?; + while let Ok(stream) = listener.accept() { + let mut buf = [0; 1024]; + while let Ok(size) = stream.receive(&mut buf, flag_set!()) { + if size == 0 { + break; + } + stream.send(&buf[..size], flag_set!())?; + } + } + Ok(Self {}) + } +} -- 2.41.0
Powered by blists - more mailing lists