Revision e6838a29ecb484c97e4efef9429643b9851fba6e authored by J. Bruce Fields on 21 April 2017, 20:10:18 UTC, committed by J. Bruce Fields on 25 April 2017, 20:34:37 UTC
A client can append random data to the end of an NFSv2 or NFSv3 RPC call
without our complaining; we'll just stop parsing at the end of the
expected data and ignore the rest.

Encoded arguments and replies are stored together in an array of pages,
and if a call is too large it could leave inadequate space for the
reply.  This is normally OK because NFS RPC's typically have either
short arguments and long replies (like READ) or long arguments and short
replies (like WRITE).  But a client that sends an incorrectly long reply
can violate those assumptions.  This was observed to cause crashes.

Also, several operations increment rq_next_page in the decode routine
before checking the argument size, which can leave rq_next_page pointing
well past the end of the page array, causing trouble later in
svc_free_pages.

So, following a suggestion from Neil Brown, add a central check to
enforce our expectation that no NFSv2/v3 call has both a large call and
a large reply.

As followup we may also want to rewrite the encoding routines to check
more carefully that they aren't running off the end of the page array.

We may also consider rejecting calls that have any extra garbage
appended.  That would be safer, and within our rights by spec, but given
the age of our server and the NFS protocol, and the fact that we've
never enforced this before, we may need to balance that against the
possibility of breaking some oddball client.

Reported-by: Tuomas Haanpää <thaan@synopsys.com>
Reported-by: Ari Kauppi <ari@synopsys.com>
Cc: stable@vger.kernel.org
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 5a7ad11
Raw File
Makefile.headersinst
# ==========================================================================
# Installing headers
#
# header-y  - list files to be installed. They are preprocessed
#             to remove __KERNEL__ section of the file
# genhdr-y  - Same as header-y but in a generated/ directory
#
# ==========================================================================

# generated header directory
gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))

kbuild-file := $(srctree)/$(obj)/Kbuild
include $(kbuild-file)

# called may set destination dir (when installing to asm/)
_dst := $(if $(destination-y),$(destination-y),$(if $(dst),$(dst),$(obj)))

old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
ifneq ($(wildcard $(old-kbuild-file)),)
include $(old-kbuild-file)
endif

include scripts/Kbuild.include

installdir    := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))

header-y      := $(sort $(header-y))
subdirs       := $(patsubst %/,%,$(filter %/, $(header-y)))
header-y      := $(filter-out %/, $(header-y))

# files used to track state of install/check
install-file  := $(installdir)/.install
check-file    := $(installdir)/.check

# generic-y list all files an architecture uses from asm-generic
# Use this to build a list of headers which require a wrapper
wrapper-files := $(filter $(header-y), $(generic-y))

srcdir        := $(srctree)/$(obj)
gendir        := $(objtree)/$(gen)

oldsrcdir     := $(srctree)/$(subst /uapi,,$(obj))

# all headers files for this dir
header-y      := $(filter-out $(generic-y), $(header-y))
all-files     := $(header-y) $(genhdr-y) $(wrapper-files)
output-files  := $(addprefix $(installdir)/, $(all-files))

input-files1  := $(foreach hdr, $(header-y), \
		   $(if $(wildcard $(srcdir)/$(hdr)), \
			$(wildcard $(srcdir)/$(hdr))) \
		   )
input-files1-name := $(notdir $(input-files1))
input-files2  := $(foreach hdr, $(header-y), \
		   $(if  $(wildcard $(srcdir)/$(hdr)),, \
			$(if $(wildcard $(oldsrcdir)/$(hdr)), \
				$(wildcard $(oldsrcdir)/$(hdr)), \
				$(error Missing UAPI file $(srcdir)/$(hdr))) \
		   ))
input-files2-name := $(notdir $(input-files2))
input-files3  := $(foreach hdr, $(genhdr-y), \
		   $(if	$(wildcard $(gendir)/$(hdr)), \
			$(wildcard $(gendir)/$(hdr)), \
			$(error Missing generated UAPI file $(gendir)/$(hdr)) \
		   ))
input-files3-name := $(notdir $(input-files3))

# Work out what needs to be removed
oldheaders    := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
unwanted      := $(filter-out $(all-files),$(oldheaders))

# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
unwanted-file := $(addprefix $(installdir)/, $(unwanted))

printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))

quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
                            file$(if $(word 2, $(all-files)),s))
      cmd_install = \
        $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \
        $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \
        $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \
        for F in $(wrapper-files); do                                   \
                echo "\#include <asm-generic/$$F>" > $(installdir)/$$F;    \
        done;                                                           \
        touch $@

quiet_cmd_remove = REMOVE  $(unwanted)
      cmd_remove = rm -f $(unwanted-file)

quiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
# Headers list can be pretty long, xargs helps to avoid
# the "Argument list too long" error.
      cmd_check = for f in $(all-files); do                          \
                  echo "$(installdir)/$${f}"; done                      \
                  | xargs                                            \
                  $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
	          touch $@

PHONY += __headersinst __headerscheck

ifndef HDRCHECK
# Rules for installing headers
__headersinst: $(subdirs) $(install-file)
	@:

targets += $(install-file)
$(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE
	$(if $(unwanted),$(call cmd,remove),)
	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
	$(call if_changed,install)

else
__headerscheck: $(subdirs) $(check-file)
	@:

targets += $(check-file)
$(check-file): scripts/headers_check.pl $(output-files) FORCE
	$(call if_changed,check)

endif

# Recursion
.PHONY: $(subdirs)
$(subdirs):
	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@

targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard \
             $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))

ifneq ($(cmd_files),)
	include $(cmd_files)
endif

.PHONY: $(PHONY)
PHONY += FORCE
FORCE: ;
back to top