Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4537340rdb; Fri, 15 Sep 2023 05:30:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFt/UzkPzcBnodzUp7N75AvSf0DC2q3ATfwv3j3veK5yIGLBnMHDTKPNWSI7c4pj/Rxm8zr X-Received: by 2002:a17:90b:88f:b0:271:9e59:df28 with SMTP id bj15-20020a17090b088f00b002719e59df28mr1174294pjb.29.1694781039008; Fri, 15 Sep 2023 05:30:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694781038; cv=none; d=google.com; s=arc-20160816; b=I4RSx0egnq6shjASknyuR+gnYOiYinq6ccWhaVuqnbvsOiJF/+7m9Ba/4CV5uJoXmV JNqqttEItm8OTftKP0JLPOm3+kZhfRIm2kfJI4RSps4YcBQvCFHRekbT9hwrL8VytFz1 UOd/4SspCCGD2nnjktKvoA4GcArnZM701hAb8xMWSgCRd0yaTQKBK61C7wnZYWSIDPoH ZJuGRjoNBeQ5hvOsq/PWPHykQGcJsMe75/ze5uwwqa1k5klq6Ok5g+ltou1dLoGb45WI genrZPnYwxRrnsLENxh4NCxHx9fSNH0Z+BOeIaR8d2XPvW8R01BnLlzFTu8qcXc3hN1K e/ow== 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:from:date:dkim-signature; bh=KWUTTgPAUvTLzKrLP6oc3d68vCkhgUGZ2fi5Q9n95I4=; fh=9C+24Lnk88V0d/4vSf8OkHmPatZJ8VM1TUZ6aG2w/bk=; b=H7wdSY986+8tqSFWkwKvEJDPBcSRW7wFdm4alsv1jjbPCEhW7/1p2f2+kz0dbsyL9T XRJNIn8vj1Cenl8JutqL2S0QNzkopJo40hajqLN2qvDLV26QcAA2OQNmtv8LsstJDW2X y6gDwgdo+yzN3wh0YbAqMxVQoNhr1Eac6mbe/zhQbNOCQkAKVyW5nv2hqXVUltgwWJMv 8LM1miZlMXdEIQTVhqf+t/dOi0Gufp6Z8x3aJ9YRE40ku5QUPAMnZicRR/JkV+DR9y0w ze9lxbJ45u6xkd6Bv4JXzR95LfoODrV7NGL1jGtyoMw+2r4j7qYiLLkhHXy2nrlP0SWL 1iJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WowTx6jZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bg26-20020a056a02011a00b00564bdf6958fsi3140838pgb.649.2023.09.15.05.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:30:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WowTx6jZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 33ECC8038F8E; Fri, 15 Sep 2023 02:56:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233894AbjIOJ4y (ORCPT + 99 others); Fri, 15 Sep 2023 05:56:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233880AbjIOJ4x (ORCPT ); Fri, 15 Sep 2023 05:56:53 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11C601720 for ; Fri, 15 Sep 2023 02:56:45 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9a9f139cd94so260479866b.2 for ; Fri, 15 Sep 2023 02:56:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694771770; x=1695376570; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=KWUTTgPAUvTLzKrLP6oc3d68vCkhgUGZ2fi5Q9n95I4=; b=WowTx6jZZo3Ve9HkV6smrhkacANuBZvPpHBEHmEH7eMzDtvJh1HCEUQcBY/H8PtTSH OO30c6jYWc3kLvkruHmSsyGkiT8zuR0dZRIebHSlH1UuFm2bN6fV9H7Sx3Dej9KBXkZd jTzNXAfREkkCygD6AJqB36SRbKM8uuXyjtw4S2nBT39JYRefm7HuDyLFYHglr1u/MZz4 MZBKpwbyZE71C9iaoW9U1a69YoTpw2oEuja3Y9IEI7kY3+HDoSoTw1jben+pT7+IZWqw 6iAwaV7AWv5SIE8uWsDwxNAi9gsWafgC3titOgyB4GjiWMSnb6NJvmr4J1wAcqH8RjTa IujQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694771770; x=1695376570; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KWUTTgPAUvTLzKrLP6oc3d68vCkhgUGZ2fi5Q9n95I4=; b=hV4yrP+3by8F+JxcuNgzprKK2csrhMze0ncaz/KzsdOG8BB1BUwEWfsyiSsApaCMxR yyVLkmx4oFntD7z3s4EEtfGt8Y4iqYzqukYwO9vgt1ovrOWdYIs/OcexzdBDPTuoQl06 1QmqDeaD2/f1Usng79d0i4//Pv7QpkntpyVzpbtdXWY3GbTm06dFGcOy0BkTF2SsS7xT Plg1eF1lRK6Sf5wd22U8WrCh9W6/yv2120E+2pk5lSNbyxyDEXlxCKdS6XCotU0Pwd/h nxgrqFhhyzXe9cK1FvL/g14QtXneBXnY1UB8pPCnpfzBFz0vr/PwPRfXn7rH1J8Bndbk VFiQ== X-Gm-Message-State: AOJu0YwsBd/xtu+uFF1nrMxwnOkPq59EwhWKgrA/ZkHOt40AcQSIDb3y fJYLrQv+m7MleoICLGirrg== X-Received: by 2002:a17:906:3112:b0:9a5:a701:2b90 with SMTP id 18-20020a170906311200b009a5a7012b90mr993708ejx.40.1694771769552; Fri, 15 Sep 2023 02:56:09 -0700 (PDT) Received: from p183 ([46.53.253.54]) by smtp.gmail.com with ESMTPSA id e10-20020a170906080a00b00997d76981e0sm2180256ejd.208.2023.09.15.02.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 02:56:08 -0700 (PDT) Date: Fri, 15 Sep 2023 12:56:07 +0300 From: Alexey Dobriyan To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski , Linus Walleij , torvalds@linux-foundation.org, akpm@linux-foundation.org Subject: Buggy __free(kfree) usage pattern already in tree Message-ID: <07c32bf1-6c1a-49d9-b97d-f0ae4a2b42ab@p183> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 15 Sep 2023 02:56:56 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 lipwig.vger.email __free() got some usage and some of the usage is buggy: 832 static struct fwnode_handle * 833 gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank, 834 struct fwnode_handle *parent) 835 { 838 char **line_names __free(kfree) = NULL; // returns NULL or ERR_PTR(-E) 848 line_names = gpio_sim_make_line_names(bank, &line_names_size); 849 if (IS_ERR(line_names)) 850 return ERR_CAST(line_names); This pattern will result in calling kfree() on error value. And there are no compiler or sparse checking these things. This test module demonstrates the landmine: [ 812.981089] ------------[ cut here ]------------ [ 812.981597] WARNING: CPU: 0 PID: 1326 at mm/slab_common.c:991 free_large_kmalloc+0x50/0x80 [ 813.013266] ---[ end trace 0000000000000000 ]--- [ 813.013800] object pointer: 0xfffffffffffffff4 #include #include #include struct S { int x; }; static struct S* f(void) { struct S* s = kmalloc(sizeof(struct S), GFP_KERNEL); s = NULL; return s ?: ERR_PTR(-ENOMEM); } static int __init xxx_module_init(void) { struct S *s __free(kfree) = NULL; s = f(); if (IS_ERR(s)) { return PTR_ERR(s); } return 0; } static void __exit xxx_module_exit(void) { } module_init(xxx_module_init); module_exit(xxx_module_exit); MODULE_LICENSE("GPL");