Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp339571lqp; Wed, 12 Jun 2024 03:11:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUuicVI4fFPEtf0duUcBJuWDeiDbZZnN99OmcneqvL60tA2vI/aMmEMfFGFWs1Tf+MqncVLG/1XHQHHtqzk2WQhoJQkx3MrLHkt9BDoA== X-Google-Smtp-Source: AGHT+IFgJKuqgblIaR8Lu/fV/shQNIYlBMaBEbINN7mUmvK+gv0U5EmP6GgK2+RrS6wUt+OjlmE/ X-Received: by 2002:a17:906:b24e:b0:a6e:2a67:789f with SMTP id a640c23a62f3a-a6f47facce9mr88826666b.40.1718187110531; Wed, 12 Jun 2024 03:11:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718187110; cv=pass; d=google.com; s=arc-20160816; b=JgB/pKGicjdOBVv5y+RCjtJ2VcR874ysmrye7SfJm38cSfDsPlb2Kb2Rq5AEul8uRH 77j2eQDBe64ytseIqag0Tz3oZn8VrxdkqXsQ9Mgp1gFqcLJ7mw4yNdRB4G/eC/F2cCy/ sWGO3thQArhLcN7mdNLLHDrnziSQDVo/cRks5kFksaIgYmvQU9nesqmpAxd5NKez33j/ 08mQM9GrCzDQshTYTi1CT0Hqg6Ih7285KNvZD7XMJ0t/sCIjhZm4wVQ2pXsIVJjjQLjB ckMj+FRKNxbtnN99c2olnjhawPAIJpOkxalYe5c5lUF9AjC6K9aWSP74i4SDdLaP2ZQ7 Le5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=JB137Y60BhwWEDBjTqvHulcYwQ9jTNh9hWVkbeGFpbY=; fh=+to9BavAw/JIA8Pp8gGSG5SjbSk4QzLGAX3NuWrUqjE=; b=BbCraEdbqpAywLo356UcEz+BGtDfr21ERhnCA4Z7XuG828xZgllZJcebEvXhmNKeXf 74YUHJg36rwhKLVrwPK3B6dAA1YO1gdsV606U3eL8RQHOPitxelPwk5jkBAgNnYPek3g BVLFqkosa7iJQNPXrt9h1YHETtPHFDBaRyG4EUE0NCJZnSJS+GFb3iRd6K3OXMKFxegE Vw0Lqv8aldCQbfm15IY2q8dDlf9PSeklc8nYYv+5v/pMsEf7JOxH94jCTiWUKz5IZOPD d7zMZjllPi9TjoIik6zXVGzb0tD1EcnZAcltk+4rFuJeC6y2ICAeHULs/U0WgaJDfnvq A+gg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FdY2uucs; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-211335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211335-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f3672d23bsi171797266b.781.2024.06.12.03.11.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 03:11:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FdY2uucs; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-211335-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211335-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 43EE41F21889 for ; Wed, 12 Jun 2024 10:11:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EA5916E881; Wed, 12 Jun 2024 10:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FdY2uucs" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07DA733FE for ; Wed, 12 Jun 2024 10:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718187104; cv=none; b=B38u5Ron5Zcb5fV5TgeXciZXPkWtjpUHvNtyLjkONpEiR8Z+zJp0KCNOKXv6eZ92T8kmhtUSW1tz18oF/hUStB8CZthxyDRW5Rs5Zp2Wl3nKfnb2IQstVylkEgc8lHdYMkMzirDVm7bCExkXTrJ3WBYzEzmZIWCGbmO+Izu5bpo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718187104; c=relaxed/simple; bh=KFf2FT18RPV8C8MRIqXhIhGb0bt0t/RSv998zsVKsOo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=tuLWbaGf98JL/pT+L5BH35GB8bfjKGTXSzDMm5cCVK7GIYI2NNUJI63aDhkcW6l9awvcWGZXTwnhR8HGMmlS1ubHnFxuLxSGuVGp3oACwYalm0vDLJYXcFPQXC7xtxHXxDl5GfEhTvtUkAK7w0r/TWl5to9SwhpWOnE+LQRkr6c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FdY2uucs; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1ee5f3123d8so109505ad.1 for ; Wed, 12 Jun 2024 03:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718187102; x=1718791902; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JB137Y60BhwWEDBjTqvHulcYwQ9jTNh9hWVkbeGFpbY=; b=FdY2uucssI/Pc5Gx5pwQ8/ZrpiX0jO/VHBFMJ5EZnOXBWMYEN1W8F6fMe/yOPJqADR pWYFhotDZJj2z5ag4jZFl1IWZtlTI8L20gmaB5AiPqTVlF/hb+/D4fLeQdu4Z/LhelVu KzshCLBt5Hv3tds9nRCzi/QIrXURpJ8OPP7+JZm01TkBekIoFrRXRYdWHa9NclPcLwNR 4Pm/MWg7Sxycj9AnFv7IPYyaZONdVkfFhcxg38tv50CbDm3VkweoBGHSiP2RGxQgCmaQ 8C45mkIqnVnjbUlquUtWIf+ttoXONNGYJ+/1RWpslj76hOLEHaHuyr/bqBdCN3NTVYAK MgpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718187102; x=1718791902; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JB137Y60BhwWEDBjTqvHulcYwQ9jTNh9hWVkbeGFpbY=; b=stR4TUSL9lOtpXqnM63Dv0gxR9Go4C42bDQTfOko/2eiDKyYs5kvbf36XpSqxUaqhc vr8HEeyTHF7/kcZP/5stwEki/L0P6PYspQ+LMXJ5n6uDDhXAsPNWvzp28Phfnbcwtamu fH0NEGDAcqRvoZw+E7WkWJw/4+JlhzlO7WG1iIRlMSEFaKG9FK/7gih0kwmZaAGgUrVu GDkN1KUFklLzvlA2IwnAGZjcKQtDgDg/CGccd9DhDG/t6uS7bEIsMn0wjmwul7E2HLbc Fabm2eT9jUEA8Z2+6lE7/bDyFazSS4ulAULZhpvz1kLIsPQsnFIsC1i6ZKR58l/kFN6K BH3A== X-Forwarded-Encrypted: i=1; AJvYcCWgdBlq0wSXm3488gcFRaodRCTt1fT9pz+2HXIY5ervxD/sBWlphEqhPzEZQ2AFO0wzqu63d/ttyTbO0r9Lp5uBhX/tyzy9idoIjYN9 X-Gm-Message-State: AOJu0YyMrWez9Nh8EAGlQWknkrfFlsIXBMDvyHCMSmfgcYZRmxBUIlsK lAexYkxF6bqlZwBqdX7e4Qm7j9NyPnWQNiqAiNtL7femLIEn+vkJxNRFTxjRPROUWoRL+ueR1N7 7aJBHdu240JPQXG5Yzb2VquIGR3VxtaEPr1BU X-Received: by 2002:a17:902:c40a:b0:1e0:c571:d652 with SMTP id d9443c01a7336-1f83b371decmr2105695ad.1.1718187101848; Wed, 12 Jun 2024 03:11:41 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240611133229.527822-1-nogikh@google.com> <20240611115133.fa80466e924ad34ed4ad73cb@linux-foundation.org> In-Reply-To: <20240611115133.fa80466e924ad34ed4ad73cb@linux-foundation.org> From: Aleksandr Nogikh Date: Wed, 12 Jun 2024 12:11:30 +0200 Message-ID: Subject: Re: [PATCH] kcov: don't lose track of remote references during softirqs To: Andrew Morton Cc: dvyukov@google.com, andreyknvl@gmail.com, arnd@arndb.de, elver@google.com, glider@google.com, syzkaller@googlegroups.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 11, 2024 at 8:51=E2=80=AFPM Andrew Morton wrote: > > On Tue, 11 Jun 2024 15:32:29 +0200 Aleksandr Nogikh w= rote: > > > In kcov_remote_start()/kcov_remote_stop(), we swap the previous KCOV > > metadata of the current task into a per-CPU variable. However, the > > kcov_mode_enabled(mode) check is not sufficient in the case of remote > > KCOV coverage: current->kcov_mode always remains KCOV_MODE_DISABLED > > for remote KCOV objects. > > > > If the original task that has invoked the KCOV_REMOTE_ENABLE ioctl > > happens to get interrupted and kcov_remote_start() is called, it > > ultimately leads to kcov_remote_stop() NOT restoring the original > > KCOV reference. So when the task exits, all registered remote KCOV > > handles remain active forever. > > > > Fix it by introducing a special kcov_mode that is assigned to the > > task that owns a KCOV remote object. It makes kcov_mode_enabled() > > return true and yet does not trigger coverage collection in > > __sanitizer_cov_trace_pc() and write_comp_data(). > > What are the userspace visible effects of this bug? I *think* it's > just an efficiency thing, but how significant? In other words, should > we backport this fix? > The most uncomfortable effect (at least for syzkaller) is that the bug prevents the reuse of the same /sys/kernel/debug/kcov descriptor. If we obtain it in the parent process and then e.g. drop some capabilities and continuously fork to execute individual programs, at some point current->kcov of the forked process is lost, kcov_task_exit() takes no action, and all KCOV_REMOTE_ENABLE ioctls calls from subsequent forks fail. And, yes, the efficiency is also affected if we keep on losing remote kcov objects. a) kcov_remote_map keeps on growing forever. b) (If I'm not mistaken), we're also not freeing the memory referenced by kcov->area. I think it would be nice to backport the fix to the stable trees. --=20 Aleksandr