From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12927C43331 for ; Sun, 29 Mar 2020 16:52:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF4EE2073B for ; Sun, 29 Mar 2020 16:52:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728110AbgC2Qwa (ORCPT ); Sun, 29 Mar 2020 12:52:30 -0400 Received: from mx.sdf.org ([205.166.94.20]:61333 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727323AbgC2Qwa (ORCPT ); Sun, 29 Mar 2020 12:52:30 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 02TGq4Aa019498 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sun, 29 Mar 2020 16:52:05 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02TGq45F000077; Sun, 29 Mar 2020 16:52:04 GMT Date: Sun, 29 Mar 2020 16:52:04 +0000 From: George Spelvin To: Bernard Metzler Cc: linux-kernel@vger.kernel.org, Doug Ledford , Jason Gunthorpe , linux-rdma@vger.kernel.org, Faisal Latif , Shiraz Saleem , Bart Van Assche , lkml@sdf.org Subject: Re: [RFC PATCH v1 42/50] drivers/ininiband: Use get_random_u32() Message-ID: <20200329165204.GC4675@SDF.ORG> References: <202003281643.02SGhN9T020186@sdf.org> MIME-Version: 1.0 Content-Type: text/plain Content-Disposition: inline In-Reply-To: Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org On Sun, Mar 29, 2020 at 03:01:36PM +0000, Bernard Metzler wrote: > -----"George Spelvin" wrote: ----- >> Subject: [EXTERNAL] [RFC PATCH v1 42/50] drivers/ininiband: Use get_random_u32() >> >> There's no need to get_random_bytes() into a temporary buffer. >> >> This is not a no-brainer change; get_random_u32() has slightly weaker >> security guarantees, but code like this is the classic example of when >> it's appropriate: the random value is stored in the kernel for as long >> as it's valuable. >> >> TODO: Could any of the call sites be further weakened to prandom_u32()? >> If we're randomizing to avoid collisions with a *cooperating* (as opposed >> to malicious) partner, we don't need cryptographic strength. >> >> Signed-off-by: George Spelvin >> Cc: Doug Ledford >> Cc: Jason Gunthorpe >> Cc: linux-rdma@vger.kernel.org >> Cc: Faisal Latif >> Cc: Shiraz Saleem >> Cc: Bart Van Assche >> Cc: Bernard Metzler >> diff --git a/drivers/infiniband/sw/siw/siw_verbs.c >> b/drivers/infiniband/sw/siw/siw_verbs.c >> index 5fd6d6499b3d7..42f3ced4ca7c7 100644 >> --- a/drivers/infiniband/sw/siw/siw_verbs.c >> +++ b/drivers/infiniband/sw/siw/siw_verbs.c >> @@ -1139,7 +1139,7 @@ int siw_create_cq(struct ib_cq *base_cq, const >> struct ib_cq_init_attr *attr, >> rv = -ENOMEM; >> goto err_out; >> } >> - get_random_bytes(&cq->id, 4); >> + cq->id = get_random_u32(); >> siw_dbg(base_cq->device, "new CQ [%u]\n", cq->id); >> >> spin_lock_init(&cq->lock); > Speaking for the siw driver only, these two changes are looking > good to me. What is needed is a pseudo-random number, not > to easy to guess for the application. get_random_u32() provides that. > > Thanks! > > Reviewed-by: Bernard Metzler Just so you know, get_random_u32() is still crypto-strength: it is unguessable even to a resourceful attacker with access to large amounts of other get_random_u32() output. prandom_u32() is much cheaper, but although well seeded and distributed (so equally resistant to accidental collisions), *is* guessable if someone really wants to work at it. Many intra-machine networks (like infiniband) are specifically not designed to be robust in the face of malicious actors on the network. A random transaction ID is sent in the clear, and a malicious actor wanting to interfere could simply copy it. In such cases, there's no need for crypto-grade numbers, because the network already assumes that nobody's actively trying to create collisions. You seem to be saying that the siw driver could use prandom_u32().