Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3907515rwb; Tue, 8 Nov 2022 09:39:36 -0800 (PST) X-Google-Smtp-Source: AMsMyM6Sy3wrJ9iNO0OpDnycOJDCMJXJx0YAvv/H2LEWWQQGR6aL8ikdVvdzx0JhPF3cYoEFtaVw X-Received: by 2002:a17:906:9746:b0:78e:11cc:3bb3 with SMTP id o6-20020a170906974600b0078e11cc3bb3mr52326201ejy.379.1667929176335; Tue, 08 Nov 2022 09:39:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667929176; cv=none; d=google.com; s=arc-20160816; b=qzMbANI24PpSyioeNmAqtmzcmCxUJx7C/mvnZBbPyDbzSQjE9UEhJWOyizYgLVUO5U t1jyVe6f0jf0qaEd3QyHOKO0nzA3ny8EJH0FcCS93iH9eUV+vXJ0GSqwlmJTw4VT3xKT OKTJMTdHZnxfsr48o6a/OaGBCLRVath7TNrRS2u5m7qNt/aLZxeRqaDGkDwWLzm4RznB K5MzIY+dE/9+3rRMweC70fDCcz+HSXlZdpBepOHHAi8NRZE0Kicwpvg21XkiyKbWb0Ts ac/4Mja4hwbW7gVkCpTQ7NQHp8OcW2bCz1seFzeJdyQK8jcxqsl6SdRqrETY7KVyyyw2 bmSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:date:from:dkim-signature; bh=5FVCMfeiZLHWKmFh+FqLYpaeqKRAlifxYJVyfWqZqZk=; b=U046ZW7/k3MgAGwKM9TthTnKUIiZVz63ycjbUOlbE3Ko9VRc1BME1vu35o374CBsQI bcyLcnMJ/m8vsQSugsxpm4TXr/+0+oBYj+HKqeQ0f31VlXRcwbvzD+XKW8Pl0r69ixNj 0mAci1EUQnqouR+A5UwL3I3Ba+LYxIollAs2kgEA7L+iHpAXN2Faqst45J/4pnE+B1om 8UFp+KiqS2+4DRL/TnfCFRIquXHPKinbOdrlpRJPfvMKh1FKsexypcO1dkW0ptgubYFT x3vi+rBqzuEN7/cwMT7PTCs0Q/hFZ7rIcJOCdHXiQLgO2JxIiXbf+27Ij8J0L+IsLtpG qrSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TcXV7SAA; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m14-20020a50ef0e000000b00457e6752422si11678894eds.189.2022.11.08.09.39.03; Tue, 08 Nov 2022 09:39:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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; dkim=pass header.i=@chromium.org header.s=google header.b=TcXV7SAA; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234218AbiKHR3c (ORCPT + 99 others); Tue, 8 Nov 2022 12:29:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234364AbiKHR3b (ORCPT ); Tue, 8 Nov 2022 12:29:31 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 197DF20996 for ; Tue, 8 Nov 2022 09:29:29 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id b62so14008767pgc.0 for ; Tue, 08 Nov 2022 09:29:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-disposition:mime-version:message-id:subject:cc:to:date:from :from:to:cc:subject:date:message-id:reply-to; bh=5FVCMfeiZLHWKmFh+FqLYpaeqKRAlifxYJVyfWqZqZk=; b=TcXV7SAA0xvPOfmvHzBUPQnugs/YasXJ6whZHnJ7gjDDFxRs64xayMIqnUph3gVGuM Vk7oED5XLpqF8JjKACQYtGGBJcsD1icZ4+7PfBZj5p814CvweAwkXr8kDdYGLXWjSTH8 mSeioFi2Rcl6sCMT060qYV7CiWku9QUPYtbzw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5FVCMfeiZLHWKmFh+FqLYpaeqKRAlifxYJVyfWqZqZk=; b=mY6zgBjgZ7jjtWLLwfbnwXUAAQdSvpLim7TeQJEYD7PdCgQHoM8uI1Qog/DueUIMGV p2vRioCJmih+Og53Z+uddRWSUKl5U/6MpUjeiOhFKTdqCmRk6sYzgKZP/Xc7Sho5jE9J QgcGPjdYDY8v/2hnI0R7zZ6wNG1mt05qGl/ZbozUPGU7xY59tZ6NsMxqE/M1yZvraoTz eonbpkNBSmEZBDjETZUm44Xm9QN73ZtusqC/Sr9ZklgJTpE/uFsqXmW5gXXlRr7GqrBa elhjZ0h2WhmJDaKaR/X5wsSVRC0Gt7wg2B8wwGBogdaaos19Ad0N5VGm+avz9joKyRpT PP4g== X-Gm-Message-State: ACrzQf1tEExG7lCDKomt60rh9Faj6Re1XsTz1X9agF2Zd9yaQBZwRtzt cOp1w5A3+jiI+nhN0Nb5c4OFvQ== X-Received: by 2002:a63:6909:0:b0:41c:9f4f:a63c with SMTP id e9-20020a636909000000b0041c9f4fa63cmr50519040pgc.76.1667928568583; Tue, 08 Nov 2022 09:29:28 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id b191-20020a621bc8000000b0056bb0357f5bsm6631443pfb.192.2022.11.08.09.29.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 09:29:28 -0800 (PST) From: coverity-bot X-Google-Original-From: coverity-bot Date: Tue, 8 Nov 2022 09:29:27 -0800 To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, Theodore Ts'o , Dominik Brodowski , "Jason A. Donenfeld" , Olivia Mackall , linux-crypto@vger.kernel.org, Herbert Xu , "Gustavo A. R. Silva" , linux-next@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Coverity: add_early_randomness(): Integer handling issues Message-ID: <202211080929.F5B344C9F@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-crypto@vger.kernel.org Hello! This is an experimental semi-automated report about issues detected by Coverity from a scan of next-20221108 as part of the linux-next scan project: https://scan.coverity.com/projects/linux-next-weekly-scan You're getting this email because you were associated with the identified lines of code (noted below) that were touched by commits: Mon Nov 7 12:47:57 2022 +0100 e0a37003ff0b ("hw_random: use add_hwgenerator_randomness() for early entropy") Coverity reported the following: *** CID 1527234: Integer handling issues (SIGN_EXTENSION) drivers/char/hw_random/core.c:73 in add_early_randomness() 67 int bytes_read; 68 69 mutex_lock(&reading_mutex); 70 bytes_read = rng_get_data(rng, rng_fillbuf, 32, 0); 71 mutex_unlock(&reading_mutex); 72 if (bytes_read > 0) { vvv CID 1527234: Integer handling issues (SIGN_EXTENSION) vvv Suspicious implicit sign extension: "rng->quality" with type "unsigned short" (16 bits, unsigned) is promoted in "bytes_read * 8 * rng->quality / 1024" to type "int" (32 bits, signed), then sign-extended to type "unsigned long" (64 bits, unsigned). If "bytes_read * 8 * rng->quality / 1024" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1. 73 size_t entropy = bytes_read * 8 * rng->quality / 1024; 74 add_hwgenerator_randomness(rng_fillbuf, bytes_read, entropy, false); 75 } 76 } 77 78 static inline void cleanup_rng(struct kref *kref) If this is a false positive, please let us know so we can mark it as such, or teach the Coverity rules to be smarter. If not, please make sure fixes get into linux-next. :) For patches fixing this, please include these lines (but double-check the "Fixes" first): Reported-by: coverity-bot Addresses-Coverity-ID: 1527234 ("Integer handling issues") Fixes: e0a37003ff0b ("hw_random: use add_hwgenerator_randomness() for early entropy") Thanks for your attention! -- Coverity-bot