Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6549299rdb; Tue, 2 Jan 2024 05:48:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8aHAXDU+CLJwvWjgx8ZwGBfann0ngG0dklBLkpGxZyCGOOriuWqPKkmiMlXMJU31hHriG X-Received: by 2002:a05:622a:13d4:b0:427:974c:d4a4 with SMTP id p20-20020a05622a13d400b00427974cd4a4mr22895073qtk.8.1704203288323; Tue, 02 Jan 2024 05:48:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704203288; cv=none; d=google.com; s=arc-20160816; b=DzkhUkejpYCWJ+j9htsdd0C3G04zDbQSjWF8/C9FM+Ou6yghs3VYfCLZfujWu8GlzI nneQDmC09bhJUmsVlWWSID5+I3M9OfqXoDoV5JXw2HSLLwH0WXPVuKTT7LPlkB/fHUnL a00q4yVxxUkKMBKRZq4+mqpsrkLHontkzOWwIpxZ3pVRB5weHsfNfxj5VlFH/+7/92Fu W226ZkavdOv59q4gMytH/gYFOXDhnB1V2gLCXpoNUGqieBrGCeYNDHN6VgNP58OqY8// zUY2txy/IUig6ke2+w+urRValRmBNIWIPw15iNZDy9YcTZ7BvBDNfZaAKsr9UDXad2qj YaeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature:dkim-signature:dkim-signature; bh=Fn91W3IuOvD77xTkollMSFA//O+slhWPewfM4nu/8YY=; fh=ZZfaJ5Q2YejPjN2B0wOQCLLVurVmPp9FDYC6cMAd/Xo=; b=B2u8QH4LMR2MdyodHb1Jvb7p1/SQGz0mr0eTn4P5r8cdH/oLrV6nvCWaCjmo6fhRGx moGFV7fcw6psKff+Ji9upOpYLIlmC8CoS8to3i7g4/PhfKkDC+44Gv36wAvpFOjHLhQA uK3jDoTsevVkX5I77AEHogbXKPKjxvMmndFTYKWWiLgsL87W4rcxxT8ykxSvEhXIGUth E3yjKIMK8F2TfZEBDt8hDhg9qNVLcDFxwk8/exu2xzk30IU0CxXBvKAjit64SNgFi+PJ 2wunzGRah4Ll/Artd2wSAlJkbt1XuylXXAne3fwrERLUomJZlvS7bxXcqERbM3yIAYrq g75g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Gd9hn96C; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Gd9hn96C; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel+bounces-14436-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14436-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p12-20020a05622a13cc00b0042832e153ddsi509655qtk.504.2024.01.02.05.48.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 05:48:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14436-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Gd9hn96C; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Gd9hn96C; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel+bounces-14436-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14436-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1AA941C220E6 for ; Tue, 2 Jan 2024 13:48:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1DA3FC1E; Tue, 2 Jan 2024 13:47:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="Gd9hn96C"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="lf4aYHUL"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="Gd9hn96C"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="lf4aYHUL" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 C22DA10940; Tue, 2 Jan 2024 13:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BBA4A21FD3; Tue, 2 Jan 2024 13:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1704203271; h=from:from:reply-to: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=Fn91W3IuOvD77xTkollMSFA//O+slhWPewfM4nu/8YY=; b=Gd9hn96CbvxDZREN/9vBcxFp5oo63p8ln1MRJHJFNTW8bBR4ynjNMEH6Tltih8fDHCtoA+ FMu7UYsuCF8rwhDzD5q475ALaJsFqYkmcwCXqWxyPFcYtrWYpanBj5JJSBGxm1t8MkPSyz +peYwb8+F7ck4OD/42Jba7iTzRTzUdo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1704203271; h=from:from:reply-to: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=Fn91W3IuOvD77xTkollMSFA//O+slhWPewfM4nu/8YY=; b=lf4aYHULWqzaj7W0XVWI941+Kj4b88tYBjE2svC80AKn70RYPZdJpAnb7LJX7cedUIZh+I fUo3jfFhB0zI2pBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1704203271; h=from:from:reply-to: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=Fn91W3IuOvD77xTkollMSFA//O+slhWPewfM4nu/8YY=; b=Gd9hn96CbvxDZREN/9vBcxFp5oo63p8ln1MRJHJFNTW8bBR4ynjNMEH6Tltih8fDHCtoA+ FMu7UYsuCF8rwhDzD5q475ALaJsFqYkmcwCXqWxyPFcYtrWYpanBj5JJSBGxm1t8MkPSyz +peYwb8+F7ck4OD/42Jba7iTzRTzUdo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1704203271; h=from:from:reply-to: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=Fn91W3IuOvD77xTkollMSFA//O+slhWPewfM4nu/8YY=; b=lf4aYHULWqzaj7W0XVWI941+Kj4b88tYBjE2svC80AKn70RYPZdJpAnb7LJX7cedUIZh+I fUo3jfFhB0zI2pBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B054313AC6; Tue, 2 Jan 2024 13:47:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qNP9KgcUlGWqVQAAD6G6ig (envelope-from ); Tue, 02 Jan 2024 13:47:51 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 3D0A6A07EF; Tue, 2 Jan 2024 14:47:51 +0100 (CET) Date: Tue, 2 Jan 2024 14:47:51 +0100 From: Jan Kara To: Amir Goldstein Cc: Su Hui , jack@suse.cz, repnop@google.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] fanotify: avoid possible NULL dereference Message-ID: <20240102134751.2flliwe4lfvp3r5a@quack3> References: <20230808091849.505809-1-suhui@nfschina.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -2.12 X-Spamd-Result: default: False [-2.12 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.997]; RCPT_COUNT_SEVEN(0.00)[7]; FREEMAIL_TO(0.00)[gmail.com]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-1.32)[90.27%] X-Spam-Flag: NO On Thu 10-08-23 20:58:16, Amir Goldstein wrote: > On Tue, Aug 8, 2023 at 12:19 PM Su Hui wrote: > > > > smatch error: > > fs/notify/fanotify/fanotify_user.c:462 copy_fid_info_to_user(): > > we previously assumed 'fh' could be null (see line 421) > > > > Fixes: afc894c784c8 ("fanotify: Store fanotify handles differently") > > Signed-off-by: Su Hui ' > > Reviewed-by: Amir Goldstein I'm sorry but this has somehow fallen through the cracks. > > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c > > index f69c451018e3..5a5487ae2460 100644 > > --- a/fs/notify/fanotify/fanotify_user.c > > +++ b/fs/notify/fanotify/fanotify_user.c > > @@ -459,12 +459,13 @@ static int copy_fid_info_to_user(__kernel_fsid_t *fsid, struct fanotify_fh *fh, > > if (WARN_ON_ONCE(len < sizeof(handle))) > > return -EFAULT; > > > > - handle.handle_type = fh->type; > > handle.handle_bytes = fh_len; Well, if passed 'fh' is NULL, we have problems later in the function anyway. E.g. in fanotify_fh_buf() a few lines below. So I think this needs a bit more work that just this small fixup... Honza > > > > /* Mangle handle_type for bad file_handle */ > > if (!fh_len) > > handle.handle_type = FILEID_INVALID; > > + else > > + handle.handle_type = fh->type; > > > > if (copy_to_user(buf, &handle, sizeof(handle))) > > return -EFAULT; > > -- > > 2.30.2 > > -- Jan Kara SUSE Labs, CR