From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 240976E5ED for ; Tue, 2 Jul 2024 19:06:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719947212; cv=none; b=ZdF9MH0Y2VoJvW0PmvxHYP3L98cKC1mRq/pAaWSkHAs/V77NwSIvYHH6jpQ9UgzstKxIcpvjJq6qO3Pu+a/PSuEyKEpDBWTq8POPoibaWY7mi7uYSJwvgY8Adk8AOvSin55ViVpdVTxAANrdFupT2JJW1TN31peXRqnLcBW/8FE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719947212; c=relaxed/simple; bh=9oTQbPhIKrtj2CunXwJ1xKEFkcptcJJZbcDmZP1qBfs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K8dEJH2j29WyoDJQEn8lVSTdei80eoU9DF+2Nan8wF/6F92NduWvI2KFnN15maFePWWRhvfCpXOd6ZhXhI3RjJTKBgl2xH34z1nbb4kTrEpNInbfCp/cKF8y7Bkt4FsVfpZdZEhEkWZLV+j2bXoiwXeNzFFmdKgIefTaU9tcvnU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jo2Y74lh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eBPG4xjr; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jo2Y74lh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eBPG4xjr" Date: Tue, 2 Jul 2024 20:12:33 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1719943956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rBL/9oB2KixNpv9EdsvM6VEir6mo24cXpWJumxL6yp4=; b=jo2Y74lhL7qEIO57nDymsv9dhUH1dkIfII8sj6MHJpY6KHV0dYdJidrzDu0sCceYHBQlk+ +zpL1dPax8a4yK8OhkpR0hpgG5bpWuwtLfMYvRLLiwJK9B0DKhWG5vyw2PNouIYgPK5Osq +aObcO5X30yd8lEeNWfRs9gC3j6dR9XJQBfC64l9oI4q/r9uuDELIjsb1IzVwR44cvLn1q vJkChKZr7J2RiEHZUMNUd3ZZ7Ym6xFca+cpwY4et6mkGoh6+WEeoLfvbg0jBp0CdOf8J45 DaC2YGkoLW8rJlr4OiDXbkRbNom4NcW2TvJOgphnH3/hB4mYREmRwyVoXghhyQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1719943956; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rBL/9oB2KixNpv9EdsvM6VEir6mo24cXpWJumxL6yp4=; b=eBPG4xjrhwETYQJGKeLK24dE2+JSoNvIBVtjHaOht72U7TArHtomXx87meO4wL7wuuwC94 Vx9mfHuQnHQjWJAA== From: Sebastian Andrzej Siewior To: Jiri Olsa Cc: bpf@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Hao Luo , John Fastabend , KP Singh , Martin KaFai Lau , Song Liu , Stanislav Fomichev , Thomas Gleixner , Yonghong Song Subject: Re: [PATCH v2 bpf-next 3/3] bpf: Implement bpf_check_basics_ok() as a macro. Message-ID: <20240702181233.URQ43uFX@linutronix.de> References: <20240702142542.179753-1-bigeasy@linutronix.de> <20240702142542.179753-4-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: On 2024-07-02 18:27:31 [+0200], Jiri Olsa wrote: > On Tue, Jul 02, 2024 at 04:21:43PM +0200, Sebastian Andrzej Siewior wrote: > > sparse complains about the argument type for filter that is passed to > > bpf_check_basics_ok(). There are two users of the function where the > > variable is with __user attribute one without. The pointer is only > > checked against NULL so there is no access to the content and so no need > > for any user-wrapper. > >=20 > > Adding the __user to the declaration doesn't solve anything because > > there is one kernel user so it will be wrong again. > > Splitting the function in two seems an overkill because the function is > > small and simple. >=20 > could we just retype the __user argument? like >=20 > bpf_check_basics_ok((const struct sock_filter *) fprog->filter, ...) If we keep the function and add a cast here then cast the __user part away and it would be wrong if we do something else with the pointer. If it is understood that that will never happen=E2=80=A6 > > --- a/net/core/filter.c > > +++ b/net/core/filter.c > > @@ -1035,16 +1035,20 @@ static bool chk_code_allowed(u16 code_to_probe) =E2=80=A6 > > + /* macro instead of a function to avoid woring about _filter which mi= ght be a > > + * user or kernel pointer. It does not matter for the NULL check. > > + */ > > +#define bpf_check_basics_ok(fprog_filter, fprog_flen) \ > > +({ \ > > + bool __ret =3D true; \ > > + u16 __flen =3D fprog_flen; \ >=20 > why not use fprog_flen directly? I'm not sure I get the changelog > explanation=20 This was to avoid expanding `fprog_flen' twice. But looking at the actual output, the code generation seems to be unaffected. > thanks, > jirka Sebastian