Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6412422ybv; Wed, 12 Feb 2020 11:43:02 -0800 (PST) X-Google-Smtp-Source: APXvYqzl2MINFVR6GvGAPH1NhsZmEnkeX2XhIZTkM0cR7B7MScbeU6hFRmnNiJCESQ7XMx0FkgAJ X-Received: by 2002:a9d:7ccc:: with SMTP id r12mr10999389otn.22.1581536582837; Wed, 12 Feb 2020 11:43:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581536582; cv=none; d=google.com; s=arc-20160816; b=sXd1x51QNEJoKYFkCtxqQzMf03nySv61PvcF3q0exgBA8emSQrVHyOkIUOZDnB16qT S08if2Cn7Rxo3dkEovPNuCyimioV53w3/9q3Gq1l5LXaqDBq0D8S5J4FWHbynoOvh6df An58cYifLu54QrDPxnFqIk2mz+wyhkiil+1p7JnQr8V1VbrVD8I/BEaNpm+tcYLjXnsP Dzj4gKmDNnFBR/oicKQVaQHFXysHrcljJrEm5GrqVysVY2Qz9sjArqqtNw7mtATwzrV9 Zu1ReTPNQ2aJrBWw2FsnXwOuvsvVVH1vl+Vhk6Ojmc04qF0e7NZI68dMVgjLDdHm/c5L D1VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=7YEJUaf3OPn/UnW+O58tc3Erq+im81eIKbDaL/jda8o=; b=PJaiHt5xNVpjLhK0j0/NUZoLxDR3VhO+f1bWSj+lT9Ai7ZXBhTcaESspgoiBAwd4BV GitbE5LO5Za6Qbah2cstUMpQ12aCDPfWXlkX6wGzNtA5Hwx/oQYQMP63WC0xO1v5khNb r5KzP2Y4YXS0Byjo/+CzMZPgBDHxQPVtugO9YFDavrYJfwTqrVDvD2Z0v8b41sj7LJxd cO/hViFfMyoVQugg5Cy73L983l/+i9EeWAD4qsASJvT3hN8HRrOHxD0XqglQ8eo2pUF4 kGG27LhWMzE2Mjon5nE5FLbOFC40QKTr2BathdzdRjC4Y19InYnz6bX6mdj+8EUSsI3P 0eww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@krude.de header.s=mail header.b="eW/iRqpV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=krude.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si705751otq.262.2020.02.12.11.42.49; Wed, 12 Feb 2020 11:43:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@krude.de header.s=mail header.b="eW/iRqpV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=krude.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729018AbgBLTln (ORCPT + 99 others); Wed, 12 Feb 2020 14:41:43 -0500 Received: from smtp.noc-kru.de ([88.218.226.4]:39301 "EHLO smtp.noc-kru.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727361AbgBLTln (ORCPT ); Wed, 12 Feb 2020 14:41:43 -0500 X-Greylist: delayed 544 seconds by postgrey-1.27 at vger.kernel.org; Wed, 12 Feb 2020 14:41:41 EST Received: from localhost (localhost.localdomain [127.0.0.1]) by mx.noc-kru.de (Postfix) with ESMTP id C2BE15A2199; Wed, 12 Feb 2020 20:32:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at idefix.krude.de Received: from smtp.noc-kru.de ([88.218.226.4]) by localhost (idefix.noc-kru.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JVfAgvFchAtr; Wed, 12 Feb 2020 20:32:33 +0100 (CET) Received: from phlox.h.transitiv.net (2001-4dd0-2d41-0-d1dc-282-62ef-8fa2.ipv6dyn.netcologne.de [IPv6:2001:4dd0:2d41:0:d1dc:282:62ef:8fa2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by mx.noc-kru.de (Postfix) with ESMTPSA id 13F3F5A229E; Wed, 12 Feb 2020 20:32:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=krude.de; s=mail; t=1581535953; bh=1vmRLVZks48GT3ZVlDPxnXV5eHetAPhkCTAe9N3Qtxg=; h=Date:From:To:Cc:Subject:From; b=eW/iRqpV3rlUoNITwHSxS0QXKIs8HLqajq+M2MNdMwofEcn/SG8X7W6AEjso5yuDr FOEMusYTUwK9zL2JDgJGTKoFS3kdL4X7fuyGdyzCR+7OKJSO+1hWhjOnRtH0tKCVq2 bWp3gyztgR0Qn23r0ysZdALSRktWWe2gDUtWmF3g= Date: Wed, 12 Feb 2020 20:32:27 +0100 From: Johannes Krude To: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , trivial@kernel.org Subject: [PATCH] bpf_prog_offload_info_fill: replace bitwise AND by logical AND Message-ID: <20200212193227.GA3769@phlox.h.transitiv.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This if guards whether user-space wants a copy of the offload-jited bytecode and whether this bytecode exists. By erroneously doing a bitwise AND instead of a logical AND on user- and kernel-space buffer-size can lead to no data being copied to user-space especially when user-space size is a power of two and bigger then the kernel-space buffer. Signed-off-by: Johannes Krude --- kernel/bpf/offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c index 2c5dc6541..bd09290e3 100644 --- a/kernel/bpf/offload.c +++ b/kernel/bpf/offload.c @@ -321,7 +321,7 @@ int bpf_prog_offload_info_fill(struct bpf_prog_info *info, ulen = info->jited_prog_len; info->jited_prog_len = aux->offload->jited_len; - if (info->jited_prog_len & ulen) { + if (info->jited_prog_len && ulen) { uinsns = u64_to_user_ptr(info->jited_prog_insns); ulen = min_t(u32, info->jited_prog_len, ulen); if (copy_to_user(uinsns, aux->offload->jited_image, ulen)) { -- 2.24.0