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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F24CC6FA82 for ; Sat, 10 Sep 2022 20:30:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbiIJUaD (ORCPT ); Sat, 10 Sep 2022 16:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbiIJUaA (ORCPT ); Sat, 10 Sep 2022 16:30:00 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E147818E30 for ; Sat, 10 Sep 2022 13:29:59 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id b21so4909288plz.7 for ; Sat, 10 Sep 2022 13:29:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=3OB7lD9IsLsjTT/Zgb3BM7QAVB4ydEQ1DyuFepEmj3Y=; b=TVDUx2hQxcx9YajRsRQPfI7VgRkyHwrlZO7cYvz2u9rl2snFvvYnJDWLoDS/05E4wo X9wuFpyUvGUltIm1E7ICSuu9RUXxc8IZuhn5L+JsWkrR4NZOImmhUW4EP0T+uugqNzrk pj0oORzIA08UTdpvjwXpB1Z0OqsgbJBNXYJFmLLAeWia2raNI40zAiXN0D+xsp9QZ5p/ K72iwJKgPs8GEx00FnC5uf6BRvwUqTvl9SVqVcOgBA0a73PvMA7ltX3imPKfo6GFVKaa pdS8B8DF0g0qghIYChRm/Wx6drgajTXiptCZ4zF/uCxPD6xwQ1H2w7ARfL8jIJgxK0sH iRPQ== 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=3OB7lD9IsLsjTT/Zgb3BM7QAVB4ydEQ1DyuFepEmj3Y=; b=4Vj7BzOLzf7A33JQvSvFjq7INeQ4HV6Ux0dNkA9WB7y8wbSyCt9h5teEyQwHjf5ENH o9Bngn+uEkwiCSGnZ+n7j2Kyze4+wmdv3Dl8wllq0sMlu3xWo9r7pHFacpMC21BP5qtj vZBEc7+8/XEiHrPzIj2vewS7PeXVWFWpQP0MZfqWy+dDG3a40Kqu1pmCRL3rtqEAVZMC h9XuxDgMD2UHvLqAZpiEA+310oDKghPaDtdB7Nt6u+UArOe+liJd2t5mkFCJLgoD7MWF ohF5aM37zyQYV5qXev7Xna4JM6nRPIoFQwtXODyaJdDGoKJuJR2xMBMqeyzjLkV+J17u 1Tng== X-Gm-Message-State: ACgBeo1C/21bTWeIWAR2ATyYbiuTGUbNm4mXFVIPIcYKm34CXemHosuY 3dhbnSpRKiXKFxnUD19/uXhmYm61JjyUfNPjlu9WqQ== X-Google-Smtp-Source: AA6agR4zLIlTlZe/0RVmVx49oJdfG1mYQvJFbdLFr1vOKxT2ZifJrd7mtQ4FR3csW9F0zYw8Ux112gEewoiKIAkMYcM= X-Received: by 2002:a17:902:d505:b0:176:96f1:2e61 with SMTP id b5-20020a170902d50500b0017696f12e61mr19227932plg.73.1662841799269; Sat, 10 Sep 2022 13:29:59 -0700 (PDT) MIME-Version: 1.0 References: <0000000000005ed86405e846585a@google.com> <20220910020633.2620505-1-eadavis@sina.com> In-Reply-To: <20220910020633.2620505-1-eadavis@sina.com> From: Stanislav Fomichev Date: Sat, 10 Sep 2022 13:29:47 -0700 Message-ID: Subject: Re: [PATCH] kernel/bpf: htab_map_alloc() exit by free_map_locked logic issue To: eadavis@sina.com Cc: syzbot+5d1da78b375c3b5e6c2b@syzkaller.appspotmail.com, andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, martin.lau@linux.dev, netdev@vger.kernel.org, song@kernel.org, syzkaller-bugs@googlegroups.com, yhs@fb.com, eadivs Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 9, 2022 at 7:07 PM wrote: > > From: eadivs > > syzbot is reporting WARNING: ODEBUG bug in htab_map_alloc(), the > loop exits without reaching length HASHTAB_MAP_LOCK_COUNT, and > the loop continues HASHTAB_MAP_LOCK_COUNT times in label > free_map_locked. Please use [PATCH bpf] vs [PATCH bpf-next] in subject to indicate which tree you're targeting. Also, it seems your email hasn't reached the mailing list for some reason. Are you sure that the issue is due to HASHTAB_MAP_LOCK_COUNT? The code seems fine as is; unconditionally calling free on NULL shouldn't be an issue. htab_map_alloc+0xc76/0x1620 kernel/bpf/hashtab.c:632 Which, if I'm looking at the function is: bpf_map_area_free(htab); ? > Link: https://syzkaller.appspot.com/bug?extid=5d1da78b375c3b5e6c2b > Reported-by: syzbot+5d1da78b375c3b5e6c2b@syzkaller.appspotmail.com > Signed-off-by: eadivs > --- > kernel/bpf/hashtab.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c > index 65877967f414..f5381e1c00a6 100644 > --- a/kernel/bpf/hashtab.c > +++ b/kernel/bpf/hashtab.c > @@ -473,7 +473,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) > bool percpu_lru = (attr->map_flags & BPF_F_NO_COMMON_LRU); > bool prealloc = !(attr->map_flags & BPF_F_NO_PREALLOC); > struct bpf_htab *htab; > - int err, i; > + int err, i, j = HASHTAB_MAP_LOCK_COUNT; > > htab = kzalloc(sizeof(*htab), GFP_USER | __GFP_ACCOUNT); > if (!htab) > @@ -523,8 +523,10 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) > sizeof(int), > sizeof(int), > GFP_USER); > - if (!htab->map_locked[i]) > + if (!htab->map_locked[i]) { > + j = i; > goto free_map_locked; > + } > } > > if (htab->map.map_flags & BPF_F_ZERO_SEED) > @@ -554,7 +556,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) > free_prealloc: > prealloc_destroy(htab); > free_map_locked: > - for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++) > + for (i = 0; i < j; i++) > free_percpu(htab->map_locked[i]); > bpf_map_area_free(htab->buckets); > free_htab: > -- > 2.37.2 >