Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp466576ybg; Tue, 9 Jun 2020 05:26:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWl4sP+a0aWT0KqFN83U/h1poCRSMfGkjJMwXXo1yV0ehRanG+VSerE284NDiUi49IglTQ X-Received: by 2002:a17:906:a2c5:: with SMTP id by5mr25170478ejb.492.1591705601126; Tue, 09 Jun 2020 05:26:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591705601; cv=none; d=google.com; s=arc-20160816; b=Mm2OHWEwY/ykDln4o74heLCvFDyRcEEvcbkHpr95N3VHGIKYymgOnvVF8WsCkUxZNN +URyzOVvn4yHjbZUTBthL0AgMOgmhdNQDcBxrVa2ZSTUFGG6Vmv3pHlbEofFQORCpFle FIMcqYPqT+Fw+MepqeuNvib2rr4bnvXjKDJq6pb/ROcgIpHBr7N59Qkv/cersSCF9nqV +CjziOlekIOBaxq0EYccq4RS23o/wALV9afAkpTfdiwY13J8y2r31AsTmTBGWxHgsOXO iPf5W511k6KNP2De1WK3SHe7WYsqBZlwnPqrcFJGKPlD0HW9FmWli+/Dm2l6++2lUXS0 Sq1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=d3aWiXtS8cF+u5/TS5j+n1u7AbVcRqeRZ4SH9J+GaOc=; b=M1uc5hsJh4ZFnZhFTYTX5yuzjdreI2+tCeXdh/FtU66y9YH6Owq+J6I4hJ1ZcniIO4 KZyxB/66gggpfmx9WTEUaAtZA89xZvlHr2PEqkTb1XRA2s4DbQF57yb3Qp9HjYJNlU5p g/FMEGoOMfwT5fQ7OXFWBimDrs2bixQPMLpeGMCyYlyqnGuocjeLak3tQIaWlixUiiQE Bs9uFsdXt3qxX3a6RL7onuQQ2QmJiqqROe0ipQlsZdHuO28kI+GkROoAV0RwVU/Mm1f8 uOHXSBUob1TIjlW7MAvjrzqqWRouvbZ06qJr7bXb7VYafRcFO23g69AX9CHlkwEbkEZF kcEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WKD2WtuM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si10951090ejt.637.2020.06.09.05.26.18; Tue, 09 Jun 2020 05:26:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WKD2WtuM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbgFIMXb (ORCPT + 99 others); Tue, 9 Jun 2020 08:23:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:29766 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727113AbgFIMXa (ORCPT ); Tue, 9 Jun 2020 08:23:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591705409; h=from:from: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=d3aWiXtS8cF+u5/TS5j+n1u7AbVcRqeRZ4SH9J+GaOc=; b=WKD2WtuM0+nuv4bAR+O/tj8YcKzXGUTExm+N/3gaq2OLApaTBGDsKbSUkxD9705Q9m8UJa s2kUvPyVQOLdpZqdTDTGL8WOkcNbvcMeffAeLioRhJ8pWe8dUzekRQFuK8PrYD6Z8y1nAI lpXErSd+tq78tZFcH3Vbkrt5UcGorXM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-mSCxeT0HPrWtom8qduK5cQ-1; Tue, 09 Jun 2020 08:23:26 -0400 X-MC-Unique: mSCxeT0HPrWtom8qduK5cQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3CEF2107B266; Tue, 9 Jun 2020 12:23:24 +0000 (UTC) Received: from carbon (unknown [10.40.208.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id C715F5D9C9; Tue, 9 Jun 2020 12:23:19 +0000 (UTC) Date: Tue, 9 Jun 2020 14:23:15 +0200 From: Jesper Dangaard Brouer To: Gaurav Singh Cc: Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , KP Singh , netdev@vger.kernel.org (open list:XDP (eXpress Data Path)), bpf@vger.kernel.org (open list:XDP (eXpress Data Path)), linux-kernel@vger.kernel.org (open list) Subject: Re: [PATCH] bpf: alloc_record_per_cpu Add null check after malloc Message-ID: <20200609142315.4d131599@carbon> In-Reply-To: <20200609120804.10569-1-gaurav1086@gmail.com> References: <20200609120804.10569-1-gaurav1086@gmail.com> Organization: Red Hat Inc. MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 9 Jun 2020 08:08:03 -0400 Gaurav Singh wrote: > The memset call is made right after malloc call. To fix this, add the null check right after malloc and then do memset. > Did you read the section about how long lines should be in desc? > Signed-off-by: Gaurav Singh > --- > samples/bpf/xdp_rxq_info_user.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c > index 4fe47502ebed..490b07b7df78 100644 > --- a/samples/bpf/xdp_rxq_info_user.c > +++ b/samples/bpf/xdp_rxq_info_user.c > @@ -202,11 +202,11 @@ static struct datarec *alloc_record_per_cpu(void) > > size = sizeof(struct datarec) * nr_cpus; > array = malloc(size); > - memset(array, 0, size); > if (!array) { > fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus); > exit(EXIT_FAIL_MEM); > } > + memset(array, 0, size); > return array; > } Looking at code, this bug happen in more places. Please fix up all locations. I think this fix should go through the "bpf" tree. Please read: https://github.com/torvalds/linux/blob/master/Documentation/bpf/bpf_devel_QA.rst -- Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer