Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2185651rwn; Fri, 16 Sep 2022 06:58:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MQRH31V/yB++9EzD6KQqxnQunWtCCPMSIlkZgzNRSs8+kc6bdhrfHNtFuABYVcTm+7HHZ X-Received: by 2002:a17:907:7b8d:b0:77d:a8de:21c9 with SMTP id ne13-20020a1709077b8d00b0077da8de21c9mr3720871ejc.204.1663336685420; Fri, 16 Sep 2022 06:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663336685; cv=none; d=google.com; s=arc-20160816; b=zxVyJsgmFSGM1dXv1DtOAYEadLXy5QK5QJnrlAtLtBPYWUqDzzXHwQZbAvpDm18ppG fnLWUe3F9DOtSqO2iBI1WEjmvFtVTWmlAIzs9wcvDuF3/YM9/rj/wc8UQ2L9QCD3xRK6 SJRG9FTZ9huPYQWAq6zSQuRda/D80G/zh8fYwm1/sKqUkKCaFV7NRX9xSbb8KPsiDZId zmnwoPQ/gkRI3MxEuQSwWdMrh+Z+I2iweDakDHv08nMy40J8VrTRWAzl0RtM7n4YyS1X +zMPqbgaZCRQjvV29LnKyCz0EHUYgnMlDuuNt9mkjnoZRoRKoACmZeRltHSLR6d9LhRv H5SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KgBYor1Htf/vgvjRNDzZz0OSBXCS1g2qA2z8v/wMsdQ=; b=redVj3YjGLFImmu0xIxmsa2RO64DgfOkn10hfysYr4G9bgp5T+oU2taJp9V54eenwv icGG121g0sch8vOCPnE8WjaQctr8LJDvRq9lpEsHxwjTsOBmSNigE1jhj5UVL60MQR68 fYOgYkhQUhJs+InzZzKLQ5S5ZBfFTYUKRFFb+ifVQ8ygeRQ4aTKPTnuIiFdXFx45f8nm Exmy00e6XeIomfo52RgN+08Ven8/Ug6E+P3PD/rkN5IvsV2yW9ZlkrzA1E1DqDVhOvMv 3pBdom7nrEa8c/kA9np49g6f343HKVWP+xjAUsf5CLfMcZzGQa2xbFs5mtnnMd+S5NW1 zwcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=duV1RS8T; 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; 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 f11-20020a056402194b00b00451f43411a3si2119316edz.255.2022.09.16.06.57.39; Fri, 16 Sep 2022 06:58:05 -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; dkim=pass header.i=@chromium.org header.s=google header.b=duV1RS8T; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbiIPNby (ORCPT + 99 others); Fri, 16 Sep 2022 09:31:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbiIPNbu (ORCPT ); Fri, 16 Sep 2022 09:31:50 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8988F92F52 for ; Fri, 16 Sep 2022 06:31:49 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so25677966pjq.3 for ; Fri, 16 Sep 2022 06:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=KgBYor1Htf/vgvjRNDzZz0OSBXCS1g2qA2z8v/wMsdQ=; b=duV1RS8TM2EGZ6omH4ubcEo80bgH2kyZd5qyDXZXa3PhTBC8+KG+to4g1PhL106fEN 2Ce5cVmi6xX3gbz38EE8qox07VoXA4Av+FZJ80wWOZ6UV6i5CZqldo0nA14gKiagdGWT bAcrvdodiN1cfiDHSyxQittJvsK3g6HcGnXF8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=KgBYor1Htf/vgvjRNDzZz0OSBXCS1g2qA2z8v/wMsdQ=; b=kwyTurIz4gHXiJ7dc1RYWx0sKRgSP0QcQLK7K2/rapFIOSzQoxzxD9C82Zg0Yq+dlE CfbqdpvpfgtDIVR9UqTsneyHlkkRLe21OwI8QBloPfkHg+WJf86xxlEedKEATrdPz+Cg 5hmuYK8GDPtGYC6B7ozOivY5ICP3p5A130J9wGAd5Nd9pefKz6StlV6jg5dTJDNaHPwu 3gCsPLetr5rYaTHT9CxVpI29e7SZP/oAmF7AD46RTj7bTvbmgFudBNOrRx/KtLIjCUer UAwjf5WV217gzxjxwnkAvFreVXIuaZL5UZw5cNWcR+UIEfrAglBdKxqZGguWw/l9afCt KnTQ== X-Gm-Message-State: ACrzQf1Q1OT9l8YvvVtN2n3i/UdsEyo/ok+n4bPtBxrNV+/YM0e/txWk ZqHvlremjMy2evhbLucdvgoBiA== X-Received: by 2002:a17:903:110f:b0:178:8756:6e5e with SMTP id n15-20020a170903110f00b0017887566e5emr938412plh.12.1663335108874; Fri, 16 Sep 2022 06:31:48 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id s15-20020a63524f000000b00434acf7a05fsm13723090pgl.45.2022.09.16.06.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 06:31:46 -0700 (PDT) Date: Fri, 16 Sep 2022 06:31:45 -0700 From: Kees Cook To: Dan Carpenter Cc: "Gustavo A. R. Silva" , Peter Rosin , Wolfram Sang , "Gustavo A. R. Silva" , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] i2c: mux: harden i2c_mux_alloc() against integer overflows Message-ID: <202209160630.CF7AE9708D@keescook> References: <202209160101.2A240E9@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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=ham 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 On Fri, Sep 16, 2022 at 11:23:25AM +0300, Dan Carpenter wrote: > [...] > net/ipv6/mcast.c:450 ip6_mc_source() saving 'size_add' to type 'int' Interesting! Are you able to report the consumer? e.g. I think a bunch of these would be fixed by: diff --git a/net/core/sock.c b/net/core/sock.c index 4cb957d934a2..f004c4d411e3 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2552,10 +2552,11 @@ struct sk_buff *sock_omalloc(struct sock *sk, unsigned long size, /* * Allocate a memory block from the socket's option memory buffer. */ -void *sock_kmalloc(struct sock *sk, int size, gfp_t priority) +void *sock_kmalloc(struct sock *sk, size_t size, gfp_t priority) { - if ((unsigned int)size <= sysctl_optmem_max && - atomic_read(&sk->sk_omem_alloc) + size < sysctl_optmem_max) { + if (size > INT_MAX || size > sysctl_optmem_max) + return NULL; + if (atomic_read(&sk->sk_omem_alloc) < sysctl_optmem_max - size) { void *mem; /* First do the add, to avoid the race if kmalloc * might sleep. -- Kees Cook