Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp984063rwb; Fri, 23 Sep 2022 06:51:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7k0VNxPrUFNLyAb+8MkIugtTkiWTvh5PEpbDRCdF4cHEzUvFCVhOn3v5hbfXDzHayOILb7 X-Received: by 2002:a17:907:2672:b0:780:8bb5:25a3 with SMTP id ci18-20020a170907267200b007808bb525a3mr6904953ejc.281.1663941063230; Fri, 23 Sep 2022 06:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663941063; cv=none; d=google.com; s=arc-20160816; b=UDzbnro7GH0dlkT+Sdoxkbmeqn7HYrCSc08Fr2zm7o/gHQs2M0mRLRASZC7CGMCsGp iklfl7qpEMAm+kfAQ6xA2AIWXH5ckguWM5TERpJbcH3lTVxLjt3AAZwM4SoVEI0imIld 2axJnSfphO5lZoqkaPGxXNnBTE/aYWMZFZsqJ7QGZuWdwW3ufywVJktwDH3T+1Ak5+jF fxRNNfTFpHvM2MDqihgrtKaSLoXJiB89UzPPr28torMAZQ67HXrN1+cIlPyo8rAYTDsX DnMaZaqmaJvYQstOIsYJiGuD/bwvUOXfNz8lKcaM/m7GEu2L5MlOjMQa896BCopppRw9 LX6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=TIxUcLFewKUrI9Gr/MmE+wKa02a1LZQqMu2jG1Cimoc=; b=vMW1ATjnQ0jTZsERGcyBr8oGQK/VVD4T4zDdTwph3ICZihnX4iYUWOHubf1HZrHdR3 LGVF6wyUJ3QrWjVRlaQD9ojlbBJjoN7yHKPSgelZ/cQuzvvdV7/HB+G6iHbVovYVU9Wc EAClbp/StNHnHpZMGR/L/ss8uecmTt2/mV4kqeB7kLUIWS19dgoRbQXuB50F9GVsldJ0 n2e3Xhh+JXpT/fyMHk5JtnZbKnHghGh6Jm4mOeaX+VS8243s/Q7fQfihav5RuNuFBUiJ Vt4ZLY0SLdiLFchUrwLN6qAUF4YKFg1pKMrPWgy7SFZQx37zQ5yMkbMPxq8Ahd7SszES M5kQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hh5-20020a170906a94500b0077cb9bc7984si6629578ejb.181.2022.09.23.06.50.36; Fri, 23 Sep 2022 06:51:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231623AbiIWMun (ORCPT + 99 others); Fri, 23 Sep 2022 08:50:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231264AbiIWMuk (ORCPT ); Fri, 23 Sep 2022 08:50:40 -0400 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDFBB12CC9C for ; Fri, 23 Sep 2022 05:50:34 -0700 (PDT) Received: by mail-qt1-f179.google.com with SMTP id g23so8314867qtu.2 for ; Fri, 23 Sep 2022 05:50:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=TIxUcLFewKUrI9Gr/MmE+wKa02a1LZQqMu2jG1Cimoc=; b=CT2S3S+Krlt4PUddaN/GIloLTXVkmAEvIGKC2nSXSlkKuoxUpTN9fJoqXdE9xyC8Wc hLtpmfG4sWirKWvUZgxi/4kGQPTkhNSFmwQUsug7J8UW0l02e1ao7/2SU+SyOez4gD5f jlJAP2ml5bMofv8tShPbZpnOjV8eNUJenE/qlOmQ/AoDV02Xo9tseEkWjiczYOq/BRx+ 0VIgzfvRBqok6XtvAtWBgUajVRCX268h0lDq/GFw8IFhonHqn29EV8MDVn4f0Y0O29d8 OjN9ccpv8mjGL6WQyhamXwv9Wflc3F8tnje0GP/V0rMdYL7XrAppdk2dFShRIULBOuGo 9sgA== X-Gm-Message-State: ACrzQf2f6U8516mNUZdgG0yliRq9bgn9hh9wToaBUsDEZ68MF/DI77GQ YQTXumpSm92XL8mSiBAqGgRwFq8icr8PQQ== X-Received: by 2002:ac8:59d4:0:b0:35b:b9a4:8ff8 with SMTP id f20-20020ac859d4000000b0035bb9a48ff8mr6824019qtf.614.1663937433086; Fri, 23 Sep 2022 05:50:33 -0700 (PDT) Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com. [209.85.219.169]) by smtp.gmail.com with ESMTPSA id c6-20020a05620a268600b006cbb8ca04f8sm6262873qkp.40.2022.09.23.05.50.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Sep 2022 05:50:32 -0700 (PDT) Received: by mail-yb1-f169.google.com with SMTP id e81so16908157ybb.13 for ; Fri, 23 Sep 2022 05:50:32 -0700 (PDT) X-Received: by 2002:a25:8e84:0:b0:696:466c:baa with SMTP id q4-20020a258e84000000b00696466c0baamr8477549ybl.604.1663937432351; Fri, 23 Sep 2022 05:50:32 -0700 (PDT) MIME-Version: 1.0 References: <20220921185208.3549140-1-Jason@zx2c4.com> <20220921185208.3549140-2-Jason@zx2c4.com> In-Reply-To: From: Geert Uytterhoeven Date: Fri, 23 Sep 2022 14:50:21 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] m68k: virt: generate new RNG seed on reboot To: "Jason A. Donenfeld" Cc: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, Laurent Vivier Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jason, On Fri, Sep 23, 2022 at 2:26 PM Jason A. Donenfeld wrote: > On Fri, Sep 23, 2022 at 2:23 PM Geert Uytterhoeven wrote: > > > > > + if (rng_seed_record && rng_seed_record->size > sizeof(*rng_seed_record) + 2) { > > > > > + u16 len = rng_seed_record->size - sizeof(*rng_seed_record) - 2; > > > > > + get_random_bytes((u8 *)rng_seed_record->data + 2, len); > > > > > + *(u16 *)rng_seed_record->data = len; > > > > Storing the length should use the proper cpu_to_be16 accessor. > > Okay, I'll do that for v2. > > (Simply out of curiosity, why? Isn't m68k always big endian and this > is arch/ code?) Yes it is. But virt_parse_bootinfo() below already uses the right accessor. BTW, I guess people thought the same about PowerPC? Although I agree the probability of someone creating a little-endian m68k clone in an FPGA or SkyWater project and trying to run Linux on it quite low ;-) > > > The way I tested this is by having my initramfs just call > > > `reboot(RB_AUTOBOOT);`, and having add_bootloader_randomness() print > > > its contents to the console. I checked that it was both present and > > > different every time. > > > > Are you sure the new kernel did receive the same randomness as prepared > > by get_random_bytes()? I would expect it to just reboot into qemu, > > reload the kernel from disk, and recreate a new bootinfo from scratch, > > including generating a new random seed. > > Yes I'm sure. Without this patch, the new kernel sees the zeroed state. That's interesting. So QEMU preserves the old bootinfo, which is AFAIK not guaranteed to be still available (that's why I added save_bootinfo()). Perhaps that works because only memory starting from a rounded-up value of _end will be used, and you're just lucky? I'm wondering what else it preserves. It sure has to reload the kernel image, as at least the data section will no longer contain the initialization values after a reboot... Laurent? Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds