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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C351DC54EE9 for ; Tue, 13 Sep 2022 05:27:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 581118D0001; Tue, 13 Sep 2022 01:27:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 50A0A6B0073; Tue, 13 Sep 2022 01:27:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AA328D0001; Tue, 13 Sep 2022 01:27:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 245EE6B0072 for ; Tue, 13 Sep 2022 01:27:01 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0AD5540E61 for ; Tue, 13 Sep 2022 05:27:01 +0000 (UTC) X-FDA: 79905928242.15.6533452 Received: from smtp.smtpout.orange.fr (smtp03.smtpout.orange.fr [80.12.242.125]) by imf09.hostedemail.com (Postfix) with ESMTP id 6794F1400B1 for ; Tue, 13 Sep 2022 05:26:59 +0000 (UTC) Received: from [192.168.1.18] ([90.11.190.129]) by smtp.orange.fr with ESMTPA id XyRkouUZN3VQxXyRko1dbL; Tue, 13 Sep 2022 07:26:58 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 13 Sep 2022 07:26:58 +0200 X-ME-IP: 90.11.190.129 Message-ID: <4b87891d-b475-0ad6-db36-a9c1f334c785@wanadoo.fr> Date: Tue, 13 Sep 2022 07:26:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] mm/slub: fix to return errno if kmalloc() fails Content-Language: en-US To: Chao Yu , "Vlastimil Babka (SUSE)" , linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Chao Yu , muchun.song@linux.dev References: <20220830141009.150075-1-chao@kernel.org> <2025305d-16db-abdf-6cd3-1fb93371c2b4@wanadoo.fr> From: Marion & Christophe JAILLET In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663046819; a=rsa-sha256; cv=none; b=Xp6gWj9XNF3/PtA/7nDLxEVoEm660QPNHviTzpGWIkeH56ZzIG+RKwyC2NyrkwQ+9jVqiT hpzKNJWQWJu0ok0QgdQhC3dYg7qPRNKjMNzU5XQaLI97eUL7ZJBKF2kSyGm5wF/EjnrSdG olpPIvT4ndcdcevyWcLXLWylh5JV8Os= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.125 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663046819; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wGk7n2F1w60X+fA6nfchVxYm8/Efkm5od+gV3INsXnw=; b=l9RXxSo9o1oYXdFb5L9hnaes5VNDPx2shOVAfgtv9S5kCEjwmr0jJZ079zTJ3HtKt3eRvi qLBhgL+vuRYuPWBSGnun1JWauAKuj8qv23v/zT+MPKeVM24MSjvprhHj4gJYAo8gjjN1pp m3PNc6YmSbYQAtfoLseWnQ/1HGN2Dgs= X-Stat-Signature: tgtqmor71tbj6ux64ikaso5yeoskgyis X-Rspamd-Queue-Id: 6794F1400B1 Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.125 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1663046819-425984 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Le 13/09/2022 à 05:42, Chao Yu a écrit : > On 2022/9/10 0:47, Christophe JAILLET wrote: >> Le 30/08/2022 à 16:10, Chao Yu a écrit : >>> From: Chao Yu >>> >>> In create_unique_id(), kmalloc(, GFP_KERNEL) can fail due to >>> out-of-memory, if it fails, return errno correctly rather than >>> triggering panic via BUG_ON(); >>> >>> kernel BUG at mm/slub.c:5893! >>> Internal error: Oops - BUG: 0 [#1] PREEMPT SMP >>> >>> Call trace: [...] >>> >>> Cc: >>> Reported-by: syzbot+81684812ea68216e08c5@syzkaller.appspotmail.com >>> Signed-off-by: Chao Yu >>> --- >>>   mm/slub.c | 5 ++++- >>>   1 file changed, 4 insertions(+), 1 deletion(-) >>> >>> diff --git a/mm/slub.c b/mm/slub.c >>> index 862dbd9af4f5..e6f3727b9ad2 100644 >>> --- a/mm/slub.c >>> +++ b/mm/slub.c >>> @@ -5890,7 +5890,8 @@ static char *create_unique_id(struct >>> kmem_cache *s) >>>       char *name = kmalloc(ID_STR_LENGTH, GFP_KERNEL); >> >> Hi, >> >> looks that ID_STR_LENGTH could even be reduced to 32 or 16. >> >> The 2nd BUG_ON at the end of the function could certainly be just >> removed as well or remplaced by a: >>         if (p > name + ID_STR_LENGTH - 1) { >>          kfree(name); >>          return -E; >>      } > > Hi Christophe, Vlastimil, > > Should I include this in v3? or may be in another patch? Hi, My own preference would be for 3 patches. Yours, as-is. It fixes a specific issue spotted by syzbot. Another one for removing a BUG_ON() (that, IIUC can't happen!) Mostly a clean-up or a good practice in order to remove BUG_ON() from the kernel we it can be handled another way. Eventually a 3rd one for reducing ID_STR_LENGTH. I guess that it is safe to reduce it to 32 or 16, but the impact on RL would be so small, that I wonder if it worth proposing it. Just my 2c, CJ > > Thanks, > >> >> Just my 2c, >> >> CJ >> >>>       char *p = name; >>> -    BUG_ON(!name); >>> +    if (!name) >>> +        return ERR_PTR(-ENOMEM); >>>       *p++ = ':'; >>>       /* >>> @@ -5948,6 +5949,8 @@ static int sysfs_slab_add(struct kmem_cache *s) >>>            * for the symlinks. >>>            */ >>>           name = create_unique_id(s); >>> +        if (IS_ERR(name)) >>> +            return PTR_ERR(name); >>>       } >>>       s->kobj.kset = kset; >>